Compare commits
103 Commits
fd28677d66
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c7521f0e2b | |||
| 2f15cb639c | |||
| 49b02c2d4f | |||
| 532a2287c5 | |||
| 36fc4d0360 | |||
| 797f4c61f6 | |||
| a6a78cca8b | |||
| 772d287fcd | |||
| d0dae475f9 | |||
| 9b1618f85b | |||
| 8f90e98215 | |||
| 9758d91e0a | |||
| a57e0bb433 | |||
| 02ef25d4e7 | |||
| f5363ca862 | |||
| 0be345eb24 | |||
| e0d09ed7b3 | |||
| 2df98eb31c | |||
| a4e176c682 | |||
| c4fbbfda4a | |||
| 36f4dcf807 | |||
| 3d56151787 | |||
| 3a6f9b0044 | |||
| 8ab7bbaea7 | |||
| 9a7528d49b | |||
| b583946f7e | |||
| 8101ff0cb4 | |||
| 18aa0130a7 | |||
| 1d3c86c56c | |||
| 2a8bd88a3e | |||
| be16a588c2 | |||
| 4100d5c77a | |||
| a16a2981e1 | |||
| 953d677c8e | |||
| 5b5c1d9563 | |||
| 5056c20667 | |||
| 8f0315e588 | |||
| 6ba4ee1e06 | |||
| b4b84dc797 | |||
| 7fd7df2913 | |||
| eac827d932 | |||
| a85e31ff16 | |||
| 646d2a1361 | |||
| d01e456ae5 | |||
| db790e2c89 | |||
| 75cbaa3302 | |||
| 083d73d287 | |||
| d21d1ab960 | |||
| 043dbbf24a | |||
| 3d7ec83ec9 | |||
| 70f5667adc | |||
| 8ff77d7dba | |||
| c1ede4ade8 | |||
| 5caecb887f | |||
| 4f4aa27da8 | |||
| c6cbb5d1fb | |||
| e56e2892d0 | |||
| be3837ff06 | |||
| 0cbb024411 | |||
| ada49d3491 | |||
| eebaa11bfb | |||
| 6c85d2e871 | |||
| f67219fe02 | |||
| 774ad4d820 | |||
| adcc5a1dc1 | |||
| 5d18183d82 | |||
| 2fca49b120 | |||
| b1bc83586f | |||
| d61d242f4e | |||
| 6f97f4576f | |||
| 70492235c7 | |||
| 7251a12469 | |||
| b6cf793e1b | |||
| 78169c3bc0 | |||
| db12446a68 | |||
| c151b49334 | |||
| d14cd9f3de | |||
| 121610f8d9 | |||
| de507c7bc0 | |||
| c4bdb01b21 | |||
| e027d84da4 | |||
| 9f7bc1c37a | |||
| 2c6b52f0ed | |||
| f165dc1425 | |||
| 9cd386b720 | |||
| 58431d1d8d | |||
| f3013c8509 | |||
| aecf64af27 | |||
| 17cdb6c7fd | |||
| 229eef6db1 | |||
| 9886a3a5b2 | |||
| 095df145d6 | |||
| 91f83f781c | |||
| 0361510a05 | |||
| 93006fd299 | |||
| 81ba3ae6e8 | |||
| dbd9efc8f5 | |||
| 4dbaf69a3e | |||
| 2090dd25ea | |||
| e8b26f997f | |||
| 882e31ab96 | |||
| 667e279768 | |||
| dc6081fcaf |
@@ -0,0 +1,5 @@
|
||||
# Docserver Configuration
|
||||
DOCSERVER_PORT=8000
|
||||
DOCSERVER_USER=admin
|
||||
DOCSERVER_PASSWORD=admin123
|
||||
MOMENTRY_DOCS_DIR=/Users/accusys/momentry_core/docs_v1.0/doc_wasm
|
||||
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: Cross-Project Bug
|
||||
about: 跨專案 Bug 會診
|
||||
title: ''
|
||||
labels: type:bug, cross-project
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
## Bug 描述
|
||||
|
||||
## 影響專案
|
||||
- [ ] markbase
|
||||
- [ ] MarkBaseEngine
|
||||
- [ ] momentry_core
|
||||
- [ ] momentry_studio
|
||||
|
||||
## 重現步驟
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
## 預期行為
|
||||
|
||||
## 實際行為
|
||||
|
||||
## 影響分析
|
||||
| 層級 | 影響 | 緊急度 |
|
||||
|------|------|--------|
|
||||
| 使用者 | | 🔴/🟡/🟢 |
|
||||
| 資料 | | 🔴/🟡/🟢 |
|
||||
| 服務 | | 🔴/🟡/🟢 |
|
||||
|
||||
## 會診團隊
|
||||
| 專案 | 負責人 | 狀態 |
|
||||
|------|--------|------|
|
||||
| markbase | @ | |
|
||||
| MarkBaseEngine | @ | |
|
||||
| momentry_core | @ | |
|
||||
| momentry_studio | @ | |
|
||||
|
||||
## 修復方案
|
||||
|
||||
## 驗證結果
|
||||
- [ ] Sandbox 測試通過
|
||||
- [ ] CI/CD 通過
|
||||
- [ ] 手動測試通過
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Feature Request
|
||||
about: 新功能需求
|
||||
title: ''
|
||||
labels: type:feature
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
## 功能描述
|
||||
|
||||
## 使用場景
|
||||
|
||||
## 驗收標準
|
||||
- [ ] 標準 1
|
||||
- [ ] 標準 2
|
||||
|
||||
## 技術方案 (可選)
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
name: Requirement
|
||||
about: 跨專案需求
|
||||
title: ''
|
||||
labels: type:requirement
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
## 需求名稱
|
||||
|
||||
## 影響專案
|
||||
- [ ] markbase
|
||||
- [ ] MarkBaseEngine
|
||||
- [ ] momentry_core
|
||||
- [ ] momentry_studio
|
||||
|
||||
## 需求描述
|
||||
|
||||
## API 變更 (如適用)
|
||||
|
||||
## 資料庫變更 (如適用)
|
||||
|
||||
## 驗收標準
|
||||
- [ ] 標準 1
|
||||
- [ ] 標準 2
|
||||
|
||||
## 依賴 Issue
|
||||
- Blocks #
|
||||
- Related to #
|
||||
@@ -0,0 +1,20 @@
|
||||
name: Core Test
|
||||
on:
|
||||
push:
|
||||
branches: [main, develop]
|
||||
paths: ['src/**', 'Cargo.toml']
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
lint-and-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- name: Cargo fmt
|
||||
run: cargo fmt -- --check
|
||||
- name: Cargo clippy
|
||||
run: cargo clippy -- -D warnings
|
||||
- name: Cargo test
|
||||
run: cargo test --lib
|
||||
@@ -0,0 +1,23 @@
|
||||
name: Cross-Project Integration
|
||||
on:
|
||||
push:
|
||||
branches: [main, develop]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
integration:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup Sandbox
|
||||
run: ./scripts/setup_sandbox.sh
|
||||
- name: Build All
|
||||
run: ./scripts/build_all.sh
|
||||
- name: Start Services
|
||||
run: ./scripts/start_services.sh
|
||||
- name: Run Integration Tests
|
||||
run: ./scripts/run_integration_tests.sh
|
||||
- name: Cleanup
|
||||
if: always()
|
||||
run: ./scripts/cleanup_sandbox.sh
|
||||
@@ -0,0 +1,22 @@
|
||||
name: Release
|
||||
on:
|
||||
push:
|
||||
tags: ['v*']
|
||||
|
||||
jobs:
|
||||
build-and-release:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build Release
|
||||
run: cargo build --release
|
||||
- name: Run Full Tests
|
||||
run: cargo test
|
||||
- name: Create Release
|
||||
run: |
|
||||
cp target/release/momentry ./momentry-${{ github.ref_name }}
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: momentry-${{ github.ref_name }}
|
||||
path: momentry-${{ github.ref_name }}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE vlm_requests\n SET \n status = 'completed',\n result = $1,\n processing_time_ms = $2,\n completed_at = NOW()\n WHERE id = $3\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "0373b02cc8de069f6e964bc023c4e29497cb66f8b0a181bafa73f175454e6903"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO command_queue (\n message_id, queue_name, queue_type,\n command_type, command_category,\n key, value, priority,\n request_id, key_id, billing_context,\n scheduled_at, max_retries,\n created_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Jsonb",
|
||||
"Int2",
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Jsonb",
|
||||
"Timestamptz",
|
||||
"Int4",
|
||||
"Timestamptz"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "08adb7aafb3214ab7740baabcb6db8901c80dc5357008cd984f50d497fd416a2"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT status, result, error\n FROM vlm_requests\n WHERE id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "status",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "result",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "error",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "1083cb140d49eed76e1f5081b88cbdca34f59052571490635dc8b1fdca3b1bd3"
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE dev.videos SET processing_status = $1 WHERE uuid = $2",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Jsonb",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "2d61eacd106ad5144c99a85c84f070924af9b29103a507e115674d1b14b77181"
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE dev.jobs SET status = 'COMPLETED', processed_frames = total_frames, updated_at = NOW() WHERE id = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "345d912734b063a7b30d52c066045553964d0a55453a7e26a4d8b8d758be3857"
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT command_type, command_category, queue_name, handler, priority, billing_required\n FROM queue_routes\n WHERE active = true\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "command_type",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "command_category",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "queue_name",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "handler",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "priority",
|
||||
"type_info": "Int2"
|
||||
},
|
||||
{
|
||||
"ordinal": 5,
|
||||
"name": "billing_required",
|
||||
"type_info": "Bool"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": []
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "392a5b8ec9b3f9cf1736d47eeecaa1fe87ffa62024146c3d2c37bf028d954b3f"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE vlm_consumer_offsets\n SET current_offset = $1, last_poll_at = NOW()\n WHERE consumer_id = $2\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "3d7027dffb815b8a40e5525c9065bdd3173ff567cf8b7b299ad56f5b4cfb49de"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE command_queue\n SET status = $2,\n processing_completed_at = $3,\n token_usage = $4,\n cost_usd = $5\n WHERE message_id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Varchar",
|
||||
"Timestamptz",
|
||||
"Jsonb",
|
||||
"Float8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "4580e475bf8395911bbf9b36660094cf4483a4d4dcbe3dc7b5437904aeb86780"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO vlm_requests (request_type, priority, payload, status)\n VALUES ($1, $2, $3, 'pending')\n RETURNING id\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Int4",
|
||||
"Jsonb"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "5bc08af47af66dc518afee2939f2fb33ea3384c63226fc474043346225923fcc"
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE command_queue\n SET status = 'processing',\n consumer_group = $1,\n consumer_id = $2,\n processing_started_at = NOW(),\n timeout_at = NOW() + ($5::bigint * INTERVAL '1 second')\n WHERE message_id IN (\n SELECT message_id\n FROM command_queue\n WHERE queue_name = $3\n AND status = 'pending'\n AND (scheduled_at IS NULL OR scheduled_at <= NOW())\n ORDER BY priority ASC, created_at ASC\n LIMIT $4\n FOR UPDATE SKIP LOCKED\n )\n RETURNING\n message_id, queue_name, queue_type,\n command_type, command_category, command_action,\n key, value, priority,\n request_id, key_id, billing_context, token_usage, cost_usd,\n status, consumer_group, consumer_id,\n retry_count, max_retries, last_error,\n created_at, scheduled_at, processing_started_at, processing_completed_at\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "message_id",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "queue_name",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "queue_type",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "command_type",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "command_category",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 5,
|
||||
"name": "command_action",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 6,
|
||||
"name": "key",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "value",
|
||||
"type_info": "Jsonb"
|
||||
},
|
||||
{
|
||||
"ordinal": 8,
|
||||
"name": "priority",
|
||||
"type_info": "Int2"
|
||||
},
|
||||
{
|
||||
"ordinal": 9,
|
||||
"name": "request_id",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 10,
|
||||
"name": "key_id",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 11,
|
||||
"name": "billing_context",
|
||||
"type_info": "Jsonb"
|
||||
},
|
||||
{
|
||||
"ordinal": 12,
|
||||
"name": "token_usage",
|
||||
"type_info": "Jsonb"
|
||||
},
|
||||
{
|
||||
"ordinal": 13,
|
||||
"name": "cost_usd",
|
||||
"type_info": "Float8"
|
||||
},
|
||||
{
|
||||
"ordinal": 14,
|
||||
"name": "status",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 15,
|
||||
"name": "consumer_group",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 16,
|
||||
"name": "consumer_id",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 17,
|
||||
"name": "retry_count",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 18,
|
||||
"name": "max_retries",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 19,
|
||||
"name": "last_error",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 20,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 21,
|
||||
"name": "scheduled_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 22,
|
||||
"name": "processing_started_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 23,
|
||||
"name": "processing_completed_at",
|
||||
"type_info": "Timestamptz"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Text",
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "5f27ef47fc166a0bb8f8a26ccbd7418710e3bbb280af10935ffb2eddffcd33e4"
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE dev.jobs SET status = 'FAILED', error_message = $2, updated_at = NOW() WHERE id = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "60cc008705cfea3a4532b9496db8f6ed0e3023436660bdf8ee81fe78fe270971"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE vlm_requests\n SET status = 'processing', started_at = NOW()\n WHERE id = ANY($1)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8Array"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "66ef83b7ad3fe95922fb2aa9a083ed55b14c5b4d7dd6b9ada1659d6060780533"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO vlm_requests (request_type, priority, payload, status)\n VALUES ($1, $2, $3, 'pending')\n RETURNING id\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Int4",
|
||||
"Jsonb"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "748de226872459680cdd121b4b27369b73ae2edfeb9c75c03f1b8e240cb55f0c"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO command_execution_log (\n message_id, handler, action, status,\n result, error_message,\n duration_ms, tokens_used, cost_usd,\n executed_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Jsonb",
|
||||
"Text",
|
||||
"Int4",
|
||||
"Int4",
|
||||
"Float8",
|
||||
"Timestamptz"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "7b3d7e7af47f2f91193229925454e22e1ef1a8fec81174092b926880ca36a118"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE vlm_requests\n SET status = 'failed', error = $1, completed_at = NOW()\n WHERE id = $2\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "7d4e34cc4505455b678b45b2f884021a6cf786e0e86d8f15f1b324e6a8bcfac9"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE command_queue\n SET status = 'failed',\n processing_completed_at = $3,\n last_error = $2,\n retry_count = retry_count + 1\n WHERE message_id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"Timestamptz"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "89d0f71757cf23b1a02923e97ed0c1921cafbdd69844e43c41c00222d5595f18"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE vlm_consumer_offsets\n SET \n total_processed = total_processed + $1,\n total_succeeded = total_succeeded + $2,\n total_failed = total_failed + $3\n WHERE consumer_id = $4\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8",
|
||||
"Int8",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "8fb9ba962eb0fc70bca83f7523afe081285a79aacaf5821d2e41f7539c57ced6"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO vlm_dlq (original_id, original_request_type, original_priority, original_payload, error, retry_count)\n VALUES ($1, $2, $3, $4, $5, $6)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Varchar",
|
||||
"Int4",
|
||||
"Jsonb",
|
||||
"Text",
|
||||
"Int4"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "961e59ccb11c4e1674573d1e55e61dea1aa9eb9c78e506ba42aa1a42b891bf27"
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT\n message_id, queue_name, queue_type,\n command_type, command_category, command_action,\n key, value, priority,\n request_id, key_id, billing_context, token_usage, cost_usd,\n status, consumer_group, consumer_id,\n retry_count, max_retries, last_error,\n created_at, scheduled_at, processing_started_at, processing_completed_at\n FROM command_queue\n WHERE message_id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "message_id",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "queue_name",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "queue_type",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "command_type",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "command_category",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 5,
|
||||
"name": "command_action",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 6,
|
||||
"name": "key",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "value",
|
||||
"type_info": "Jsonb"
|
||||
},
|
||||
{
|
||||
"ordinal": 8,
|
||||
"name": "priority",
|
||||
"type_info": "Int2"
|
||||
},
|
||||
{
|
||||
"ordinal": 9,
|
||||
"name": "request_id",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 10,
|
||||
"name": "key_id",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 11,
|
||||
"name": "billing_context",
|
||||
"type_info": "Jsonb"
|
||||
},
|
||||
{
|
||||
"ordinal": 12,
|
||||
"name": "token_usage",
|
||||
"type_info": "Jsonb"
|
||||
},
|
||||
{
|
||||
"ordinal": 13,
|
||||
"name": "cost_usd",
|
||||
"type_info": "Float8"
|
||||
},
|
||||
{
|
||||
"ordinal": 14,
|
||||
"name": "status",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 15,
|
||||
"name": "consumer_group",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 16,
|
||||
"name": "consumer_id",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 17,
|
||||
"name": "retry_count",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 18,
|
||||
"name": "max_retries",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 19,
|
||||
"name": "last_error",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 20,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 21,
|
||||
"name": "scheduled_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 22,
|
||||
"name": "processing_started_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 23,
|
||||
"name": "processing_completed_at",
|
||||
"type_info": "Timestamptz"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "a09f617a37776df57c4e711b25e62075db983095764bb5f2bae1e3dfddc3b243"
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT \n id as offset,\n request_type,\n priority,\n payload\n FROM vlm_requests\n WHERE status = 'pending'\n ORDER BY priority ASC, created_at ASC\n LIMIT $1\n FOR UPDATE SKIP LOCKED\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "offset",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "request_type",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "priority",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "payload",
|
||||
"type_info": "Jsonb"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "ab09a5b7e35daf5fa5085ce9a986c9d58de60f4b9ffc0a127a7d17694d42277a"
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT id, request_type, payload, retry_count, priority\n FROM vlm_requests\n WHERE id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "request_type",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "payload",
|
||||
"type_info": "Jsonb"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "retry_count",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "priority",
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "ec65769979d98dae69f4bb8ef280bb55ec401b86eaa01e80e63833654125733d"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE vlm_requests\n SET \n status = 'pending',\n retry_count = retry_count + 1,\n error = $1\n WHERE id = $2\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "fff0adae6b82b647111a1d27ac7c0a9e15311a8bacd4c1a5b7229e511df45954"
|
||||
}
|
||||
@@ -936,14 +936,19 @@ shellcheck scripts/*.sh monitor/**/*.sh
|
||||
|
||||
## Gitea Sync
|
||||
|
||||
主要 sync 管道為 Gitea:`http://192.168.110.200:3000/admin/momentry_core.git`
|
||||
主要 sync 管道為 Gitea:`http://192.168.110.210:3000/warren/momentry_core.git`(m4mini)
|
||||
|
||||
> **2026-11-05 更正**:舊文檔記載的 `http://192.168.110.200:3000/admin/momentry_core.git`
|
||||
> 已失效(主機無回應)。本機實際 remote 為 m4mini 的 `warren/momentry_core`,分支
|
||||
> `feature/dynamic-concurrency-*` 為進行中工作分支。可用測試:
|
||||
> `curl -s -u "warren:<TOKEN>" http://192.168.110.210:3000/api/v1/repos/warren/momentry_core`
|
||||
|
||||
### 產生 Access Token(首次設定)
|
||||
|
||||
```bash
|
||||
# admin 帳號密碼為 AccusysTest!
|
||||
TOKEN=$(curl -s -X POST "http://192.168.110.200:3000/api/v1/users/admin/tokens" \
|
||||
-u "admin:AccusysTest!" \
|
||||
# 登入 warren 帳號後於 API 產生 token(scopes: write:repository)
|
||||
TOKEN=$(curl -s -X POST "http://192.168.110.210:3000/api/v1/users/warren/tokens" \
|
||||
-u "warren:<PASSWORD>" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name":"m5max128_push","scopes":["write:repository"]}' | jq -r '.sha1')
|
||||
echo $TOKEN
|
||||
@@ -953,11 +958,11 @@ echo $TOKEN
|
||||
|
||||
```bash
|
||||
# 用 token 取代密碼
|
||||
git remote add origin http://admin:TOKEN@192.168.110.200:3000/admin/momentry_core.git
|
||||
git remote add origin http://warren:TOKEN@192.168.110.210:3000/warren/momentry_core.git
|
||||
|
||||
# 同步
|
||||
git pull origin main
|
||||
git push origin main
|
||||
git pull origin feature/dynamic-concurrency-v1.3.4
|
||||
git push origin feature/dynamic-concurrency-v1.3.4
|
||||
```
|
||||
|
||||
### Token 記錄
|
||||
@@ -968,6 +973,16 @@ git push origin main
|
||||
|
||||
**注意**: Token 有 write:repository scope,勿外洩。如需新增 token 給其他機器,各自產自己的 token。
|
||||
|
||||
### 機器清單
|
||||
|
||||
| 機器名稱 | IP 地址 | 用途 |
|
||||
|----------|---------|------|
|
||||
| **m5max48** (本機) | 192.168.110.201 | Momentry Core 後端服務 (port 3002) |
|
||||
| **m4promini** | 192.168.110.203 | Studio 前端服務 |
|
||||
| **m4mini** | 192.168.110.210 | 待確認用途 |
|
||||
|
||||
---
|
||||
|
||||
## Release Workflow
|
||||
|
||||
### Release 前準備
|
||||
|
||||
Generated
+746
-3
File diff suppressed because it is too large
Load Diff
+15
-1
@@ -1,11 +1,12 @@
|
||||
[package]
|
||||
name = "momentry_core"
|
||||
version = "1.3.2"
|
||||
version = "1.3.5"
|
||||
edition = "2021"
|
||||
authors = ["Momentry Team"]
|
||||
description = "Digital asset management system with video analysis and RAG"
|
||||
|
||||
[dependencies]
|
||||
sysinfo = "0.30"
|
||||
# Core
|
||||
anyhow = "1.0"
|
||||
thiserror = "1.0"
|
||||
@@ -17,6 +18,11 @@ once_cell = "1.19"
|
||||
libc = "0.2"
|
||||
dotenv = "0.15"
|
||||
|
||||
# Image processing (camera motion + pHash dedup)
|
||||
image = "0.25"
|
||||
ndarray = "0.16"
|
||||
rustfft = "6"
|
||||
|
||||
# CLI
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
|
||||
@@ -29,6 +35,7 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
regex = "1"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
urlencoding = "2.1"
|
||||
|
||||
# UUID
|
||||
sha2 = "0.10"
|
||||
@@ -84,6 +91,9 @@ crossterm = "0.28"
|
||||
# Terminal
|
||||
atty = "0.2"
|
||||
tokio-util = { version = "0.7.18", features = ["io"] }
|
||||
walkdir = "2.5.0"
|
||||
flate2 = "1.0"
|
||||
tar = "0.4"
|
||||
|
||||
# System
|
||||
|
||||
@@ -131,6 +141,10 @@ path = "src/bin/test_bm25_simple.rs"
|
||||
name = "integrated_player"
|
||||
path = "src/bin/integrated_player.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "docserver"
|
||||
path = "src/bin/docserver/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "pipeline_worker"
|
||||
path = "src/bin/pipeline_worker.rs"
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
# 移除 MongoDB 依賴 — 變更說明
|
||||
|
||||
## 問題
|
||||
m5max128 (192.168.110.200) 的 `/api/v1/health` 端點掛住,因為 health check
|
||||
等待 MongoDB 連線回應,但該機器未安裝 MongoDB。
|
||||
|
||||
## 修改內容
|
||||
|
||||
### `src/api/health.rs`
|
||||
| 變更 | 說明 |
|
||||
|---|---|
|
||||
| 移除 `MongoCache` import | 不再需要 MongoDB 型別 |
|
||||
| 移除 `check_mongodb()` 函數 | 不再檢查 MongoDB 健康狀態 |
|
||||
| `health()` 函數 | `all_ok` 條件改為只檢查 PostgreSQL + Redis + Qdrant |
|
||||
| `health_detailed()` 函數 | 同上,移除 MongoDB 檢查 |
|
||||
| `ServiceHealth` struct | `mongodb` 欄位註解化 |
|
||||
|
||||
### 影響範圍
|
||||
- Health 端點不再依賴 MongoDB
|
||||
- `AppState` 中的 `mongo_cache` 欄位仍保留(供其他功能使用)
|
||||
- server.rs 中的 MongoDB 初始化(5 秒 timeout → disabled fallback)維持原樣
|
||||
|
||||
## 重新編譯
|
||||
|
||||
### 目前阻礙
|
||||
`.sqlx/` 目錄只有 3 個查詢快取檔案,缺少:
|
||||
- `command/queue.rs` 的查詢快取
|
||||
- `vlm/consumer.rs` 的查詢快取
|
||||
|
||||
### 解決步驟
|
||||
```bash
|
||||
# 方法 1: 完整 .sqlx 快取(需要連線到 DB)
|
||||
cd /Users/accusys/momentry_core
|
||||
export DATABASE_URL="postgres://accusys@localhost:5432/momentry"
|
||||
cargo sqlx prepare
|
||||
SQLX_OFFLINE=true cargo build --release
|
||||
|
||||
# 方法 2: 修復現有查詢錯誤後再編譯
|
||||
# 檢查 src/core/command/queue.rs 和 src/core/vlm/consumer.rs 的 sqlx 巨集
|
||||
|
||||
# 編譯完成後替換 binary
|
||||
cp target/release/momentry ../momentry/bin/momentry
|
||||
```
|
||||
|
||||
### 部署到 203 (m4promini)
|
||||
```bash
|
||||
scp target/release/momentry accusys@192.168.110.203:~/momentry/bin/momentry
|
||||
ssh accusys@192.168.110.203 'launchctl stop com.momentry.server && launchctl start com.momentry.server'
|
||||
```
|
||||
|
||||
## 驗證
|
||||
重啟後測試:
|
||||
```bash
|
||||
curl -s -m 10 http://localhost:3002/api/v1/health
|
||||
# 應回傳: {"status":"ok", ...} 而不是超時
|
||||
```
|
||||
|
||||
## Git commit
|
||||
`4f4aa27d` on branch `feature/dynamic-concurrency-v1.3.4`
|
||||
@@ -0,0 +1,173 @@
|
||||
# Pipeline Configuration
|
||||
|
||||
**File**: `config/pipeline_flows.json`
|
||||
|
||||
---
|
||||
|
||||
## 📋 Purpose
|
||||
|
||||
This configuration file defines the processing pipeline for video analysis tasks. It controls:
|
||||
|
||||
- Which processors run and in what order
|
||||
- Tool selection and parameters
|
||||
- Execution conditions and dependencies
|
||||
- Failure handling and timeouts
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
### View Current Configuration
|
||||
|
||||
```bash
|
||||
# View pipeline configuration
|
||||
cat config/pipeline_flows.json | jq
|
||||
|
||||
# Check specific flow
|
||||
jq '.flows.register' config/pipeline_flows.json
|
||||
```
|
||||
|
||||
### Modify Configuration
|
||||
|
||||
1. Edit `config/pipeline_flows.json`
|
||||
2. Validate JSON syntax: `jq . config/pipeline_flows.json`
|
||||
3. Restart worker: `launchctl restart gui/$(id -u)/com.momentry.worker`
|
||||
|
||||
---
|
||||
|
||||
## 📊 Configuration Structure
|
||||
|
||||
```
|
||||
pipeline_flows.json
|
||||
├── version # Schema version
|
||||
├── enabled # Global enable/disable
|
||||
├── max_concurrent_stages # Concurrency limit
|
||||
├── default_timeout_secs # Default timeout
|
||||
└── flows # Pipeline definitions
|
||||
├── register # Full registration pipeline
|
||||
├── reprocess # Selective reprocessing
|
||||
└── phase1_pack # Packaging pipeline
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔄 Available Flows
|
||||
|
||||
### register
|
||||
|
||||
**Purpose**: Complete video processing pipeline
|
||||
|
||||
**Stages**: cut → asr → face → ocr → scene → asrx
|
||||
|
||||
**Usage**: Automatically triggered during video registration
|
||||
|
||||
---
|
||||
|
||||
### reprocess
|
||||
|
||||
**Purpose**: Selective reprocessing of specific processors
|
||||
|
||||
**Usage**: Manually triggered via Admin Panel or API
|
||||
|
||||
---
|
||||
|
||||
### phase1_pack
|
||||
|
||||
**Purpose**: Package Phase 1 results
|
||||
|
||||
**Usage**: Triggered after register completes
|
||||
|
||||
---
|
||||
|
||||
## 🔀 Execution Mode: Parallel vs Blocking
|
||||
|
||||
Each stage's `parallel` flag is the **single source of truth** for how the worker
|
||||
executes that stage. The worker reads it at runtime (via
|
||||
`src/core/pipeline_config.rs`) instead of hardcoding the mode per processor.
|
||||
|
||||
| `parallel` | Meaning | Worker behavior |
|
||||
|------------|---------|-----------------|
|
||||
| `true` | Non-blocking | Stage is dispatched to the background (pool or `tokio::spawn`); the worker poll loop continues. |
|
||||
| `false` | Blocking | Stage runs inline; the caller waits for it to finish before continuing. |
|
||||
|
||||
Unknown / missing stages default to `true` (parallel), so a missing entry never
|
||||
reintroduces blocking.
|
||||
|
||||
**Scene VLM example**: the `scene` stage is declared `"parallel": true`, so Scene
|
||||
VLM (which can run for hours on a large file) is spawned as a background task
|
||||
instead of being awaited inline. A semaphore (1 concurrent) and an in-flight set
|
||||
guard against duplicate spawns across poll cycles. Setting `"parallel": false`
|
||||
would restore the previous inline/blocking behavior.
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Tool Selection
|
||||
|
||||
### Priority System
|
||||
|
||||
- **0**: Highest priority (preferred tool)
|
||||
- **1-99**: Fallback tools
|
||||
|
||||
### Example
|
||||
|
||||
```json
|
||||
{
|
||||
"tools": [
|
||||
{
|
||||
"name": "swift_face",
|
||||
"priority": 0,
|
||||
"description": "ANE accelerated"
|
||||
},
|
||||
{
|
||||
"name": "python_insightface",
|
||||
"priority": 1,
|
||||
"description": "CPU fallback"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📚 Documentation
|
||||
|
||||
- **Full Guide**: `docs_v1.0/OPERATIONS/Pipeline_Configuration_Guide.md`
|
||||
- **Processor Reference**: `docs_v1.0/OPERATIONS/Processor_Commands_Reference.md`
|
||||
- **Tool Selector**: `docs_v1.0/DESIGN/Tool_Selector_V1.0.md`
|
||||
|
||||
---
|
||||
|
||||
## 🔍 Debugging
|
||||
|
||||
### Check Pipeline Status
|
||||
|
||||
```bash
|
||||
# View worker logs
|
||||
tail -f logs/worker_3002.log | grep -E "Pipeline|Stage"
|
||||
|
||||
# Check processor jobs
|
||||
psql -U accusys -d momentry -c "SELECT uuid, processor_type, status FROM processor_jobs ORDER BY created_at DESC LIMIT 10;"
|
||||
```
|
||||
|
||||
### Test Configuration
|
||||
|
||||
```bash
|
||||
# Validate JSON
|
||||
jq . config/pipeline_flows.json
|
||||
|
||||
# Check specific processor
|
||||
jq '.flows.register.stages[] | select(.name == "face")' config/pipeline_flows.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ Important
|
||||
|
||||
1. **Always validate JSON** before saving
|
||||
2. **Restart worker** after configuration changes
|
||||
3. **Backup configuration** before major changes
|
||||
4. **Test changes** in development environment first
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: 2026-10-14
|
||||
+304
-103
@@ -1,154 +1,355 @@
|
||||
{
|
||||
"filter_config": {
|
||||
"face": {
|
||||
"min_confidence": 0.5,
|
||||
"min_size": 30
|
||||
"version": "1.3.5",
|
||||
"updated_at": "2026-11-15T12:00:00+0800",
|
||||
"updated_by": "admin",
|
||||
"vlm_prompts": {
|
||||
"scene_vlm": {
|
||||
"system_prompt": "You are a helpful assistant that analyzes video scenes.",
|
||||
"user_prompt": "Describe this scene. What is happening? What objects and people are visible?",
|
||||
"max_tokens": 200,
|
||||
"description": "Scene analysis VLM prompt"
|
||||
},
|
||||
"rust_vlm_summary": {
|
||||
"system_prompt": "You are a helpful assistant that describes people in images.",
|
||||
"user_prompt": "Describe the person in this image. Focus on clothing, accessories, and distinctive features.",
|
||||
"max_tokens": 300,
|
||||
"description": "Face trace VLM prompt for person description"
|
||||
},
|
||||
"garbled_recovery": {
|
||||
"system_prompt": "You are a helpful assistant that verifies speech transcription quality.",
|
||||
"user_prompt": "Analyze this transcript for garbled text. Is it intelligible?",
|
||||
"max_tokens": 100,
|
||||
"description": "ASR garbled text recovery prompt"
|
||||
}
|
||||
},
|
||||
"llm_config": {
|
||||
"chat": {
|
||||
"model": "gemma-4-12b-it",
|
||||
"timeout": 30,
|
||||
"url": "http://localhost:8080/v1/chat/completions"
|
||||
},
|
||||
"summary": {
|
||||
"url": "http://127.0.0.1:8080/v1/chat/completions",
|
||||
"model": "gemma-4-12b-it",
|
||||
"timeout": 60,
|
||||
"url": "http://localhost:8080/v1/chat/completions"
|
||||
"fallbacks": [
|
||||
"http://127.0.0.1:8082/v1/chat/completions"
|
||||
],
|
||||
"strategy": "priority",
|
||||
"enabled": true
|
||||
},
|
||||
"vlm": {
|
||||
"url": "http://127.0.0.1:8082/v1/chat/completions",
|
||||
"model": "gemma-4-12b-it",
|
||||
"timeout": 120,
|
||||
"fallbacks": [
|
||||
"http://127.0.0.1:8080/v1/chat/completions"
|
||||
],
|
||||
"strategy": "priority",
|
||||
"enabled": false
|
||||
},
|
||||
"chat": {
|
||||
"url": "http://127.0.0.1:8080/v1/chat/completions",
|
||||
"model": "gemma-4-12b-it",
|
||||
"timeout": 30,
|
||||
"fallbacks": [
|
||||
"http://127.0.0.1:8082/v1/chat/completions"
|
||||
],
|
||||
"strategy": "priority",
|
||||
"enabled": true
|
||||
},
|
||||
"embedding": {
|
||||
"url": "http://127.0.0.1:11436/v1/embeddings",
|
||||
"model": "embeddinggemma",
|
||||
"timeout": 60,
|
||||
"fallbacks": [],
|
||||
"strategy": "priority",
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
"processor_config": {
|
||||
"ASRX": {
|
||||
"default_tool": "swift",
|
||||
"enabled": true,
|
||||
"timeout": 3600,
|
||||
"tools": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "swift",
|
||||
"parameters": {},
|
||||
"priority": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"CUT": {
|
||||
"default_tool": "rust",
|
||||
"enabled": true,
|
||||
"timeout": 3600,
|
||||
"tools": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "rust",
|
||||
"parameters": {},
|
||||
"priority": 0
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "python",
|
||||
"parameters": {},
|
||||
"priority": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
"FACE": {
|
||||
"default_tool": "swift",
|
||||
"enabled": true,
|
||||
"timeout": 3600,
|
||||
"enabled": true,
|
||||
"tools": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "swift",
|
||||
"parameters": {},
|
||||
"priority": 0
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "python",
|
||||
"parameters": {},
|
||||
"priority": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
"FACE_TRACE": {
|
||||
"default_tool": "rust",
|
||||
"enabled": true,
|
||||
"timeout": 3600,
|
||||
"tools": [
|
||||
{
|
||||
"priority": 2,
|
||||
"enabled": true,
|
||||
"name": "rust",
|
||||
"parameters": {},
|
||||
"priority": 0
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "python",
|
||||
"parameters": {},
|
||||
"priority": 1
|
||||
"parameters": {}
|
||||
}
|
||||
]
|
||||
],
|
||||
"default_tool": "swift"
|
||||
},
|
||||
"OCR": {
|
||||
"default_tool": "swift",
|
||||
"enabled": true,
|
||||
"timeout": 3600,
|
||||
"enabled": true,
|
||||
"tools": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "swift",
|
||||
"parameters": {},
|
||||
"priority": 0
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
}
|
||||
]
|
||||
],
|
||||
"default_tool": "swift"
|
||||
},
|
||||
"CUT": {
|
||||
"timeout": 3600,
|
||||
"enabled": true,
|
||||
"tools": [
|
||||
{
|
||||
"name": "rust",
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
},
|
||||
{
|
||||
"name": "python",
|
||||
"priority": 2,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
}
|
||||
],
|
||||
"default_tool": "rust"
|
||||
},
|
||||
"ASRX": {
|
||||
"timeout": 3600,
|
||||
"enabled": true,
|
||||
"tools": [
|
||||
{
|
||||
"name": "swift",
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
}
|
||||
],
|
||||
"default_tool": "swift"
|
||||
},
|
||||
"FACE_TRACE": {
|
||||
"timeout": 3600,
|
||||
"enabled": true,
|
||||
"tools": [
|
||||
{
|
||||
"name": "rust",
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
},
|
||||
{
|
||||
"name": "python",
|
||||
"priority": 1,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
}
|
||||
],
|
||||
"default_tool": "rust"
|
||||
},
|
||||
"FACE_CLUSTER": {
|
||||
"timeout": 3600,
|
||||
"enabled": true,
|
||||
"tools": [
|
||||
{
|
||||
"name": "rust",
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
}
|
||||
],
|
||||
"default_tool": "rust"
|
||||
},
|
||||
"SCENE_VLM": {
|
||||
"timeout": 7200,
|
||||
"enabled": true,
|
||||
"tools": [
|
||||
{
|
||||
"name": "python",
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
}
|
||||
],
|
||||
"default_tool": "python"
|
||||
},
|
||||
"POSE": {
|
||||
"default_tool": "swift",
|
||||
"enabled": true,
|
||||
"timeout": 3600,
|
||||
"enabled": true,
|
||||
"tools": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "swift",
|
||||
"parameters": {},
|
||||
"priority": 0
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "rust",
|
||||
"parameters": {},
|
||||
"priority": 1
|
||||
"priority": 1,
|
||||
"enabled": true,
|
||||
"parameters": {}
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "mediapipe",
|
||||
"priority": 2,
|
||||
"enabled": true,
|
||||
"parameters": {
|
||||
"min_confidence": 0.5,
|
||||
"model_complexity": 2
|
||||
},
|
||||
"priority": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"default_tool": "swift"
|
||||
}
|
||||
},
|
||||
"filter_config": {
|
||||
"face": {
|
||||
"min_confidence": 0.5,
|
||||
"min_size": 30,
|
||||
"min_capture_quality": 0.25
|
||||
}
|
||||
},
|
||||
"face_filter_defaults": {
|
||||
"min_confidence": 50.0,
|
||||
"min_size": 1,
|
||||
"min_capture_quality": 0.25
|
||||
},
|
||||
"paths": {
|
||||
"output_dir": "/Users/accusys/momentry/output/demo",
|
||||
"backup_dir": "/Users/accusys/momentry/var/backup",
|
||||
"scripts_dir": "/Users/accusys/momentry/scripts",
|
||||
"cli_dir": "/Users/accusys/momentry/tools/cli",
|
||||
"python_path": "/opt/homebrew/bin/python3.11",
|
||||
"ffmpeg_path": "/opt/homebrew/bin/ffmpeg"
|
||||
},
|
||||
"concurrency": {
|
||||
"max_concurrent_jobs": 2,
|
||||
"poll_interval": 5,
|
||||
"batch_size": 5,
|
||||
"processor_timeout_secs": 3600
|
||||
},
|
||||
"feature_flags": {
|
||||
"cache_enabled": true,
|
||||
"auto_pipeline_enabled": false,
|
||||
"watcher_auto_register": false,
|
||||
"summary_enabled": true
|
||||
},
|
||||
"server": {
|
||||
"port": 3002,
|
||||
"media_base_url": "http://localhost:8888",
|
||||
"serve_base_url": "http://localhost:8888",
|
||||
"storage_root": "/Users/accusys/momentry/var/sftpgo/data",
|
||||
"timezone": "Asia/Taipei"
|
||||
},
|
||||
"admin_settings": {
|
||||
"session_timeout": 3600,
|
||||
"max_login_attempts": 5,
|
||||
"api_key_expiry_days": 365,
|
||||
"system_stats_refresh_sec": 5,
|
||||
"preferred_language": "en",
|
||||
"library_default_sort": "name_asc"
|
||||
},
|
||||
"search": {
|
||||
"vlm_max_results": 5,
|
||||
"vlm_min_score": 0,
|
||||
"vlm_min_score": 0.0,
|
||||
"vlm_output_language": "ja"
|
||||
},
|
||||
"system_config": {},
|
||||
"version": "1.0.0",
|
||||
"vlm_prompts": {
|
||||
"rust_vlm_summary": {
|
||||
"description": "Face trace VLM prompt for person description",
|
||||
"max_tokens": 300,
|
||||
"system_prompt": "You are a helpful assistant that describes people in images.",
|
||||
"user_prompt": "Describe the person in this image. Focus on clothing, accessories, and distinctive features."
|
||||
},
|
||||
"scene_vlm": {
|
||||
"description": "Scene analysis VLM prompt",
|
||||
"max_tokens": 200,
|
||||
"system_prompt": "You are a helpful assistant that analyzes video scenes.",
|
||||
"user_prompt": "Describe this scene. What is happening? What objects and people are visible?"
|
||||
"pipeline": {
|
||||
"enabled": true,
|
||||
"max_concurrent_stages": 5,
|
||||
"default_timeout_secs": 7200,
|
||||
"flows": {
|
||||
"register": {
|
||||
"name": "register",
|
||||
"description": "Full registration pipeline: all processors",
|
||||
"version": "1.0",
|
||||
"enabled": true,
|
||||
"stages": [
|
||||
{
|
||||
"name": "probe",
|
||||
"processor_type": "probe",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 300
|
||||
},
|
||||
{
|
||||
"name": "cut",
|
||||
"processor_type": "cut",
|
||||
"required": true,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600
|
||||
},
|
||||
{
|
||||
"name": "face",
|
||||
"processor_type": "face",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600
|
||||
},
|
||||
{
|
||||
"name": "ocr",
|
||||
"processor_type": "ocr",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600
|
||||
},
|
||||
{
|
||||
"name": "asrx",
|
||||
"processor_type": "asrx",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600
|
||||
},
|
||||
{
|
||||
"name": "scene_vlm",
|
||||
"processor_type": "scene_vlm",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 7200
|
||||
},
|
||||
{
|
||||
"name": "face_trace",
|
||||
"processor_type": "face_trace",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600
|
||||
},
|
||||
{
|
||||
"name": "face_cluster",
|
||||
"processor_type": "face_cluster",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600
|
||||
}
|
||||
]
|
||||
},
|
||||
"reindex": {
|
||||
"name": "reindex",
|
||||
"description": "Re-index pipeline: chunks + vectors + TKG",
|
||||
"version": "1.0",
|
||||
"enabled": true,
|
||||
"stages": [
|
||||
{
|
||||
"name": "chunk",
|
||||
"processor_type": "chunk",
|
||||
"required": true,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600
|
||||
},
|
||||
{
|
||||
"name": "vectorize",
|
||||
"processor_type": "vectorize",
|
||||
"required": true,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600
|
||||
},
|
||||
{
|
||||
"name": "tkg",
|
||||
"processor_type": "tkg",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 7200
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"updated_at": "2026-10-16T17:00:00Z",
|
||||
"updated_by": "core_team",
|
||||
"enabled": true,
|
||||
"max_concurrent_stages": 3,
|
||||
"default_timeout_secs": 3600,
|
||||
"phases": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "基础分析",
|
||||
"name_en": "Foundation",
|
||||
"description": "场景切分与分析",
|
||||
"progress_weight": 0.15,
|
||||
"color": "#4CAF50",
|
||||
"icon": "foundation",
|
||||
"parallel_strategy": "sequential",
|
||||
"processors": ["cut"]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "核心处理",
|
||||
"name_en": "Core Processing",
|
||||
"description": "语音识别、人脸检测、文字识别",
|
||||
"progress_weight": 0.60,
|
||||
"color": "#2196F3",
|
||||
"icon": "processing",
|
||||
"parallel_strategy": "limited_parallel",
|
||||
"max_concurrent": 3,
|
||||
"processors": ["asr_asrx", "face", "ocr"]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "深度分析",
|
||||
"name_en": "Deep Analysis",
|
||||
"description": "说话人识别、场景描述、人脸聚类",
|
||||
"progress_weight": 0.20,
|
||||
"color": "#9C27B0",
|
||||
"icon": "analysis",
|
||||
"parallel_strategy": "limited_parallel",
|
||||
"max_concurrent": 3,
|
||||
"processors": ["scene_vlm", "face_trace", "face_cluster"]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "知识构建",
|
||||
"name_en": "Knowledge Building",
|
||||
"description": "时序知识图谱构建",
|
||||
"progress_weight": 0.05,
|
||||
"color": "#FF9800",
|
||||
"icon": "knowledge",
|
||||
"parallel_strategy": "sequential",
|
||||
"processors": ["tkg"]
|
||||
}
|
||||
],
|
||||
"flows": {
|
||||
"register": {
|
||||
"name": "Video Registration Pipeline",
|
||||
"description": "Complete video processing pipeline for new video files",
|
||||
"version": "2.0.0",
|
||||
"enabled": true,
|
||||
"stages": [
|
||||
{
|
||||
"name": "cut",
|
||||
"processor_type": "cut",
|
||||
"phase": 1,
|
||||
"phase_name": "基础分析",
|
||||
"phase_name_en": "Foundation",
|
||||
"progress_weight": 1.0,
|
||||
"display_name": "场景切分",
|
||||
"display_name_en": "Scene Cut Detection",
|
||||
"description": "Scene cut detection using ffmpeg or Python scenedetect",
|
||||
"required": true,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600,
|
||||
"parallel": false,
|
||||
"estimated_time_secs": 5,
|
||||
"resource_type": "cpu",
|
||||
"dependencies": [],
|
||||
"tool": {
|
||||
"name": "rust_cut",
|
||||
"priority": 0,
|
||||
"description": "High-performance Rust-based scene detection",
|
||||
"parameters": {
|
||||
"min_scene_duration": 0.5,
|
||||
"threshold": 0.3
|
||||
},
|
||||
"usage_notes": "Uses ffmpeg for native detection. Falls back to Python scenedetect if unavailable."
|
||||
},
|
||||
"condition": {
|
||||
"skip_if_exists": "*.cut.json"
|
||||
},
|
||||
"on_failure": "continue"
|
||||
},
|
||||
{
|
||||
"name": "asr_asrx",
|
||||
"processor_type": "asr_asrx",
|
||||
"phase": 2,
|
||||
"phase_name": "核心处理",
|
||||
"phase_name_en": "Core Processing",
|
||||
"progress_weight": 0.35,
|
||||
"display_name": "語音識別與說話人分離",
|
||||
"display_name_en": "ASR + Speaker Diarization",
|
||||
"description": "Automatic Speech Recognition with Speaker Diarization using Rust + MLX Whisper",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600,
|
||||
"parallel": true,
|
||||
"estimated_time_secs": 25,
|
||||
"resource_type": "gpu",
|
||||
"dependencies": [],
|
||||
"tool": {
|
||||
"name": "rust_asr_asrx",
|
||||
"priority": 0,
|
||||
"description": "High-performance Rust ASR + Diarization with MLX Whisper",
|
||||
"parameters": {
|
||||
"model": "/Users/accusys/models/whisper-small-mlx",
|
||||
"diarize": true
|
||||
},
|
||||
"usage_notes": "Combines ASR and Diarization in one processor. Uses verified whisper-small-mlx model."
|
||||
},
|
||||
"condition": {
|
||||
"skip_if_exists": "*.asrx.json"
|
||||
},
|
||||
"on_failure": "continue"
|
||||
},
|
||||
{
|
||||
"name": "face",
|
||||
"processor_type": "face",
|
||||
"phase": 2,
|
||||
"phase_name": "核心处理",
|
||||
"phase_name_en": "Core Processing",
|
||||
"progress_weight": 0.35,
|
||||
"display_name": "人脸检测",
|
||||
"display_name_en": "Face Detection",
|
||||
"description": "Face detection and tracking",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 7200,
|
||||
"parallel": true,
|
||||
"estimated_time_secs": 15,
|
||||
"resource_type": "ane",
|
||||
"dependencies": [],
|
||||
"tool": {
|
||||
"name": "swift_face",
|
||||
"priority": 0,
|
||||
"description": "Apple Vision framework face detection (ANE accelerated)",
|
||||
"parameters": {
|
||||
"min_confidence": 0.5,
|
||||
"min_size": 1
|
||||
},
|
||||
"usage_notes": "Uses Apple Neural Engine for acceleration. Falls back to Python InsightFace if unavailable."
|
||||
},
|
||||
"condition": {
|
||||
"skip_if_exists": "*.face.json"
|
||||
},
|
||||
"on_failure": "continue"
|
||||
},
|
||||
{
|
||||
"name": "ocr",
|
||||
"processor_type": "ocr",
|
||||
"phase": 2,
|
||||
"phase_name": "核心处理",
|
||||
"phase_name_en": "Core Processing",
|
||||
"progress_weight": 0.30,
|
||||
"display_name": "文字识别",
|
||||
"display_name_en": "OCR",
|
||||
"description": "OCR text extraction using Apple Vision Framework",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 7200,
|
||||
"parallel": true,
|
||||
"estimated_time_secs": 10,
|
||||
"resource_type": "ane",
|
||||
"dependencies": [],
|
||||
"tool": {
|
||||
"name": "swift_ocr",
|
||||
"priority": 0,
|
||||
"description": "Apple Vision VNRecognizeTextRequest (ANE accelerated)",
|
||||
"parameters": {
|
||||
"recognition_level": "accurate",
|
||||
"uses_language_correction": true
|
||||
},
|
||||
"usage_notes": "Uses Apple Neural Engine for acceleration. Supports multiple languages with real-time recognition. 2.5x faster than Python (2s vs 5s)."
|
||||
},
|
||||
"condition": {
|
||||
"skip_if_exists": "*.ocr.json"
|
||||
},
|
||||
"on_failure": "continue"
|
||||
},
|
||||
{
|
||||
"name": "scene_vlm",
|
||||
"processor_type": "scene_vlm",
|
||||
"phase": 3,
|
||||
"phase_name": "深度分析",
|
||||
"phase_name_en": "Deep Analysis",
|
||||
"progress_weight": 0.35,
|
||||
"display_name": "场景描述",
|
||||
"display_name_en": "Scene Description",
|
||||
"description": "Scene VLM analysis for scene descriptions",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 7200,
|
||||
"parallel": true,
|
||||
"estimated_time_secs": 10,
|
||||
"resource_type": "gpu",
|
||||
"dependencies": ["cut"],
|
||||
"tool": {
|
||||
"name": "gemma_vlm",
|
||||
"priority": 0,
|
||||
"description": "Gemma 4 12B with mmproj for vision-language analysis",
|
||||
"parameters": {
|
||||
"max_tokens": 900,
|
||||
"temperature": 0.1
|
||||
},
|
||||
"usage_notes": "Generates scene descriptions in multiple languages. Requires mmproj loaded."
|
||||
},
|
||||
"condition": {
|
||||
"depends_on": "cut",
|
||||
"skip_if_exists": "*.scenes.json"
|
||||
},
|
||||
"on_failure": "continue"
|
||||
},
|
||||
{
|
||||
"name": "face_trace",
|
||||
"processor_type": "face_trace",
|
||||
"phase": 3,
|
||||
"phase_name": "深度分析",
|
||||
"phase_name_en": "Deep Analysis",
|
||||
"progress_weight": 0.20,
|
||||
"display_name": "人脸追踪",
|
||||
"display_name_en": "Face Tracing",
|
||||
"description": "Face tracking to generate face traces using IoU + Embedding Similarity",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600,
|
||||
"parallel": true,
|
||||
"estimated_time_secs": 5,
|
||||
"resource_type": "cpu",
|
||||
"dependencies": ["face"],
|
||||
"tool": {
|
||||
"name": "rust_face_trace",
|
||||
"priority": 0,
|
||||
"description": "Rust-based face tracking with IoU + Embedding similarity matching",
|
||||
"parameters": {
|
||||
"similarity_threshold": 0.85,
|
||||
"iou_threshold": 0.3
|
||||
},
|
||||
"usage_notes": "Uses Qdrant _faces collection for embeddings. Matches faces based on IoU (bbox overlap) and embedding similarity. Traces are continuous face sequences; same person may have multiple traces due to cuts or temporary exits."
|
||||
},
|
||||
"condition": {
|
||||
"depends_on": "face",
|
||||
"skip_if_exists": "*.face_traced.json"
|
||||
},
|
||||
"on_failure": "continue"
|
||||
},
|
||||
{
|
||||
"name": "face_cluster",
|
||||
"processor_type": "face_cluster",
|
||||
"phase": 3,
|
||||
"phase_name": "深度分析",
|
||||
"phase_name_en": "Deep Analysis",
|
||||
"progress_weight": 0.25,
|
||||
"display_name": "人脸聚类",
|
||||
"display_name_en": "Face Clustering",
|
||||
"description": "Face clustering and grouping with improved threshold",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600,
|
||||
"parallel": true,
|
||||
"estimated_time_secs": 5,
|
||||
"resource_type": "cpu",
|
||||
"dependencies": ["face_trace"],
|
||||
"tool": {
|
||||
"name": "rust_face_cluster",
|
||||
"priority": 0,
|
||||
"description": "Rust-based face clustering with Stage 2 merge support",
|
||||
"parameters": {
|
||||
"threshold": 0.15,
|
||||
"stage2": false,
|
||||
"method": "leader",
|
||||
"min_face_count": 20,
|
||||
"max_bbox_area": 150000
|
||||
},
|
||||
"usage_notes": "Uses Qdrant _faces collection for embeddings. Threshold=0.15 to correctly separate male/female faces. Stage 2 merge disabled to prevent over-merging. Auto-filters low-quality clusters: face_count<20 or bbox_area>150000 (hand/object detections)."
|
||||
},
|
||||
"condition": {
|
||||
"depends_on": "face_trace",
|
||||
"skip_if_exists": "*.face_cluster.json"
|
||||
},
|
||||
"on_failure": "continue"
|
||||
},
|
||||
{
|
||||
"name": "tkg",
|
||||
"processor_type": "tkg",
|
||||
"phase": 4,
|
||||
"phase_name": "知识构建",
|
||||
"phase_name_en": "Knowledge Building",
|
||||
"progress_weight": 1.0,
|
||||
"display_name": "知识图谱",
|
||||
"display_name_en": "Knowledge Graph",
|
||||
"description": "Temporal knowledge graph construction",
|
||||
"required": false,
|
||||
"enabled": true,
|
||||
"timeout_secs": 3600,
|
||||
"parallel": false,
|
||||
"estimated_time_secs": 5,
|
||||
"resource_type": "cpu",
|
||||
"dependencies": ["asr_asrx", "face_cluster"],
|
||||
"condition": {
|
||||
"depends_on": ["asr_asrx", "face_cluster"],
|
||||
"skip_if_exists": "*.tkg.json"
|
||||
},
|
||||
"on_failure": "continue"
|
||||
}
|
||||
]
|
||||
},
|
||||
"reprocess": {
|
||||
"name": "Reprocessing Pipeline",
|
||||
"description": "Selective reprocessing of specific processors",
|
||||
"version": "2.0.0",
|
||||
"enabled": true,
|
||||
"stages": []
|
||||
},
|
||||
"phase1_pack": {
|
||||
"name": "Phase 1 Packaging Pipeline",
|
||||
"description": "Package Phase 1 results for delivery",
|
||||
"version": "2.0.0",
|
||||
"enabled": true,
|
||||
"stages": [
|
||||
{
|
||||
"name": "pack",
|
||||
"processor_type": "pack",
|
||||
"phase": 4,
|
||||
"phase_name": "知识构建",
|
||||
"phase_name_en": "Knowledge Building",
|
||||
"progress_weight": 1.0,
|
||||
"display_name": "打包",
|
||||
"display_name_en": "Pack",
|
||||
"description": "Create release package with all Phase 1 outputs",
|
||||
"required": true,
|
||||
"enabled": true,
|
||||
"timeout_secs": 600,
|
||||
"parallel": false,
|
||||
"estimated_time_secs": 10,
|
||||
"resource_type": "cpu",
|
||||
"dependencies": [],
|
||||
"parameters": {
|
||||
"phase": 1,
|
||||
"include_metadata": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
-271
@@ -1,97 +1,5 @@
|
||||
{
|
||||
"processor_config": {
|
||||
"pose": {
|
||||
"implementations": [
|
||||
{
|
||||
"tool": "rust",
|
||||
"model": null,
|
||||
"priority": 1,
|
||||
"enabled": false,
|
||||
"command": {
|
||||
"executable": "tools/cli/rust/target/release/rust_pose",
|
||||
"args": [
|
||||
"--video",
|
||||
"{video_path}",
|
||||
"--output",
|
||||
"{output_path}",
|
||||
"--uuid",
|
||||
"{file_uuid}"
|
||||
]
|
||||
},
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.pose.json",
|
||||
"timeout": 1800
|
||||
},
|
||||
{
|
||||
"tool": "swift",
|
||||
"model": null,
|
||||
"priority": 0,
|
||||
"enabled": false,
|
||||
"command": {
|
||||
"executable": "scripts/swift_processors/.build/release/swift_pose",
|
||||
"args": [
|
||||
"{video_path}",
|
||||
"--output",
|
||||
"{output_path}",
|
||||
"--uuid",
|
||||
"{file_uuid}"
|
||||
]
|
||||
},
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.pose.json",
|
||||
"timeout": 1800
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"model": "mediapipe",
|
||||
"priority": 2,
|
||||
"enabled": false,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/pose_processor_mediapipe.py",
|
||||
"args": [
|
||||
"{video_path}",
|
||||
"{output_path}",
|
||||
"--uuid",
|
||||
"{file_uuid}",
|
||||
"--model-complexity",
|
||||
"{model_complexity}"
|
||||
]
|
||||
},
|
||||
"parameters": {
|
||||
"model_complexity": 2,
|
||||
"model_path": "/Users/accusys/models/mediapipe/pose_landmarker_heavy.task"
|
||||
},
|
||||
"output_file": "{file_uuid}.pose.json",
|
||||
"timeout": 3600
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"model": "yolov8-pose",
|
||||
"priority": 3,
|
||||
"enabled": false,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/pose_processor_yolov8.py",
|
||||
"args": [
|
||||
"{video_path}",
|
||||
"{output_path}",
|
||||
"--model",
|
||||
"{model_file}"
|
||||
]
|
||||
},
|
||||
"parameters": {
|
||||
"model_file": "yolov8n-pose.pt"
|
||||
},
|
||||
"output_file": "{file_uuid}.pose.json",
|
||||
"timeout": 3600
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"tool": "rust",
|
||||
"model": null
|
||||
}
|
||||
},
|
||||
"face": {
|
||||
"implementations": [
|
||||
{
|
||||
@@ -111,30 +19,6 @@
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.face.json",
|
||||
"timeout": 3600
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"model": "facenet",
|
||||
"priority": 2,
|
||||
"enabled": true,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/face_detector.py",
|
||||
"args": [
|
||||
"{video_path}",
|
||||
"{output_path}",
|
||||
"--uuid",
|
||||
"{file_uuid}",
|
||||
"--model",
|
||||
"{model_name}"
|
||||
]
|
||||
},
|
||||
"parameters": {
|
||||
"model_name": "facenet",
|
||||
"model_path": "/Users/accusys/models/facenet512.mlpackage"
|
||||
},
|
||||
"output_file": "{file_uuid}.face.json",
|
||||
"timeout": 3600
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
@@ -148,7 +32,7 @@
|
||||
"tool": "rust",
|
||||
"model": "whisper",
|
||||
"priority": 0,
|
||||
"enabled": false,
|
||||
"enabled": true,
|
||||
"command": {
|
||||
"executable": "tools/cli/rust/target/release/rust_whisper",
|
||||
"args": [
|
||||
@@ -166,64 +50,54 @@
|
||||
},
|
||||
"output_file": "{file_uuid}.asr.json",
|
||||
"timeout": 3600
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"model": "whisper",
|
||||
"priority": 1,
|
||||
"enabled": true,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/asr_processor_simplified.py",
|
||||
"args": [
|
||||
"{video_path}",
|
||||
"{output_path}",
|
||||
"--model",
|
||||
"{model_size}"
|
||||
]
|
||||
},
|
||||
"parameters": {
|
||||
"model_size": "large-v3",
|
||||
"model_dir": "/Users/accusys/models/whisper-small-mlx"
|
||||
},
|
||||
"output_file": "{file_uuid}.asr.json",
|
||||
"timeout": 7200
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"tool": "python",
|
||||
"tool": "rust",
|
||||
"model": "whisper"
|
||||
}
|
||||
},
|
||||
"asr_asrx": {
|
||||
"implementations": [
|
||||
{
|
||||
"tool": "rust",
|
||||
"model": "whisper",
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"command": {
|
||||
"executable": "tools/cli/rust/target/release/rust_asr_asrx",
|
||||
"args": [
|
||||
"--input",
|
||||
"{video_path}",
|
||||
"--output",
|
||||
"{output_path}",
|
||||
"--model",
|
||||
"/Users/accusys/models/whisper-small-mlx",
|
||||
"--diarize",
|
||||
"true"
|
||||
]
|
||||
},
|
||||
"parameters": {
|
||||
"model_dir": "/Users/accusys/models/whisper-small-mlx"
|
||||
},
|
||||
"output_file": "{file_uuid}.asrx.json",
|
||||
"timeout": 3600
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"tool": "rust",
|
||||
"model": "whisper"
|
||||
}
|
||||
},
|
||||
"asrx": {
|
||||
"implementations": [
|
||||
{
|
||||
"tool": "swift",
|
||||
"model": null,
|
||||
"priority": 0,
|
||||
"enabled": false,
|
||||
"command": {
|
||||
"executable": "scripts/swift_processors/.build/release/asrx_swift",
|
||||
"args": [
|
||||
"{video_path}",
|
||||
"--output",
|
||||
"{output_path}",
|
||||
"--uuid",
|
||||
"{file_uuid}"
|
||||
]
|
||||
},
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.asrx.json",
|
||||
"timeout": 1800
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"tool": "rust",
|
||||
"model": null,
|
||||
"priority": 0,
|
||||
"enabled": true,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/asrx_processor.py",
|
||||
"executable": "tools/cli/rust/target/release/rust_asrx",
|
||||
"args": [
|
||||
"{video_path}",
|
||||
"{output_path}",
|
||||
@@ -237,7 +111,7 @@
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"tool": "swift",
|
||||
"tool": "rust",
|
||||
"model": null
|
||||
}
|
||||
},
|
||||
@@ -261,25 +135,6 @@
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.ocr.json",
|
||||
"timeout": 3600
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"model": "tesseract",
|
||||
"priority": 2,
|
||||
"enabled": true,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/ocr_processor.py",
|
||||
"args": [
|
||||
"{video_path}",
|
||||
"{output_path}",
|
||||
"--uuid",
|
||||
"{file_uuid}"
|
||||
]
|
||||
},
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.ocr.json",
|
||||
"timeout": 3600
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
@@ -303,7 +158,9 @@
|
||||
"--min-trace-len",
|
||||
"{min_trace_len}",
|
||||
"--min-confidence",
|
||||
"{min_confidence}"
|
||||
"{min_confidence}",
|
||||
"--video-path",
|
||||
"{video_path}"
|
||||
]
|
||||
},
|
||||
"parameters": {
|
||||
@@ -312,25 +169,6 @@
|
||||
},
|
||||
"output_file": "{file_uuid}.face_traced.json",
|
||||
"timeout": 600
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"model": null,
|
||||
"priority": 1,
|
||||
"enabled": false,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/store_traced_faces.py",
|
||||
"args": [
|
||||
"--file-uuid",
|
||||
"{file_uuid}",
|
||||
"--face-json",
|
||||
"{face_json}"
|
||||
]
|
||||
},
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.face_traced.json",
|
||||
"timeout": 1200
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
@@ -364,37 +202,11 @@
|
||||
},
|
||||
"output_file": "{file_uuid}.scene_vlm.json",
|
||||
"timeout": 1800
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"model": "gemma-4-12b-it",
|
||||
"priority": 1,
|
||||
"enabled": false,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/scene_vlm_summary.py",
|
||||
"args": [
|
||||
"--file-uuid",
|
||||
"{file_uuid}",
|
||||
"--output-dir",
|
||||
"{output_dir}",
|
||||
"--llm-url",
|
||||
"{llm_url}",
|
||||
"--max-tokens",
|
||||
"{max_tokens}"
|
||||
]
|
||||
},
|
||||
"parameters": {
|
||||
"llm_url": "http://localhost:8080/v1/chat/completions",
|
||||
"max_tokens": 900
|
||||
},
|
||||
"output_file": "{file_uuid}.scene_vlm.json",
|
||||
"timeout": 1800
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"tool": "python",
|
||||
"model": "gemma-4-12b-it"
|
||||
"tool": "rust",
|
||||
"model": null
|
||||
}
|
||||
},
|
||||
"tkg": {
|
||||
@@ -403,7 +215,7 @@
|
||||
"tool": "rust",
|
||||
"model": null,
|
||||
"priority": 0,
|
||||
"enabled": false,
|
||||
"enabled": true,
|
||||
"command": {
|
||||
"executable": "tools/cli/rust/target/release/rust_tkg",
|
||||
"args": [
|
||||
@@ -416,29 +228,10 @@
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.tkg.json",
|
||||
"timeout": 1800
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"model": null,
|
||||
"priority": 1,
|
||||
"enabled": true,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/build_tkg.py",
|
||||
"args": [
|
||||
"--file-uuid",
|
||||
"{file_uuid}",
|
||||
"--output-dir",
|
||||
"{output_dir}"
|
||||
]
|
||||
},
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.tkg.json",
|
||||
"timeout": 1800
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"tool": "python",
|
||||
"tool": "rust",
|
||||
"model": null
|
||||
}
|
||||
},
|
||||
@@ -467,25 +260,6 @@
|
||||
},
|
||||
"output_file": "{file_uuid}.cut.json",
|
||||
"timeout": 1800
|
||||
},
|
||||
{
|
||||
"tool": "python",
|
||||
"model": null,
|
||||
"priority": 1,
|
||||
"enabled": false,
|
||||
"command": {
|
||||
"executable": "/opt/homebrew/bin/python3.11",
|
||||
"script": "scripts/cut_detector.py",
|
||||
"args": [
|
||||
"{video_path}",
|
||||
"{output_path}",
|
||||
"--uuid",
|
||||
"{file_uuid}"
|
||||
]
|
||||
},
|
||||
"parameters": {},
|
||||
"output_file": "{file_uuid}.cut.json",
|
||||
"timeout": 1800
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
@@ -556,4 +330,4 @@
|
||||
"priority_policy": "rust/swift CLI (priority 0) > python (priority 1+)",
|
||||
"last_updated": "2026-09-27"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,6 @@ deploy:
|
||||
@echo "Building WASM doc..."
|
||||
cd ../../md_wasm && wasm-pack build --target no-modules --no-opt 2>&1 | tail -2
|
||||
cp ../../md_wasm/pkg/md_wasm_bg.wasm ../doc_wasm/pkg/
|
||||
cp ../../docs_v1.0/API_WORKSPACE/modules/0*.md ../doc_wasm/modules/
|
||||
cp ../../docs_v1.0/API_WORKSPACE/modules/1*.md ../doc_wasm/modules/
|
||||
@echo " ✅ Updated ../doc_wasm/ (WASM docs)"
|
||||
@echo "Syncing ALL API modules..."
|
||||
cp ../../docs_v1.0/API_WORKSPACE/modules/*.md ../doc_wasm/modules/
|
||||
@echo " ✅ Updated ../doc_wasm/ (WASM docs) - ALL modules included"
|
||||
|
||||
@@ -1,60 +1,208 @@
|
||||
# API Workspace
|
||||
---
|
||||
title: API Documentation Index
|
||||
version: 1.0
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
## Purpose
|
||||
# API Documentation Index
|
||||
|
||||
This directory is the **single source of truth** for all API documentation modules.
|
||||
Generated outputs go to `../GUIDES/` as assembled deliverable documents.
|
||||
Complete API reference for Momentry Core. All endpoints are documented with request/response formats, examples, and error handling.
|
||||
|
||||
## Workflow
|
||||
---
|
||||
|
||||
## 📋 Module Overview
|
||||
|
||||
### Core APIs (01-19)
|
||||
|
||||
| Module | File | Description |
|
||||
|--------|------|-------------|
|
||||
| **01** | [auth.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/01_auth.md) | Authentication - login, logout, JWT, API key |
|
||||
| **02** | [health.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/02_health.md) | Health check endpoints |
|
||||
| **03** | [register.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/03_register.md) | File registration |
|
||||
| **04** | [lookup.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/04_lookup.md) | File lookup and metadata |
|
||||
| **05** | [process.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/05_process.md) | Video processing pipeline |
|
||||
| **06** | [search.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/06_search.md) | Search operations |
|
||||
| **07** | [identity.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/07_identity.md) | Identity management |
|
||||
| **08** | [identity_agent.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/08_identity_agent.md) | Identity agent operations |
|
||||
| **08** | [media.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/08_media.md) | Media access and proxy |
|
||||
| **09** | [tmdb.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/09_tmdb.md) | TMDb integration |
|
||||
| **10** | [pipeline.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/10_pipeline.md) | Pipeline management |
|
||||
| **11** | [error_codes.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/11_error_codes.md) | Error code reference |
|
||||
| **12** | [agent.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/12_agent.md) | Agent API |
|
||||
| **13** | [config.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/13_config.md) | Configuration management |
|
||||
| **14** | [identity_history.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/14_identity_history.md) | Identity history tracking |
|
||||
| **15** | [tkg.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/15_tkg.md) | Temporal Knowledge Graph |
|
||||
| **16** | [workspace.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/16_workspace.md) | Workspace management |
|
||||
| **17** | [progress.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/17_progress.md) | Progress tracking |
|
||||
| **18** | [profile.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/18_profile.md) | File profile and metadata |
|
||||
| **19** | [people_api.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/19_people_api.md) | People management API |
|
||||
|
||||
---
|
||||
|
||||
### New APIs (20-24)
|
||||
|
||||
| Module | File | Description | Status |
|
||||
|--------|------|-------------|--------|
|
||||
| **20** | [service_management_api.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/20_service_management_api.md) | Service start/stop/health | ✅ P0 - Critical |
|
||||
| **21** | [monitor_api.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/21_monitor_api.md) | Queue/Worker/Pipeline monitoring | ✅ P1 - Important |
|
||||
| **22** | [trace_agent_api.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/22_trace_agent_api.md) | Trace and TKG operations | ✅ P1 - Important |
|
||||
| **23** | [vlm_search_api.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/23_vlm_search_api.md) | Vision Language Model search | ✅ P1 - Important |
|
||||
| **24** | [pose_appearance_api.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/24_pose_appearance_api.md) | Pose keypoints and appearance colors | ✅ P2 - Standard |
|
||||
|
||||
---
|
||||
|
||||
### Studio Team Guides (21-26)
|
||||
|
||||
| Module | File | Description |
|
||||
|--------|------|-------------|
|
||||
| **21** | [studio_team_guide.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/21_studio_team_guide.md) | Integration guide for Studio team |
|
||||
| **22** | [studio_pipeline_changes.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/22_studio_pipeline_changes.md) | Pipeline changes documentation |
|
||||
| **23** | [studio_face_group_name_fix.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/23_studio_face_group_name_fix.md) | Face group name fix guide |
|
||||
| **24** | [studio_trace_profile_read_write_bug.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/24_studio_trace_profile_read_write_bug.md) | Trace profile bug documentation |
|
||||
| **25** | [face_filter_api.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/25_face_filter_api.md) | Face filtering API |
|
||||
| **26** | [trace_thumbnail_regenerate.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/26_trace_thumbnail_regenerate.md) | Thumbnail regeneration |
|
||||
|
||||
---
|
||||
|
||||
### Additional Modules
|
||||
|
||||
| File | Description |
|
||||
|------|-------------|
|
||||
| [scene_vlm_stats_api.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/scene_vlm_stats_api.md) | Scene VLM statistics API |
|
||||
| [99_incomplete.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/99_incomplete.md) | Incomplete features reference |
|
||||
| [_template.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/_template.md) | Documentation template |
|
||||
|
||||
---
|
||||
|
||||
## 🔍 Quick Reference by Category
|
||||
|
||||
### Authentication & Security
|
||||
|
||||
- [Auth API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/01_auth.md) - Login, logout, JWT tokens, API keys
|
||||
|
||||
### File Operations
|
||||
|
||||
- [Register](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/03_register.md) - Register new files
|
||||
- [Lookup](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/04_lookup.md) - File metadata and lookup
|
||||
- [Process](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/05_process.md) - Video processing
|
||||
- [Profile](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/18_profile.md) - File profile
|
||||
|
||||
### Search & Query
|
||||
|
||||
- [Search](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/06_search.md) - General search
|
||||
- [VLM Search](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/23_vlm_search_api.md) - Vision Language Model search
|
||||
- [TKG](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/15_tkg.md) - Temporal Knowledge Graph
|
||||
|
||||
### Identity & People
|
||||
|
||||
- [Identity](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/07_identity.md) - Identity management
|
||||
- [Identity Agent](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/08_identity_agent.md) - Agent operations
|
||||
- [Identity History](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/14_identity_history.md) - History tracking
|
||||
- [People API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/19_people_api.md) - People management
|
||||
- [Trace Agent](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/22_trace_agent_api.md) - Trace operations
|
||||
- [Pose & Appearance](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/24_pose_appearance_api.md) - Pose and appearance data
|
||||
|
||||
### System & Monitoring
|
||||
|
||||
- [Health](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/02_health.md) - Health checks
|
||||
- [Service Management](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/20_service_management_api.md) - Service control
|
||||
- [Monitor](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/21_monitor_api.md) - System monitoring
|
||||
- [Progress](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/17_progress.md) - Progress tracking
|
||||
- [Pipeline](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/10_pipeline.md) - Pipeline management
|
||||
|
||||
### Media & Content
|
||||
|
||||
- [Media](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/08_media.md) - Media access
|
||||
- [TMDb](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/09_tmdb.md) - TMDb integration
|
||||
|
||||
### Configuration & Management
|
||||
|
||||
- [Config](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/13_config.md) - Configuration
|
||||
- [Workspace](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/16_workspace.md) - Workspace management
|
||||
- [Agent](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/12_agent.md) - Agent API
|
||||
|
||||
---
|
||||
|
||||
## 📖 Usage Guidelines
|
||||
|
||||
### Authentication
|
||||
|
||||
Most API endpoints require authentication via API key:
|
||||
|
||||
```bash
|
||||
# 1. Edit a module
|
||||
vim modules/09_tmdb.md
|
||||
|
||||
# 2. Preview the generated output
|
||||
make _build/API_ENDPOINTS.md
|
||||
|
||||
# 3. Check diff against current GUIDES/ content
|
||||
make check
|
||||
|
||||
# 4. Deploy to GUIDES/
|
||||
make deploy
|
||||
|
||||
# 5. Regenerate all
|
||||
make all
|
||||
curl -H "X-API-Key: your-api-key" \
|
||||
http://localhost:3002/api/v1/...
|
||||
```
|
||||
|
||||
## Directory Structure
|
||||
See [Auth API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/01_auth.md) for details.
|
||||
|
||||
```
|
||||
API_WORKSPACE/
|
||||
├── modules/ ← 11 module files (01_auth ... 11_error_codes)
|
||||
├── configs/ ← 7 assembly recipies (.toml)
|
||||
├── narratives/ ← narrative intros for specific output files
|
||||
├── _build/ ← generated output (gitignored)
|
||||
├── Makefile ← build targets
|
||||
├── assemble_docs.sh ← assembly engine
|
||||
└── README.md
|
||||
```
|
||||
### Base URLs
|
||||
|
||||
## Available `make` Targets
|
||||
| Environment | Base URL |
|
||||
|------------|----------|
|
||||
| Production | `http://localhost:3002` |
|
||||
| External | `https://m5api.momentry.ddns.net` |
|
||||
| Development | `http://localhost:3003` |
|
||||
|
||||
| Target | Output |
|
||||
|--------|--------|
|
||||
| `make reference` | `_build/API_REFERENCE.md` |
|
||||
| `make endpoints` | `_build/API_ENDPOINTS.md` |
|
||||
| `make quickref` | `_build/API_QUICK_REFERENCE.md` |
|
||||
| `make errors` | `_build/API_ERROR_CODES.md` |
|
||||
| `make index` | `_build/API_INDEX.md` |
|
||||
| `make marcom` | `_build/API_TRAINING_MARCOM.md` |
|
||||
| `make tmdb` | `_build/TMDb_User_Guide.md` |
|
||||
| `make all` | All of the above |
|
||||
| `make deploy` | Copy `_build/*` → `../GUIDES/` |
|
||||
| `make check` | `diff` against existing `../GUIDES/` files |
|
||||
### Common Patterns
|
||||
|
||||
## Adding a New Endpoint
|
||||
#### File Processing
|
||||
|
||||
1. Add the endpoint to the appropriate module (e.g., `modules/XX_files.md`)
|
||||
2. Follow the template in `modules/_template.md`
|
||||
3. `make all && make check`
|
||||
4. `make deploy`
|
||||
1. Register file: `POST /api/v1/register`
|
||||
2. Process file: `POST /api/v1/process`
|
||||
3. Check progress: `GET /api/v1/progress/{file_uuid}`
|
||||
4. Search results: `GET /api/v1/search`
|
||||
|
||||
#### Identity Management
|
||||
|
||||
1. List identities: `GET /api/v1/identities`
|
||||
2. Bind faces: `POST /api/v1/identities/{identity_uuid}/bind`
|
||||
3. Search identities: `GET /api/v1/search/identities`
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Development
|
||||
|
||||
### Adding New Endpoints
|
||||
|
||||
1. Use [_template.md](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/_template.md)
|
||||
2. Follow naming convention: `NN_topic.md`
|
||||
3. Add YAML frontmatter
|
||||
4. Include complete examples
|
||||
5. Add to this index
|
||||
|
||||
### Documentation Standards
|
||||
|
||||
All modules must include:
|
||||
- ✅ YAML frontmatter
|
||||
- ✅ Module metadata (module, description, depends)
|
||||
- ✅ Endpoint documentation with examples
|
||||
- ✅ Error codes
|
||||
- ✅ Version history
|
||||
|
||||
---
|
||||
|
||||
## 📊 Statistics
|
||||
|
||||
| Metric | Count |
|
||||
|--------|-------|
|
||||
| **Total API Modules** | 31 |
|
||||
| **Core APIs** | 20 |
|
||||
| **New APIs** | 5 |
|
||||
| **Studio Guides** | 6 |
|
||||
| **Total Endpoints** | 100+ |
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial comprehensive API index |
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: 2026-10-24
|
||||
**Maintained By**: Core Team
|
||||
@@ -0,0 +1,428 @@
|
||||
---
|
||||
title: people api API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
# People API
|
||||
|
||||
**Version**: 2.1
|
||||
**Date**: 2026-08-12
|
||||
**Base URL**: `http://localhost:3002`
|
||||
**Auth**: Requires API key header (`Authorization: Bearer <api_key>`)
|
||||
**Doc Path**: `/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/19_people_api.md`
|
||||
|
||||
---
|
||||
|
||||
## 資料架構
|
||||
|
||||
### ⚠️ People Search 核心機制
|
||||
|
||||
**People Search 使用 TEXT 名稱匹配,不使用向量搜尋。**
|
||||
|
||||
- 資料來源: `face_cluster.json` 的 `group_name`
|
||||
- 儲存位置: SQLite `trace_profiles` 表
|
||||
- 匹配方式: PostgreSQL/SQLite `ILIKE` 模糊匹配
|
||||
- **Identity 欄位目前為佔位用途,暫無實際搜尋功能**
|
||||
- **Face 512D 向量僅供 `rust_face_cluster` 工具使用,不參與任何搜尋**
|
||||
|
||||
### trace_profiles(SQLite/PostgreSQL — People Search 專用)
|
||||
|
||||
每筆 `file_uuid + trace_id` 對應一個 face trace profile:
|
||||
|
||||
| 欄位 | 類型 | 說明 |
|
||||
|------|------|------|
|
||||
| `file_uuid` | string | 影片 UUID |
|
||||
| `trace_id` | integer | Face trace ID(8Hz 取樣追蹤) |
|
||||
| `name` | string | FS name(Face 頁面顯示 + People Search 搜尋) |
|
||||
| `start_frame` | integer | 起始 frame |
|
||||
| `end_frame` | integer | 結束 frame |
|
||||
| `frame_count` | integer | 追蹤 frame 數(8Hz 取樣,多數 > 1) |
|
||||
| `key_frame` | string | 關鍵幀圖片路徑 |
|
||||
| `key_face` | string | 關鍵人臉裁切路徑 |
|
||||
| `avg_confidence` | float | 平均偵測信心值 |
|
||||
| `status` | string | 狀態(pending/confirmed) |
|
||||
|
||||
### 可搜尋註記(metadata / VLM 欄位)
|
||||
|
||||
`trace_profiles` 包含 VLM 產生的註記,可用於進階搜尋和統計:
|
||||
|
||||
| 欄位 | 類型 | 說明 |
|
||||
|------|------|------|
|
||||
| `vlm_description` | text | VLM 人物外貌描述 |
|
||||
| `vlm_clothing` | text | VLM 衣著描述 |
|
||||
| `vlm_tags` | text[] | VLM 標籤陣列 |
|
||||
| `vlm_location` | string | VLM 地點 |
|
||||
| `vlm_setting` | string | VLM 場景設定 |
|
||||
| `vlm_lighting` | string | VLM 光線 |
|
||||
| `vlm_weather` | string | VLM 天氣 |
|
||||
| `vlm_background` | text | VLM 背景描述 |
|
||||
| `vlm_bg_tags` | text[] | VLM 背景標籤 |
|
||||
|
||||
### tkg_nodes(PostgreSQL — TKG 圖譜專用,與 profile 獨立)
|
||||
|
||||
| 欄位 | 說明 |
|
||||
|------|------|
|
||||
| `external_id` | 如 "trace_9",對應 `trace_profiles.trace_id` |
|
||||
| `label` | TKG 圖譜節點標籤(與 `trace_profiles.name` 獨立) |
|
||||
| `properties` | TKG 節點屬性 |
|
||||
|
||||
### _faces(Qdrant — Face 向量比對)
|
||||
|
||||
Face embedding 向量存在 Qdrant `_faces` collection,可用作 seed 比對:
|
||||
|
||||
| Payload 欄位 | 類型 | 說明 |
|
||||
|-------------|------|------|
|
||||
| `file_uuid` | string | 影片 UUID |
|
||||
| `trace_id` | integer | Face trace ID |
|
||||
| `identity_id` | integer \| null | 已綁定的 identity ID |
|
||||
| `frame` | integer | Frame 編號 |
|
||||
| `embedding` | vector[512] | FaceNet 512-d embedding |
|
||||
| `bbox` | object | 人臉 bbox(x, y, width, height) |
|
||||
| `confidence` | float | 偵測信心值 |
|
||||
|
||||
---
|
||||
|
||||
## 1. GET /api/v1/search/people
|
||||
|
||||
搜尋已命名的 face trace profiles。回傳符合 name 的卡片列表。
|
||||
|
||||
### Query Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|------|----------|-------------|
|
||||
| `query` | string | ✅ Yes | 搜尋關鍵字(ILIKE 模糊比對 `trace_profiles.name`) |
|
||||
| `file_uuid` | string | ❌ Optional | 限制搜尋範圍 |
|
||||
| `limit` | integer | ❌ Optional | 回傳筆數上限(預設 10) |
|
||||
|
||||
### Example Request
|
||||
|
||||
```bash
|
||||
# 搜尋名字
|
||||
curl -X GET "http://localhost:3002/api/v1/search/people?query=Susan"
|
||||
|
||||
# 搜尋 VLM 註記(衣著、地點、標籤)
|
||||
curl -X GET "http://localhost:3002/api/v1/search/people?query=blue+shirt"
|
||||
|
||||
# 限定影片
|
||||
curl -X GET "http://localhost:3002/api/v1/search/people?file_uuid=abc123&query=Tom"
|
||||
```
|
||||
|
||||
### 搜尋範圍
|
||||
|
||||
People Search 會搜尋以下欄位(ILIKE 模糊比對):
|
||||
|
||||
| 欄位 | 說明 |
|
||||
|------|------|
|
||||
| `name` | FS name |
|
||||
| `vlm_description` | VLM 人物外貌描述 |
|
||||
| `vlm_clothing` | VLM 衣著描述 |
|
||||
| `vlm_tags` | VLM 標籤陣列 |
|
||||
| `vlm_location` | VLM 地點 |
|
||||
| `vlm_setting` | VLM 場景設定 |
|
||||
|
||||
### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"people": [
|
||||
{
|
||||
"file_uuid": "4655a0ab3c077e30c12b2298c2750650",
|
||||
"file_name": "",
|
||||
"trace_id": 9,
|
||||
"external_id": "trace_9",
|
||||
"name": "Susan",
|
||||
"start_frame": 118,
|
||||
"end_frame": 384,
|
||||
"frame_count": 39,
|
||||
"start_time": null,
|
||||
"end_time": null,
|
||||
"key_frame": "key_frame.jpg",
|
||||
"key_face": null,
|
||||
"avg_confidence": 0.694,
|
||||
"avg_capture_quality": 0.512,
|
||||
"best_capture_quality": 0.733
|
||||
}
|
||||
],
|
||||
"total": 18
|
||||
}
|
||||
```
|
||||
|
||||
### Response Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | 影片 UUID |
|
||||
| `trace_id` | integer | Face trace ID |
|
||||
| `external_id` | string \| null | TKG node external_id(如 "trace_9") |
|
||||
| `name` | string \| null | 使用者命名的 FS name |
|
||||
| `start_frame` | integer \| null | 起始 frame |
|
||||
| `end_frame` | integer \| null | 結束 frame |
|
||||
| `frame_count` | integer \| null | 追蹤 frame 數(8Hz 取樣) |
|
||||
| `start_time` | float \| null | 起始時間(秒) |
|
||||
| `end_time` | float \| null | 結束時間(秒) |
|
||||
| `key_frame` | string \| null | 關鍵幀圖片路徑 |
|
||||
| `key_face` | string \| null | 關鍵人臉裁切路徑 |
|
||||
| `avg_confidence` | float \| null | 平均偵測信心值 |
|
||||
| `avg_capture_quality` | float \| null | 平均畫面品質分數(清晰度,0~1) |
|
||||
| `best_capture_quality` | float \| null | 該 trace 最佳畫面品質分數 |
|
||||
|
||||
---
|
||||
|
||||
## 2. POST /api/v1/search/universal
|
||||
|
||||
統一搜尋。設定 `types: ["people"]` 搜尋人物,或組合 `"chunk"`、`"frame"`。
|
||||
|
||||
People Search 會搜尋 `trace_profiles` 的 `name` + `vlm_*` 欄位:
|
||||
- `name` — FS name
|
||||
- `vlm_description` — VLM 人物外貌描述
|
||||
- `vlm_clothing` — VLM 衣著描述
|
||||
- `vlm_tags` — VLM 標籤陣列
|
||||
- `vlm_location` — VLM 地點
|
||||
- `vlm_setting` — VLM 場景設定
|
||||
|
||||
### Request Body
|
||||
|
||||
```json
|
||||
{
|
||||
"query": "Susan",
|
||||
"file_uuid": "abc123",
|
||||
"types": ["people"],
|
||||
"page": 1,
|
||||
"page_size": 20
|
||||
}
|
||||
```
|
||||
|
||||
### Request Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `query` | string | ✅ Yes | 搜尋關鍵字 |
|
||||
| `file_uuid` | string | ❌ Optional | 限制搜尋範圍 |
|
||||
| `types` | string[] | ❌ Optional | `["chunk", "frame", "people"]` — 預設全部 |
|
||||
| `page` | integer | ❌ Optional | 頁碼(預設 1) |
|
||||
| `page_size` | integer | ❌ Optional | 每頁筆數(預設 20,最大 200) |
|
||||
|
||||
### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"query": "Susan",
|
||||
"results": [
|
||||
{
|
||||
"type": "person",
|
||||
"file_uuid": "4655a0ab3c077e30c12b2298c2750650",
|
||||
"trace_id": 9,
|
||||
"external_id": "trace_9",
|
||||
"name": "Susan",
|
||||
"frame_count": 39,
|
||||
"score": 0.95,
|
||||
"start_time": null,
|
||||
"end_time": null,
|
||||
"key_frame": "key_frame.jpg",
|
||||
"key_face": null
|
||||
}
|
||||
],
|
||||
"total": 18,
|
||||
"page": 1,
|
||||
"page_size": 20,
|
||||
"has_more": false
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. PUT /api/v1/trace-profile(單筆改名)
|
||||
|
||||
更新單一 face trace profile 的 name 和 metadata。
|
||||
|
||||
### Request Body
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "4655a0ab3c077e30c12b2298c2750650",
|
||||
"trace_id": 9,
|
||||
"name": "Susan",
|
||||
"properties": { "custom_key": "custom_value" },
|
||||
"key_frame": "path/to/key_frame.jpg",
|
||||
"key_face": "path/to/key_face.jpg",
|
||||
"aliases": ["Susie", "Sue"]
|
||||
}
|
||||
```
|
||||
|
||||
### Request Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | ✅ Yes | 影片 UUID |
|
||||
| `trace_id` | integer | ✅ Yes | Face trace ID |
|
||||
| `name` | string | ❌ Optional | 新的 FS name |
|
||||
| `properties` | object | ❌ Optional | 自訂屬性(合併更新) |
|
||||
| `key_frame` | string | ❌ Optional | 關鍵幀路徑 |
|
||||
| `key_face` | string | ❌ Optional | 關鍵人臉路徑 |
|
||||
| `aliases` | string[] | ❌ Optional | 別名列表 |
|
||||
|
||||
---
|
||||
|
||||
## 4. PUT /api/v1/trace-profile/group(批次改名)
|
||||
|
||||
批次更新多個 face trace profiles 的 name。
|
||||
|
||||
### Request Body
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "4655a0ab3c077e30c12b2298c2750650",
|
||||
"trace_ids": [9, 22, 5],
|
||||
"name": "Susan"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. POST /api/v1/groups/merge(合併群組)
|
||||
|
||||
將多個 group 的 traces 合併為一個 group name。
|
||||
|
||||
### Request Body
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "4655a0ab3c077e30c12b2298c2750650",
|
||||
"source_groups": ["Person_0", "Person_1"],
|
||||
"target_group_name": "Susan"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Error Responses
|
||||
|
||||
### 400 Bad Request
|
||||
```json
|
||||
{ "error": "name is required" }
|
||||
```
|
||||
|
||||
### 401 Unauthorized
|
||||
```
|
||||
HTTP 401 (no body) — Missing or invalid API key
|
||||
```
|
||||
|
||||
### 404 Not Found
|
||||
```json
|
||||
{ "error": "Profile not found" }
|
||||
```
|
||||
|
||||
### 500 Internal Server Error
|
||||
```json
|
||||
{ "error": "DB error: connection refused" }
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 如何命名 Face Trace
|
||||
|
||||
使用 profile API 為 face trace 命名:
|
||||
|
||||
```bash
|
||||
curl -X PUT "http://localhost:3002/api/v1/trace-profile" \
|
||||
-H "Authorization: Bearer <api_key>" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"file_uuid": "4655a0ab3c077e30c12b2298c2750650",
|
||||
"trace_id": 9,
|
||||
"name": "Susan"
|
||||
}'
|
||||
```
|
||||
|
||||
命名後即可透過 People Search API 搜尋:
|
||||
|
||||
```bash
|
||||
curl "http://localhost:3002/api/v1/search/people?query=Susan" \
|
||||
-H "Authorization: Bearer <api_key>"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pipeline 狀態定義
|
||||
|
||||
所有檔案的 status 由 `/api/v1/file/{file_uuid}/sync-status` 自動更新,依據 processor outputs 和功能就緒狀態判定。
|
||||
|
||||
| Status | 前端顯示 | 條件 | 啟用功能 |
|
||||
|--------|---------|------|---------|
|
||||
| `registered` | 📋 已註冊 | 0 processor outputs | 檔案註冊 |
|
||||
| `scanning` | 🔍 掃描中 | 1-4/5 processor outputs | — |
|
||||
| `keyword_ready` | 🔎 關鍵字可用 | sentence chunks > 0 | Smart Search |
|
||||
| `semantic_ready` | 🧠 語意可用 | embedded chunks > 0 | Semantic Search |
|
||||
| `face_mgmt_ready` | 🎭 臉部管理可用 | face_trace + trace_profiles + tkg_nodes(face_track) | People Search, Face Profile 讀寫, Face Group |
|
||||
| `agent_ready` | 🤖 Agent 可用 | face_mgmt_ready + tkg_edges | Agent TKG Tools |
|
||||
| `completed` | ✅ 完成 | 5/5 processors + 全部功能就緒 | — |
|
||||
|
||||
### Face Management Ready 明確定義
|
||||
|
||||
`face_mgmt_ready` 表示檔案已具備完整臉部管理功能,需同時滿足以下四個條件:
|
||||
|
||||
| 依賴項 | 檢查條件 | 說明 | 提供功能 |
|
||||
|--------|---------|------|---------|
|
||||
| **Face Qdrant Ready** | `_faces` collection 有 face points | Face embeddings 已存入 Qdrant | 臉部比對、相似度搜尋 |
|
||||
| **Face Trace Ready** | `face_traced.json` 存在且有 traces | Face tracking 已完成 | 人臉軌跡資料 |
|
||||
| **Face Profile Ready** | `trace_profiles` 有紀錄 | Profile 資料已建立 | 名字、VLM 註記、key_frame/key_face |
|
||||
| **Face TKG Node Ready** | `tkg_nodes` 有 `face_track` nodes | TKG 圖譜節點已建立 | 臉部群組合併、關係查詢 |
|
||||
|
||||
#### 檢查 SQL
|
||||
|
||||
```sql
|
||||
-- Face Qdrant Ready
|
||||
SELECT COUNT(*) FROM _faces WHERE file_uuid = $1; -- > 0
|
||||
|
||||
-- Face Trace Ready
|
||||
-- 檢查 face_traced.json 檔案存在且有 traces
|
||||
|
||||
-- Face Profile Ready
|
||||
SELECT COUNT(*) FROM trace_profiles WHERE file_uuid = $1; -- > 0
|
||||
|
||||
-- Face TKG Node Ready
|
||||
SELECT COUNT(*) FROM tkg_nodes WHERE file_uuid = $1 AND node_type = 'face_track'; -- > 0
|
||||
```
|
||||
|
||||
#### 啟用功能清單
|
||||
|
||||
| 功能 | API Endpoint | 說明 |
|
||||
|------|-------------|------|
|
||||
| People Search | `GET /api/v1/search/people` | 搜尋已命名人臉 |
|
||||
| Face Profile 讀寫 | `PUT /api/v1/trace-profile` | 更新名字、VLM 註記 |
|
||||
| Face Group 合併 | `POST /api/v1/groups/merge` | 合併多個群組 |
|
||||
| Face Trace 改名 | `PUT /api/v1/trace-profile` | 為單個 trace 命名 |
|
||||
| Agent Face Search | Agent Tool: `face_profile_search` | Agent 搜尋人臉 |
|
||||
|
||||
---
|
||||
|
||||
### 狀態依賴關係
|
||||
|
||||
```
|
||||
registered → scanning → keyword_ready → semantic_ready
|
||||
↓
|
||||
face_mgmt_ready → agent_ready → completed
|
||||
```
|
||||
|
||||
### 每個階段對應的 Processor
|
||||
|
||||
| 階段 | 必要 Processor | 產出 |
|
||||
|------|---------------|------|
|
||||
| `keyword_ready` | ASR, ASRX | sentence chunks |
|
||||
| `semantic_ready` | keyword_ready + Vectorize | embedded chunks |
|
||||
| `face_mgmt_ready` | Face, FaceCluster | trace_profiles (People Search + Face Management) |
|
||||
| `agent_ready` | face_mgmt_ready + TKG Edges | tkg_edges |
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,301 @@
|
||||
---
|
||||
title: Auth API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: auth -->
|
||||
<!-- description: Authentication — login, logout, JWT, session cookie, API key -->
|
||||
<!-- depends: -->
|
||||
|
||||
## Base URL
|
||||
|
||||
| Environment | URL | Purpose |
|
||||
|-------------|-----|---------|
|
||||
| Production | `http://localhost:3002` | Production deployment |
|
||||
| External (M5) | `https://m5api.momentry.ddns.net` | Remote access |
|
||||
|
||||
## Variables
|
||||
|
||||
All examples in this documentation use these environment variables:
|
||||
|
||||
```bash
|
||||
API="http://localhost:3002"
|
||||
KEY="your-api-key-here"
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
All endpoints under `/api/v1/*` require authentication.
|
||||
The following endpoints are public (no auth needed):
|
||||
|
||||
- `GET /health`
|
||||
- `POST /api/v1/auth/login`
|
||||
- `POST /api/v1/auth/logout`
|
||||
|
||||
### Three Authentication Modes
|
||||
|
||||
The system supports three authentication methods, checked in **priority order** by the middleware:
|
||||
|
||||
```
|
||||
Middleware priority:
|
||||
1. Session Cookie (Portal/browser)
|
||||
2. JWT Bearer (API clients, CLI)
|
||||
3. API Key Header (legacy compatibility)
|
||||
4. API Key Query Param (?api_key=)
|
||||
```
|
||||
|
||||
| Mode | Transport | Expiry | Scope | Best for |
|
||||
|------|-----------|--------|-------|----------|
|
||||
| **Session Cookie** | `Cookie: session_id=<session_id>` | 24h | per-browser session | Portal (browser) |
|
||||
| **JWT** | `Authorization: Bearer <token>` | 1h | per-login token | API clients, CLI, scripts |
|
||||
| **API Key** | `X-API-Key: <key>` | 90d | fixed key for automation | Legacy scripts, WordPress |
|
||||
|
||||
---
|
||||
|
||||
### Login
|
||||
|
||||
**Default accounts & API keys:**
|
||||
|
||||
| Username | Password | API Key | Role |
|
||||
|----------|----------|---------|------|
|
||||
| `admin` | `admin` | — | admin |
|
||||
| `demo` | `demo` | `muser_demo_key_32chars_abcdef1234567890` | user |
|
||||
|
||||
The demo API key is set via `MOMENTRY_DEMO_API_KEY` env var and can be used in place of JWT for marcom integrations:
|
||||
|
||||
```bash
|
||||
# Using API key instead of JWT
|
||||
curl -s "$API/api/v1/files/scan" -H "X-API-Key: muser_demo_key_32chars_abcdef1234567890"
|
||||
```
|
||||
|
||||
```bash
|
||||
# Login as admin
|
||||
curl -s -X POST "$API/api/v1/auth/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username": "admin", "password": "admin"}'
|
||||
|
||||
# Login as demo user
|
||||
curl -s -X POST "$API/api/v1/auth/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username": "demo", "password": "demo"}'
|
||||
```
|
||||
|
||||
#### Success Response
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"jwt": "eyJhbGciOiJIUzI1NiIs...",
|
||||
"api_key": "muser_...",
|
||||
"user": {
|
||||
"username": "admin",
|
||||
"role": "admin"
|
||||
},
|
||||
"expires_at": "2026-05-18T13:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `jwt` | string | JWT access token. Use as `Authorization: Bearer <jwt>`. Expires in 1 hour. |
|
||||
| `api_key` | string | Legacy API key. Use as `X-API-Key: <key>`. Good for 90 days. |
|
||||
| `user.username` | string | Username |
|
||||
| `user.role` | string | Role: `admin`, `user`, or `readonly` |
|
||||
| `expires_at` | string | ISO8601 timestamp of JWT expiration |
|
||||
|
||||
The login endpoint also sets a `Set-Cookie` header for browser-based clients:
|
||||
|
||||
```
|
||||
Set-Cookie: session_id=<session_id>; Path=/; HttpOnly; SameSite=Strict; Max-Age=86400
|
||||
```
|
||||
|
||||
#### Error Response (401)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"message": "Invalid username or password"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Using JWT
|
||||
|
||||
JWT is preferred for API clients (CLI scripts, WordPress). It is validated by the middleware without a database lookup (stateless).
|
||||
|
||||
```bash
|
||||
# Login and capture JWT
|
||||
JWT=$(curl -s -X POST "$API/api/v1/auth/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username":"admin","password":"admin"}' | python3 -c "import json,sys;print(json.load(sys.stdin)['jwt'])")
|
||||
|
||||
# Use JWT for all subsequent requests
|
||||
curl -H "Authorization: Bearer $JWT" "$API/api/v1/files/scan"
|
||||
curl -H "Authorization: Bearer $JWT" "$API/api/v1/resource/tmdb"
|
||||
```
|
||||
|
||||
JWT is short-lived (1 hour). When it expires, request a new one via login.
|
||||
|
||||
---
|
||||
|
||||
### Using Session Cookie (Browser)
|
||||
|
||||
Browser-based clients (Portal) get a session cookie automatically after login. The browser sends the cookie with every request—no manual header needed.
|
||||
|
||||
```bash
|
||||
# Login captures the session cookie from Set-Cookie header
|
||||
curl -v -X POST "$API/api/v1/auth/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username":"admin","password":"admin"}' 2>&1 | grep "Set-Cookie"
|
||||
|
||||
# Browser automatically sends: Cookie: session_id=<session_id>
|
||||
# No manual header needed for subsequent requests
|
||||
```
|
||||
|
||||
The session cookie is HttpOnly (not accessible from JavaScript) and SameSite=Strict (protected against CSRF).
|
||||
|
||||
---
|
||||
|
||||
### Using Legacy API Key
|
||||
|
||||
```bash
|
||||
curl -H "X-API-Key: $KEY" "$API/api/v1/files/scan"
|
||||
|
||||
# Also accepted via Bearer header (non-JWT format) or query parameter:
|
||||
curl -H "Authorization: Bearer $KEY" "$API/api/v1/files/scan"
|
||||
curl "$API/api/v1/files/scan?api_key=$KEY"
|
||||
```
|
||||
|
||||
API keys are validated via SHA256 hash lookup in the database. They are long-lived (90 days) and intended for automation.
|
||||
|
||||
### Obtaining an API Key (CLI)
|
||||
|
||||
```bash
|
||||
momentry api-key create "My API Key" --key-type user
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Logout
|
||||
|
||||
```bash
|
||||
# Logout using the session cookie (browser)
|
||||
curl -X POST "$API/api/v1/auth/logout" \
|
||||
-H "Cookie: session_id=<uuid>"
|
||||
```
|
||||
|
||||
#### What logout does
|
||||
|
||||
| Auth mode | Effect |
|
||||
|-----------|--------|
|
||||
| **Session Cookie** | Session deleted from database. Same cookie returns 401 on subsequent requests. |
|
||||
| **JWT** | JWT remains valid until expiry. (JWT is stateless — logout adds JWT to a blacklist only if API key mode is used.) |
|
||||
| **API Key** | API key remains valid. (Legacy keys are shared across sessions — revoking would break other clients.) |
|
||||
|
||||
#### Example: full session lifecycle
|
||||
|
||||
```bash
|
||||
# 1. Login
|
||||
SESSION_ID=$(curl -s -D - -X POST "$API/api/v1/auth/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username":"admin","password":"admin"}' | grep "Set-Cookie" | sed 's/.*session_id=\([^;]*\).*/\1/')
|
||||
|
||||
# 2. Use session (works)
|
||||
curl -s -o /dev/null -w "HTTP %{http_code}\n" "$API/api/v1/resource/tmdb" \
|
||||
-H "Cookie: session_id=$SESSION_ID"
|
||||
# → HTTP 200
|
||||
|
||||
# 3. Logout
|
||||
curl -s -X POST "$API/api/v1/auth/logout" \
|
||||
-H "Cookie: session_id=$SESSION_ID"
|
||||
# → {"success": true}
|
||||
|
||||
# 4. Use session again (rejected)
|
||||
curl -s -o /dev/null -w "HTTP %{http_code}\n" "$API/api/v1/resource/tmdb" \
|
||||
-H "Cookie: session_id=$SESSION_ID"
|
||||
# → HTTP 401
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Authentication Flow Summary
|
||||
|
||||
```
|
||||
Login Request
|
||||
│
|
||||
▼
|
||||
┌──────────────────┐
|
||||
│ 1. Check users │ ← users table (argon2 password verify)
|
||||
│ table │
|
||||
└──────┬───────────┘
|
||||
│
|
||||
┌───┴───┐
|
||||
│ match │
|
||||
└───┬───┘
|
||||
│
|
||||
▼
|
||||
┌──────────────────┐
|
||||
│ 2. Create JWT │ ← 1h expiry, signed with JWT_SECRET
|
||||
├──────────────────┤
|
||||
│ 3. Create │ ← 24h expiry, stored in sessions table
|
||||
│ session │
|
||||
├──────────────────┤
|
||||
│ 4. Set-Cookie │ ← HttpOnly, SameSite=Strict, Path=/
|
||||
├──────────────────┤
|
||||
│ 5. Return │ ← JWT + api_key + user info to client
|
||||
└──────────────────┘
|
||||
```
|
||||
|
||||
```
|
||||
Protected Request
|
||||
│
|
||||
▼
|
||||
┌──────────────────────┐
|
||||
│ Middleware checks: │
|
||||
│ │
|
||||
│ 1. Cookie session? │ → DB lookup session → get api_key → verify
|
||||
│ │
|
||||
│ 2. JWT Bearer? │ → verify JWT signature → decode claims
|
||||
│ │
|
||||
│ 3. X-API-Key? │ → SHA256 hash → DB lookup → verify
|
||||
│ │
|
||||
│ 4. ?api_key=? │ → same as #3
|
||||
│ │
|
||||
│ 5. None → 401 │
|
||||
└──────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `401` | Missing or invalid authentication |
|
||||
| `401` | Session expired or logged out |
|
||||
| `401` | JWT expired |
|
||||
| `401` | API key revoked or inactive |
|
||||
|
||||
---
|
||||
|
||||
### Related
|
||||
|
||||
- `POST /api/v1/resource/tmdb/check` — test authentication + TMDb API connectivity
|
||||
- `GET /health/detailed` — view auth status (integrations section)
|
||||
|
||||
---
|
||||
*Updated: 2026-05-19 12:49:24*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,208 @@
|
||||
---
|
||||
title: health API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: health -->
|
||||
<!-- description: Health check endpoints -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## Health Check
|
||||
|
||||
### `GET /health`
|
||||
|
||||
**Auth**: Public
|
||||
**Scope**: system-level
|
||||
|
||||
Returns basic server health status — used by load balancers and monitoring.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl "$API/health" | jq '{status, version}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"version": "1.0.0",
|
||||
"build_git_hash": "3a6c1865",
|
||||
"build_timestamp": "2026-05-16T13:38:15Z",
|
||||
"uptime_ms": 3015
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `status` | string | `ok` or `degraded` |
|
||||
| `version` | string | Semver version |
|
||||
| `build_git_hash` | string | Git commit hash |
|
||||
| `build_timestamp` | string | Binary build time |
|
||||
| `uptime_ms` | integer | Milliseconds since server start |
|
||||
|
||||
---
|
||||
|
||||
### `GET /health/detailed`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Returns full system health including each service status, resource utilization, pipeline readiness, schema migration status, identity file sync status, and external integrations.
|
||||
|
||||
> Requires authentication (JWT, session cookie, or API key). The basic `/health` endpoint remains public for load balancer checks.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl "$API/health/detailed" | jq '{status, services, resources: {cpu: .resources.cpu_used_percent, memory: .resources.memory_used_percent}}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"version": "1.0.0",
|
||||
"services": {
|
||||
"postgres": {"status": "ok", "latency_ms": 3},
|
||||
"redis": {"status": "ok", "latency_ms": 1},
|
||||
"qdrant": {"status": "ok", "latency_ms": 5}
|
||||
},
|
||||
"resources": {
|
||||
"cpu_used_percent": 12.5,
|
||||
"memory_available_mb": 32768,
|
||||
"memory_used_percent": 31.7
|
||||
},
|
||||
"pipeline": {
|
||||
"scripts_ready": true,
|
||||
"scripts_count": 345,
|
||||
"processors": {
|
||||
"asr": true,
|
||||
"yolo": true,
|
||||
"face": true,
|
||||
"pose": true,
|
||||
"ocr": true,
|
||||
"cut": true,
|
||||
"scene": true,
|
||||
"asrx": true,
|
||||
"visual_chunk": true
|
||||
},
|
||||
"models_ready": true,
|
||||
"models_count": 42,
|
||||
"scripts_integrity": {"matched": 332, "total": 345, "ok": false},
|
||||
"ffmpeg": true
|
||||
},
|
||||
"schema": {
|
||||
"table_exists": true,
|
||||
"applied": [{"filename": "migrate_add_users_table.sql"}],
|
||||
"required": [],
|
||||
"ok": true
|
||||
},
|
||||
"identities": {
|
||||
"directory_exists": true,
|
||||
"files_count": 3481,
|
||||
"index_ok": true,
|
||||
"db_count": 3481,
|
||||
"synced": true
|
||||
},
|
||||
"integrations": {
|
||||
"tmdb": {
|
||||
"api_key_configured": false,
|
||||
"enabled": false,
|
||||
"api_reachable": null
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Response Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `status` | string | `ok` if all essential services healthy |
|
||||
| `services` | object | Per-service status (postgres, redis, qdrant) |
|
||||
| `services.*.status` | string | `ok`, `error`, or `degraded` |
|
||||
| `services.*.latency_ms` | int | Response time in milliseconds |
|
||||
| `resources` | object | CPU, memory usage |
|
||||
| `pipeline.scripts_ready` | boolean | Scripts directory accessible |
|
||||
| `pipeline.scripts_count` | int | Number of Python processor scripts |
|
||||
| `pipeline.processors` | object | Per-processor availability |
|
||||
| `pipeline.models_ready` | boolean | Models directory accessible |
|
||||
| `pipeline.scripts_integrity` | object | SHA256 checksum verification results |
|
||||
| `schema.ok` | boolean | All required migrations applied |
|
||||
| `identities.synced` | boolean | Identity file count matches DB count |
|
||||
| `config` | object | Runtime toggle states (cache, auto-pipeline, watcher) |
|
||||
| `integrations.tmdb` | object | TMDB API key config and reachability |
|
||||
|
||||
### `GET /health/consistency`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Scans the database for data consistency issues. Reports anomalies without modifying any data.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/health/consistency" -H "X-API-Key: $KEY" | jq '.checks[] | {check, severity, count}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "degraded",
|
||||
"checked_at": "2026-05-18T17:30:00Z",
|
||||
"checks": [
|
||||
{
|
||||
"check": "stale_processing",
|
||||
"severity": "warn",
|
||||
"count": 3,
|
||||
"files": [
|
||||
{"file_name": "video.mp4", "file_uuid": "abc123...", "status": "processing", "detail": "job_id is null"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Check | Description | Severity |
|
||||
|-------|-------------|---------|
|
||||
| `stale_processing` | Status=processing but job_id is null | `warn` |
|
||||
| `orphaned_processing` | Status=processing but no active monitor_job | `warn` |
|
||||
| `processing_job_done` | Status=processing but job already completed | `warn` |
|
||||
| `unregistered_with_uuid` | Status=unregistered but row still in DB (migration residue) | `info` |
|
||||
|
||||
#### Health status rules
|
||||
|
||||
| Condition | status |
|
||||
|-----------|--------|
|
||||
| All services ok | `ok` |
|
||||
| Any service error | `degraded` |
|
||||
| Postgres or Redis error | `degraded` (server still responds) |
|
||||
|
||||
---
|
||||
|
||||
### Stats Endpoints
|
||||
|
||||
| Method | Endpoint | Auth | Description |
|
||||
|--------|----------|------|-------------|
|
||||
| GET | `/api/v1/stats/sftpgo` | No | SFTPGo service status |
|
||||
|
||||
---
|
||||
*Updated: 2026-05-19 12:49:24*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,206 @@
|
||||
---
|
||||
title: register API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: register -->
|
||||
<!-- description: File registration — register, scan -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## File Registration
|
||||
|
||||
### `POST /api/v1/files/register`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Register a video file for processing. Returns the file's metadata and UUID.
|
||||
|
||||
Registration can **automatically trigger the processing pipeline** if the
|
||||
[auto-pipeline toggle](/api/v1/config/auto-pipeline) is enabled (disabled by default). The system will:
|
||||
1. Register the file and run ffprobe
|
||||
2. Auto-run offline TMDb probe (reads local identity files, no API calls)
|
||||
3. Create a monitor job for the worker
|
||||
4. Worker starts all 10 processors (Cut → ASR → ASRX → YOLO → OCR → Face → Pose → VisualChunk → Story → 5W1H)
|
||||
|
||||
If the file already exists (same content hash), returns the existing record with `already_exists: true`.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `file_path` | string | Yes | — | Path to video file on disk |
|
||||
| `pattern` | string | No | — | Regex pattern for batch register (requires `file_path` to be a directory) |
|
||||
| `user_id` | integer | No | — | User ID to associate with registration |
|
||||
| `content_hash` | string | No | — | Pre-computed SHA-256 hash (skips computation) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Register a single file
|
||||
curl -s -X POST "$API/api/v1/files/register" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"file_path": "/path/to/video.mp4"}'
|
||||
|
||||
# Batch register files matching a pattern in a directory
|
||||
curl -s -X POST "$API/api/v1/files/register" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"file_path": "/path/to/dir", "pattern": ".*\\.mp4$"}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "3a6c1865...",
|
||||
"file_name": "video.mp4",
|
||||
"file_path": "/path/to/video.mp4",
|
||||
"file_type": "video",
|
||||
"duration": 120.5,
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"fps": 24.0,
|
||||
"total_frames": 2892,
|
||||
"already_exists": false,
|
||||
"message": "File registered successfully"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Always true on 200 |
|
||||
| `file_uuid` | string | 32-char hex UUID of the registered file |
|
||||
| `file_name` | string | File name (auto-renamed if name conflict) |
|
||||
| `file_path` | string | Canonical path on disk |
|
||||
| `file_type` | string | `"video"`, `"audio"`, or `"unknown"` |
|
||||
| `duration` | float | Duration in seconds |
|
||||
| `width` | integer | Video width in pixels |
|
||||
| `height` | integer | Video height in pixels |
|
||||
| `fps` | float | Frames per second |
|
||||
| `total_frames` | integer | Total frame count |
|
||||
| `already_exists` | boolean | True if same content was already registered |
|
||||
| `message` | string | Human-readable status |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `401` | Missing or invalid API key |
|
||||
| `400` | Invalid request body |
|
||||
| `404` | File path does not exist |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/files/scan`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Scan the filesystem directory and list all media files, showing which are registered, processing, or unregistered.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `page` | integer | No | 1 | Page number (1-based) |
|
||||
| `page_size` | integer | No | all | Items per page (alias: `limit`) |
|
||||
| `limit` | integer | No | all | Max items (alias for `page_size`) |
|
||||
| `pattern` | string | No | — | Regex filter on file name (e.g., `.*\\.mp4$`) |
|
||||
| `sort_by` | string | No | `name` | Sort field: `name`, `size`, `modified`, `status` |
|
||||
| `sort_order` | string | No | `asc` | Sort direction: `asc` or `desc` |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Full scan
|
||||
curl -s "$API/api/v1/files/scan" -H "X-API-Key: $KEY" | jq '{total, registered_count, unregistered_count}'
|
||||
|
||||
# Paginated (page 1, 5 per page)
|
||||
curl -s "$API/api/v1/files/scan?page=1&page_size=5" -H "X-API-Key: $KEY" | jq '{page, total_pages, files: [.files[].file_name]}'
|
||||
|
||||
# Regex filter: only mp4 files
|
||||
curl -s "$API/api/v1/files/scan?pattern=.*\\.mp4$" -H "X-API-Key: $KEY" | jq '{filtered_total, files: [.files[].file_name]}'
|
||||
|
||||
# Sort by file size (largest first)
|
||||
curl -s "$API/api/v1/files/scan?sort_by=size&sort_order=desc&page_size=5" -H "X-API-Key: $KEY" | jq '[.files[] | {file_name, file_size}]'
|
||||
|
||||
# Sort by modified time (most recent first)
|
||||
curl -s "$API/api/v1/files/scan?sort_by=modified&sort_order=desc&page_size=5" -H "X-API-Key: $KEY" | jq '[.files[] | {file_name, modified_time}]'
|
||||
|
||||
# Sort by status
|
||||
curl -s "$API/api/v1/files/scan?sort_by=status&page_size=5" -H "X-API-Key: $KEY" | jq '[.files[] | {file_name, status}]'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"files": [
|
||||
{
|
||||
"file_name": "video.mp4",
|
||||
"file_size": 12345678,
|
||||
"is_registered": true,
|
||||
"file_uuid": "3a6c1865...",
|
||||
"status": "completed",
|
||||
"registration_time": "2026-05-16T12:00:00Z",
|
||||
"job_id": 42
|
||||
}
|
||||
],
|
||||
"total": 107,
|
||||
"filtered_total": 80,
|
||||
"page": 1,
|
||||
"page_size": 20,
|
||||
"total_pages": 4,
|
||||
"registered_count": 26,
|
||||
"unregistered_count": 81
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `files` | array | Array of file info objects (paginated) |
|
||||
| `files[].file_name` | string | File name |
|
||||
| `files[].relative_path` | string | Path relative to scan root |
|
||||
| `files[].file_path` | string | Absolute path on disk |
|
||||
| `files[].file_size` | integer | File size in bytes |
|
||||
| `files[].modified_time` | string | Last modified timestamp (ISO8601) |
|
||||
| `files[].is_registered` | boolean | Whether file is registered in DB |
|
||||
| `files[].file_uuid` | string | 32-char hex UUID (only if registered) |
|
||||
| `files[].status` | string | `"completed"`, `"processing"`, `"registered"`, `"unregistered"`, or `null` |
|
||||
| `files[].registration_time` | string | DB registration timestamp (only if registered) |
|
||||
| `files[].job_id` | integer | Processing job ID (only if a job exists) |
|
||||
| `total` | integer | Total files found on disk (unfiltered) |
|
||||
| `filtered_total` | integer | Files matching regex filter |
|
||||
| `page` | integer | Current page number |
|
||||
| `page_size` | integer | Items per page |
|
||||
| `total_pages` | integer | Total pages |
|
||||
| `registered_count` | integer | Files registered in DB |
|
||||
| `unregistered_count` | integer | Files not yet registered |
|
||||
|
||||
#### Notes
|
||||
|
||||
| Feature | Behavior |
|
||||
|---------|----------|
|
||||
| **Regex** | Case-insensitive (`(?i)` prefix auto-applied). Applied to `file_name`. |
|
||||
| **Sort order** | Default (`sort_by=name`): registered files first, then alphabetically. `sort_by=status`: alphabetical by status string. |
|
||||
| **Pagination** | `page_size` and `limit` are aliases. Default: show all results. |
|
||||
| **Processing order** | `pattern` regex filter → `sort_by`/`sort_order` → `page`/`page_size` slice. |
|
||||
|
||||
---
|
||||
*Updated: 2026-05-19 12:49:24*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,438 @@
|
||||
---
|
||||
title: lookup API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: lookup -->
|
||||
<!-- description: File listing, lookup by name, file detail, faces, identities, JSON download, unregistration -->
|
||||
<!-- depends: 01_auth, 03_register -->
|
||||
|
||||
## File Lookup
|
||||
|
||||
### `GET /api/v1/files/lookup`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Search registered files by file name. Performs a case-insensitive LIKE search on the file name column. Returns basic info about matching files.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_name` | string | Yes | File name to search for (partial matches supported) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Look up a specific file
|
||||
curl -s "$API/api/v1/files/lookup?file_name=video.mp4" \
|
||||
-H "X-API-Key: $KEY"
|
||||
|
||||
# Partial name search
|
||||
curl -s "$API/api/v1/files/lookup?file_name=charade" \
|
||||
-H "X-API-Key: $KEY" | jq '.matches[].file_name'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_name": "video.mp4",
|
||||
"exists": true,
|
||||
"matches": [
|
||||
{
|
||||
"file_uuid": "a03485a40b2df2d3",
|
||||
"file_name": "video.mp4",
|
||||
"file_type": "video",
|
||||
"status": "completed"
|
||||
}
|
||||
],
|
||||
"next_name": "video (2).mp4"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_name` | string | Searched name |
|
||||
| `exists` | boolean | Exact name match exists |
|
||||
| `matches` | array | Array of matching registered files |
|
||||
| `matches[].file_uuid` | string | 32-char hex UUID |
|
||||
| `matches[].file_name` | string | Registered file name |
|
||||
| `matches[].file_type` | string | `"video"`, `"audio"`, or `null` |
|
||||
| `matches[].status` | string | Registration/processing status |
|
||||
| `next_name` | string | Suggested name for avoiding conflicts |
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
## File Listing
|
||||
|
||||
### `GET /api/v1/files`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
List all registered files with pagination. Optionally filter by status or fetch a specific file by UUID.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `page` | integer | No | 1 | Page number |
|
||||
| `page_size` | integer | No | 20 | Items per page |
|
||||
| `status` | string | No | — | Filter by status: `registered`, `processing`, `completed`, `failed`, `indexed`, `checked_out` |
|
||||
| `file_uuid` | string | No | — | Fetch a specific file (returns as single-item list) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# List all files (paginated)
|
||||
curl -s "$API/api/v1/files?page=1&page_size=10" \
|
||||
-H "X-API-Key: $KEY"
|
||||
|
||||
# Filter by status
|
||||
curl -s "$API/api/v1/files?status=completed" \
|
||||
-H "X-API-Key: $KEY"
|
||||
|
||||
# Fetch specific file
|
||||
curl -s "$API/api/v1/files?file_uuid=$FILE_UUID" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"total": 42,
|
||||
"page": 1,
|
||||
"page_size": 10,
|
||||
"data": [
|
||||
{
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"file_name": "video.mp4",
|
||||
"file_path": "/path/to/video.mp4",
|
||||
"status": "completed"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Always true on 200 |
|
||||
| `total` | integer | Total file count |
|
||||
| `page` | integer | Current page |
|
||||
| `page_size` | integer | Items per page |
|
||||
| `data` | array | Array of file items |
|
||||
| `data[].file_uuid` | string | 32-char hex UUID |
|
||||
| `data[].file_name` | string | Registered file name |
|
||||
| `data[].file_path` | string | Full filesystem path |
|
||||
| `data[].status` | string | Processing status |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get detailed info for a specific registered file including metadata, duration, FPS, and probe data.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"file_name": "video.mp4",
|
||||
"file_path": "/path/to/video.mp4",
|
||||
"status": "completed",
|
||||
"duration": 120.5,
|
||||
"fps": 24.0,
|
||||
"metadata": {
|
||||
"format": {"duration": "120.5", "size": "794863677"},
|
||||
"streams": [{"codec_name": "h264", "width": 1920, "height": 1080}]
|
||||
},
|
||||
"created_at": "2026-05-16T12:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Always true on 200 |
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `file_name` | string | Registered file name |
|
||||
| `file_path` | string | Full filesystem path |
|
||||
| `status` | string | Processing status |
|
||||
| `duration` | float | Duration in seconds |
|
||||
| `fps` | float | Frames per second |
|
||||
| `metadata` | object | Full ffprobe metadata (probe.json) |
|
||||
| `created_at` | string | Registration timestamp (ISO 8601) |
|
||||
|
||||
#### Error Codes
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | File UUID not found |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/identities`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get all identities present in a specific file with pagination.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `page` | integer | No | 1 | Page number |
|
||||
| `page_size` | integer | No | 20 | Items per page |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/identities?page=1&page_size=50" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"fps": 24.0,
|
||||
"total": 5,
|
||||
"page": 1,
|
||||
"page_size": 20,
|
||||
"data": [
|
||||
{
|
||||
"identity_id": 1,
|
||||
"identity_uuid": "a9a90105-6d6b-46ff-92da-0c3c1a57dff4",
|
||||
"name": "Audrey Hepburn",
|
||||
"metadata": {"source": "tmdb", "tmdb_id": 1234},
|
||||
"face_count": 142,
|
||||
"speaker_count": 8,
|
||||
"start_frame": 100,
|
||||
"end_frame": 5000,
|
||||
"start_time": 4.17,
|
||||
"end_time": 208.33,
|
||||
"confidence": 0.87
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `data[].identity_id` | integer | Database identity ID |
|
||||
| `data[].identity_uuid` | string/null | Global identity UUID (null if unbound) |
|
||||
| `data[].name` | string | Identity name |
|
||||
| `data[].metadata` | object | Source metadata (TMDb, etc.) |
|
||||
| `data[].face_count` | integer/null | Number of face detections |
|
||||
| `data[].speaker_count` | integer/null | Number of speaker segments |
|
||||
| `data[].start_frame` | integer/null | First appearance frame |
|
||||
| `data[].end_frame` | integer/null | Last appearance frame |
|
||||
| `data[].start_time` | float/null | First appearance time (seconds) |
|
||||
| `data[].end_time` | float/null | Last appearance time (seconds) |
|
||||
| `data[].confidence` | float/null | Average detection confidence |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/faces`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
List all face detections in a specific file with pagination.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `page` | integer | No | 1 | Page number |
|
||||
| `page_size` | integer | No | 50 | Items per page |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/faces?page=1&page_size=100" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"total": 1420,
|
||||
"page": 1,
|
||||
"page_size": 50,
|
||||
"data": [
|
||||
{
|
||||
"face_id": "face_100",
|
||||
"frame_number": 1200,
|
||||
"timestamp": 50.0,
|
||||
"bbox": [100, 50, 300, 400],
|
||||
"confidence": 0.95,
|
||||
"identity_id": 1,
|
||||
"identity_uuid": "a9a90105-6d6b-46ff-92da-0c3c1a57dff4",
|
||||
"trace_id": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `data[].face_id` | string | Face detection ID |
|
||||
| `data[].frame_number` | integer | Frame number in video |
|
||||
| `data[].timestamp` | float | Timestamp in seconds |
|
||||
| `data[].bbox` | array | Bounding box `[x1, y1, x2, y2]` |
|
||||
| `data[].confidence` | float | Detection confidence |
|
||||
| `data[].identity_id` | integer/null | Bound identity ID (null if unbound) |
|
||||
| `data[].identity_uuid` | string/null | Bound identity UUID (null if unbound) |
|
||||
| `data[].trace_id` | integer/null | Face trace ID (null if not traced) |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/json/:processor`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Download raw JSON output for a specific processor.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
| `processor` | string | Yes | Processor name: `cut`, `asrx`, `yolo`, `ocr`, `face`, `pose`, `story`, etc. |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/json/face" \
|
||||
-H "X-API-Key: $KEY" | jq '.frames | length'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
Returns the raw JSON output of the specified processor. Structure varies by processor type.
|
||||
|
||||
#### Error Codes
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | JSON file not found |
|
||||
| `500` | Failed to parse JSON |
|
||||
|
||||
---
|
||||
|
||||
## Unregister
|
||||
|
||||
### `POST /api/v1/unregister`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Delete a registered file from the system. Supports single file by UUID, or batch by directory + regex pattern.
|
||||
|
||||
#### What gets deleted
|
||||
|
||||
| Removed (default) | Not removed |
|
||||
|---------|-------------|
|
||||
| Database records (videos, chunks, embeddings, processor_results, pre_chunks) | The original source video file on disk |
|
||||
| Processor output JSON files (`{uuid}.*.json`) — unless `delete_output_files: false` | Temp/working directories |
|
||||
| In-memory cache entries | |
|
||||
| MongoDB cached lists | |
|
||||
|
||||
> ⚠️ Database deletion is **irreversible**. To keep output files, set `"delete_output_files": false`.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
At least one mode must be specified: either `file_uuid` alone, or `file_path` + `pattern` together.
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `file_uuid` | string | * | — | Single file UUID to delete |
|
||||
| `file_path` | string | * | — | Directory path (for batch delete) |
|
||||
| `pattern` | string | * | — | Regex pattern (requires `file_path`) |
|
||||
| `delete_output_files` | boolean | No | `true` | If `true`, also delete processor output JSON files (`{uuid}.*.json`). Set to `false` to keep them. |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Delete a single file by UUID (default: also deletes output JSON files)
|
||||
curl -s -X POST "$API/api/v1/unregister" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"file_uuid": "'"$FILE_UUID"'"}'
|
||||
|
||||
# Keep output JSON files, only delete DB records
|
||||
curl -s -X POST "$API/api/v1/unregister" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"file_uuid": "'"$FILE_UUID"'", "delete_output_files": false}'
|
||||
|
||||
# Batch delete all mp4 files in a directory
|
||||
curl -s -X POST "$API/api/v1/unregister" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"file_path": "/path/to/dir", "pattern": ".*\\.mp4$"}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "a03485a40b2df2d3",
|
||||
"message": "Video unregistered successfully"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | True if deletion succeeded |
|
||||
| `file_uuid` | string | UUID of the deleted file (single mode) |
|
||||
| `message` | string | Human-readable status |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `400` | Neither `file_uuid` nor `file_path`+`pattern` provided |
|
||||
| `404` | File UUID not found |
|
||||
| `401` | Missing or invalid API key |
|
||||
|
||||
---
|
||||
*Updated: 2026-06-20 — Added file listing, file detail, file identities, file faces, and JSON download endpoints*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,542 @@
|
||||
---
|
||||
title: process API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: process -->
|
||||
<!-- description: Processing pipeline — trigger, probe, progress, jobs -->
|
||||
<!-- depends: 01_auth, 03_register -->
|
||||
|
||||
## Processing Pipeline
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/process`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Trigger the processing pipeline for a registered file. Creates a monitor job that the worker picks up and processes sequentially. Returns immediately with the job info—processing runs asynchronously in the background.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `processors` | string[] | No | all | Specific processors to run: `["cut","asr","asrx","yolo","ocr","face","pose","visual_chunk","story","5w1h"]` |
|
||||
| `rules` | string[] | No | all | Rule names to apply (currently unused) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Run all processors
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/process" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" -d '{}'
|
||||
|
||||
# Run specific processors only
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/process" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"processors": ["asr", "face", "yolo"]}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Processing triggered",
|
||||
"file_uuid": "3a6c1865..."
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Always true on 200 |
|
||||
| `message` | string | Human-readable status message |
|
||||
| `file_uuid` | string | 32-char hex UUID of the file |
|
||||
|
||||
**Note**: Processing runs asynchronously in the background. Use `/api/v1/job/:uuid` to track job status and `/api/v1/progress/:file_uuid` for real-time progress.
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | File UUID not found |
|
||||
| `401` | Missing or invalid API key |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/probe`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get ffprobe metadata for a registered file. Returns video/audio stream info, codec details, duration, resolution, and frame rate.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/probe" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3a6c1865...",
|
||||
"file_name": "video.mp4",
|
||||
"file_size": 794863677,
|
||||
"duration": 120.5,
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"fps": 24.0,
|
||||
"total_frames": 2892,
|
||||
"cached": true,
|
||||
"format": {
|
||||
"filename": "/path/to/video.mp4",
|
||||
"format_name": "mov,mp4,m4a,3gp",
|
||||
"duration": "120.5",
|
||||
"size": "12345678",
|
||||
"bit_rate": "819200"
|
||||
},
|
||||
"streams": [
|
||||
{
|
||||
"index": 0,
|
||||
"codec_name": "h264",
|
||||
"codec_type": "video",
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"r_frame_rate": "24/1",
|
||||
"duration": "120.5"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `file_name` | string | File name |
|
||||
| `file_size` | integer | File size in bytes (from filesystem) |
|
||||
| `duration` | float | Duration in seconds |
|
||||
| `width` | integer | Video width in pixels |
|
||||
| `height` | integer | Video height in pixels |
|
||||
| `fps` | float | Frames per second |
|
||||
| `total_frames` | integer | Estimated total frames |
|
||||
| `cached` | boolean | True if result was from cached probe JSON |
|
||||
| `format` | object | Container format info (ffprobe format section) |
|
||||
| `streams` | array | Array of stream info objects |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/progress/:file_uuid`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get real-time processing progress for a file via Redis pub/sub. Includes per-processor status, current/total frames, ETA, and system resource stats.
|
||||
|
||||
**Note**: This endpoint uses **POST** method, not GET. The progress data is stored in Redis as a hash, and POST is used to retrieve the latest state.
|
||||
|
||||
#### Pipeline Order
|
||||
|
||||
| Order | Processor | Dependencies | Description |
|
||||
|-------|-----------|-------------|-------------|
|
||||
| 1 | `cut` | — | Scene detection |
|
||||
| 2 | `asr` | cut | Speech-to-text (per scene) |
|
||||
| 3 | `asrx` | asr | Speaker diarization |
|
||||
| 4 | `yolo` | — | Object detection |
|
||||
| 5 | `ocr` | — | Text recognition |
|
||||
| 6 | `face` | — | Face detection & embedding (8Hz sampling) |
|
||||
| 7 | `face_trace` | face | Face tracking (IoU + embedding, assigns trace_id) |
|
||||
| 8 | `pose` | face_trace | Pose expansion from face traces, inherits trace_id |
|
||||
| 9 | `appearance` | pose | Appearance expansion from pose traces, inherits trace_id |
|
||||
|
||||
**Key Concepts:**
|
||||
- **Face** = Identity anchor (who is this person?) — requires high-quality embedding
|
||||
- **Pose** = Tracking (where is this person?) — extends tracking when face is occluded
|
||||
- **Appearance** = Tracking (what do they look like?) — extends tracking when pose is occluded
|
||||
|
||||
**Trace ID Inheritance:**
|
||||
```
|
||||
Face trace (identity anchor)
|
||||
↓ inherits trace_id
|
||||
Pose expansion (tracking continuity)
|
||||
↓ inherits trace_id
|
||||
Appearance expansion (tracking continuity)
|
||||
```
|
||||
|
||||
**Frame Count Relationship:**
|
||||
```
|
||||
face frames ≤ pose frames ≤ appearance frames
|
||||
```
|
||||
(Each level expands outward from the previous level's traces)
|
||||
|
||||
All processors except `story` and `5w1h` run concurrently when their dependencies are met. Story and 5W1H run sequentially after their prerequisites.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/progress/$FILE_UUID" -H "X-API-Key: $KEY" | jq '{overall_progress, processors: [.processors[] | {name, status}]}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3a6c1865...",
|
||||
"overall_progress": 71,
|
||||
"cpu_percent": 45.2,
|
||||
"gpu_percent": 30.1,
|
||||
"memory_percent": 62.4,
|
||||
"processors": [
|
||||
{"processor_type": "asr", "status": "complete", "progress": 100},
|
||||
{"processor_type": "yolo", "status": "running", "progress": 65},
|
||||
{"processor_type": "face", "status": "pending", "progress": 0}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `overall_progress` | integer | Overall progress percentage (0–100) |
|
||||
| `processors` | array | Per-processor status list |
|
||||
| `processors[].processor_type` | string | Processor name (`asr`, `cut`, `yolo`, etc.) |
|
||||
| `processors[].status` | string | `"pending"`, `"running"`, `"complete"`, or `"failed"` |
|
||||
| `processors[].progress` | integer | Per-processor progress (0–100) |
|
||||
| `processors[].eta_seconds` | integer | Estimated seconds remaining (running processors) |
|
||||
| `processors[].current` | integer | Current frame count |
|
||||
| `processors[].total` | integer | Total frame count |
|
||||
| `cpu_percent` | float | Current CPU usage |
|
||||
| `gpu_percent` | float | Current GPU utilization |
|
||||
| `memory_percent` | float | Current memory usage |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/jobs`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
List all processing jobs (monitor jobs) in the system. Shows job status, which file each job is processing, and current processor info.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/jobs" -H "X-API-Key: $KEY" | jq '{count, jobs: [.jobs[] | {uuid, status}]}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"jobs": [
|
||||
{
|
||||
"id": 42,
|
||||
"uuid": "3a6c1865...",
|
||||
"status": "running",
|
||||
"current_processor": "yolo",
|
||||
"created_at": "2026-05-16T12:00:00Z",
|
||||
"started_at": "2026-05-16T12:01:00Z"
|
||||
}
|
||||
],
|
||||
"count": 15,
|
||||
"page": 1,
|
||||
"page_size": 20
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `jobs` | array | Array of job info objects |
|
||||
| `jobs[].id` | integer | Job ID |
|
||||
| `jobs[].uuid` | string | File UUID being processed |
|
||||
| `jobs[].status` | string | `"pending"`, `"running"`, `"completed"`, `"failed"` |
|
||||
| `jobs[].current_processor` | string | Currently active processor, or null |
|
||||
| `count` | integer | Total job count |
|
||||
| `page` | integer | Current page number |
|
||||
| `page_size` | integer | Jobs per page |
|
||||
|
||||
### `GET /api/v1/job/:uuid`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get detailed information about a specific processing job, including its queue position.
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"id": 51,
|
||||
"uuid": "c36f35685177c981aa139b66bbbccc5b",
|
||||
"status": "queued",
|
||||
"current_processor": null,
|
||||
"progress_current": 0,
|
||||
"progress_total": 0,
|
||||
"processors": [],
|
||||
"created_at": "2026-06-22 23:08:48.497018",
|
||||
"started_at": null,
|
||||
"updated_at": null,
|
||||
"queue_position": 3
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `id` | integer | Monitor job ID |
|
||||
| `uuid` | string | File UUID |
|
||||
| `status` | string | `"pending"`, `"queued"`, `"running"`, `"completed"`, `"failed"` |
|
||||
| `current_processor` | string | Currently active processor, or null |
|
||||
| `progress_current` | integer | Current progress count |
|
||||
| `progress_total` | integer | Total progress count |
|
||||
| `processors` | array | Processor list |
|
||||
| `created_at` | string | Job creation timestamp |
|
||||
| `started_at` | string | Processing start timestamp, or null |
|
||||
| `updated_at` | string | Last update timestamp, or null |
|
||||
| `queue_position` | integer | Position in FIFO queue (null if not pending/queued) |
|
||||
|
||||
---
|
||||
|
||||
### Status Lifecycle
|
||||
|
||||
```
|
||||
register ──→ pending
|
||||
│
|
||||
trigger (POST /process)
|
||||
│
|
||||
queued ←── queue_position counts jobs ahead
|
||||
│
|
||||
worker picks up
|
||||
│
|
||||
processing
|
||||
│
|
||||
┌────────┴────────┐
|
||||
▼ ▼
|
||||
completed failed
|
||||
│
|
||||
checkin ──→ indexed
|
||||
checkout ──→ checked_out
|
||||
```
|
||||
|
||||
| Status | Meaning |
|
||||
|--------|---------|
|
||||
| `pending` | File registered, not yet triggered |
|
||||
| `queued` | Triggered, waiting for worker in FIFO queue |
|
||||
| `processing` | Worker actively processing |
|
||||
| `completed` | All processors finished successfully |
|
||||
| `failed` | One or more essential processors failed |
|
||||
| `indexed` | Post-processing checkin complete |
|
||||
| `checked_out` | User checked out the file |
|
||||
|
||||
Queue order is FIFO (`created_at ASC`). The `GET /api/v1/job/:uuid` endpoint returns `queue_position` showing how many jobs are ahead.
|
||||
|
||||
### Frontend Status Mapping
|
||||
|
||||
When displaying file status in the frontend list (e.g. after `GET /api/v1/files/scan`), map the `status` field as follows:
|
||||
|
||||
| DB Status | Status Label | Filter: 待處理 | Filter: 處理中 | Count: pendingCount | Count: processingCount |
|
||||
|-----------|-------------|----------------|----------------|---------------------|-----------------------|
|
||||
| `unregistered` | 未註冊 | No | No | No | No |
|
||||
| `registered` | 待處理 | **Yes** | No | **Yes** | No |
|
||||
| `pending` | 待處理 | **Yes** | No | **Yes** | No |
|
||||
| `queued` | 排隊中 | **Yes** | **Yes** | **Yes** | **Yes** |
|
||||
| `processing` | 處理中 | No | **Yes** | No | **Yes** |
|
||||
| `completed` | 已完成 | No | No | No | No |
|
||||
| `failed` | 處理失敗 | No | No | No | No |
|
||||
| `indexed` | 已入庫 | No | No | No | No |
|
||||
|
||||
**`queued` 的特殊處理**:
|
||||
- `statusLabel` → 顯示「排隊中」,加 `ms-badge-warn` 樣式(黃色)
|
||||
- `filterPending` → 應包含 `queued`,讓它在「待處理」filter 可見
|
||||
- `pendingCount` + `processingCount` → 兩者都應包含 `queued`,因它既是「待處理」也是「正在排隊」
|
||||
- 在 `refreshAllStatus` / `loadFiles` 中,如果檔案狀態是 `queued`,應顯示簡單的排隊訊息(無需 polling progress)
|
||||
- 當 worker pickup 後,狀態會變為 `processing`,此時 `refreshAllStatus` 會自動偵測到並開始 polling progress
|
||||
- 也可以提供一個「queue_position」顯示:呼叫 `GET /api/v1/job/:uuid` 取得排在第幾位
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/processor-counts`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get counts of processor JSON output files. See `15_tkg.md` for full documentation.
|
||||
|
||||
---
|
||||
|
||||
## Pipeline Steps (Manual)
|
||||
|
||||
These endpoints execute individual pipeline steps. They are typically called by the worker automatically, but can be invoked manually for debugging or re-processing.
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/store-asrx`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Store ASRX diarization results as chunk records in the database. Converts ASRX segments into searchable chunk entries.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/store-asrx" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "ASRX chunks stored",
|
||||
"file_uuid": "3a6c1865..."
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/rule1`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Execute Rule 1 pipeline step. Applies rule-based chunking to create structured chunk records from processor outputs.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/rule1" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Rule 1 complete: 45 chunks",
|
||||
"file_uuid": "3a6c1865...",
|
||||
"chunks": 45
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Always true on 200 |
|
||||
| `message` | string | Human-readable completion message |
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `chunks` | integer | Number of chunks produced |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/vectorize`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Generate vector embeddings for all chunks of a file and store them in Qdrant for semantic search.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/vectorize" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Vectorization complete",
|
||||
"file_uuid": "3a6c1865..."
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/phase1`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Execute Phase 1 of the post-processing pipeline. Combines store-asrx, rule1, and vectorize into a single step.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/phase1" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Phase 1 complete",
|
||||
"file_uuid": "3a6c1865..."
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/complete`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Mark a video as fully processed. Updates the video status to `completed` and finalizes all pipeline state.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/complete" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Video marked as completed",
|
||||
"file_uuid": "3a6c1865..."
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Pipeline Step Order
|
||||
|
||||
```
|
||||
process (trigger)
|
||||
│
|
||||
├─→ cut, yolo, ocr, face, pose, asrx (parallel processors)
|
||||
│
|
||||
├─→ store-asrx (store diarization as chunks)
|
||||
│
|
||||
├─→ rule1 (rule-based chunking)
|
||||
│
|
||||
├─→ vectorize (embed chunks to Qdrant)
|
||||
│
|
||||
└─→ complete (mark done)
|
||||
```
|
||||
|
||||
Phase 1 (`/phase1`) combines store-asrx + rule1 + vectorize into one call.
|
||||
|
||||
---
|
||||
*Updated: 2026-06-23 — Added queued status, FIFO queue order, queue_position in job detail, frontend status mapping table*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,146 @@
|
||||
---
|
||||
title: pipeline API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: pipeline -->
|
||||
<!-- description: Pipeline processors, ingestion status, stats endpoints -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## Pipeline
|
||||
|
||||
### Pipeline Completion Flow
|
||||
|
||||
The pipeline is **not complete** until both the 10 processors AND the 入庫 (ingestion) steps have finished. The worker polls every 3 seconds and only marks the job as `completed` when all ingestion steps verify OK.
|
||||
|
||||
```
|
||||
10 processors done
|
||||
↓ (job status stays "running")
|
||||
Algorithm 1 Trigger: Rule 1 + Vectorize + Phase 1 Pack
|
||||
↓ (job runs in parallel)
|
||||
Algorithm 2 Trigger: Face Trace → TKG, Scene Metadata, Identity Agent, 5W1H Agent
|
||||
↓ (poll checks every 3s)
|
||||
Ingestion verification: rule1 ✓ vectorize ✓ rule3 ✓ face_trace ✓ tkg ✓ scene_meta ✓ 5w1h ✓
|
||||
↓
|
||||
job status = "completed"
|
||||
```
|
||||
|
||||
### 10 Processor Stages
|
||||
|
||||
| # | Processor | Depends On | Description |
|
||||
|---|-----------|------------|-------------|
|
||||
| 1 | `Cut` | — | Scene boundary detection (PySceneDetect) |
|
||||
| 2 | `ASR` | Cut | Automatic speech recognition (faster-whisper) |
|
||||
| 3 | `ASRX` | ASR | Speaker diarization + ASR refinement |
|
||||
| 4 | `YOLO` | — | Object detection (YOLOv8) |
|
||||
| 5 | `OCR` | — | Optical character recognition |
|
||||
| 6 | `Face` | — | Face detection + recognition (InsightFace + CoreML) |
|
||||
| 7 | `Pose` | — | Pose estimation |
|
||||
| 8 | `VisualChunk` | YOLO | Visual object chunking |
|
||||
| 9 | `Story` | ASRX + Cut + YOLO + Face | Narrative scene summarization (LLM, with embedding) |
|
||||
| 10 | `5W1H` | Story | Who/What/When/Where/Why extraction (LLM, with embedding) |
|
||||
|
||||
### 入庫 (Post-Processing / Ingestion)
|
||||
|
||||
These steps run after the 10 processors and are **required for pipeline completion**. The worker checks all of them before marking the job as done.
|
||||
|
||||
| # | Step | Triggers When | Verification |
|
||||
|---|------|--------------|-------------|
|
||||
| 1 | **Rule 1 Sentence Chunking** | ASR + ASRX done | `chunk` table has rows with `chunk_type = 'sentence'` |
|
||||
| 1.1 | **Rule 1 OCR Chunks** | OCR done | OCR pre_chunks grouped into sentence chunks |
|
||||
| 2 | **Auto-Vectorize** | Rule 1 done | `chunk.embedding` IS NOT NULL for sentence chunks |
|
||||
| 3 | **Phase 1 Pack** | Rule 1 done | `release_pack.py --phase 1` executed |
|
||||
| 4 | **Rule 3 Scene Chunking** | All 10 processors done + Cut + ASR | `chunk` table has rows with `chunk_type = 'cut'` |
|
||||
| 5 | **Face Trace** | All 10 processors done + Face | `face_detections.trace_id` IS NOT NULL |
|
||||
| 6 | **Qdrant Face Sync** | Face Trace done | Qdrant face_embedding collection populated |
|
||||
| 7 | **Trace Chunks** | Face Trace done | `chunk` table has rows with `chunk_type = 'trace'` |
|
||||
| 8 | **TKG Builder** | Face Trace done | `tkg_nodes` + `tkg_edges` tables have rows |
|
||||
| 9 | **TMDb Face Matching** | TMDb enabled + Face done | `face_detections.identity_id` IS NOT NULL |
|
||||
| 10 | **Heuristic Scene Metadata** | Face + YOLO done | `{file_uuid}.scene_meta.json` exists on disk |
|
||||
| 11 | **Template 5W1H Story Summary (PG)** | Story done | `chunk.embedding` IS NOT NULL for story chunks |
|
||||
| 12 | **LLM 5W1H Summary (PG)** | 5W1H done | `chunk.embedding` IS NOT NULL for llm chunks |
|
||||
| 13 | **Voice Embedding (Qdrant)** | ASRX done | Qdrant voice collection populated |
|
||||
| 14 | **Face Embedding (Qdrant)** | Face done | Qdrant face collection populated |
|
||||
| 15 | **Identity Agent** | Face + ASRX done | `identities` with `source = 'identity_agent'` |
|
||||
| 16 | **5W1H Agent** | Cut + ASR done | `chunk.summary_text` IS NOT NULL for cut chunks |
|
||||
| 17 | **Release Pack** | 5W1H Agent done | `release_pack.py --phase 2` executed |
|
||||
|
||||
### Ingestion Status
|
||||
|
||||
Check real-time ingestion status for a file:
|
||||
|
||||
```bash
|
||||
curl "$API/api/v1/stats/ingestion-status/{file_uuid}"
|
||||
```
|
||||
|
||||
Returns per-step `done` / `pending` status with detail counts.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl "$API/api/v1/stats/ingestion-status/bd80fec9c42afb0307eb28f22c64c76a" | jq '.steps[] | {name, status, detail}'
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "bd80fec9c42afb0307eb28f22c64c76a",
|
||||
"steps": [
|
||||
{ "name": "rule1_sentence", "status": "done", "detail": "35 sentence chunks" },
|
||||
{ "name": "rule1_ocr", "status": "done", "detail": "30 OCR frames" },
|
||||
{ "name": "rule1_ocr_chunks", "status": "done", "detail": "3 OCR-only chunks" },
|
||||
{ "name": "auto_vectorize", "status": "pending", "detail": "0 embedded" },
|
||||
{ "name": "rule3_scene", "status": "pending", "detail": "0 scene chunks" },
|
||||
{ "name": "face_trace", "status": "pending", "detail": "0 traces" },
|
||||
{ "name": "trace_chunks", "status": "pending", "detail": "0 trace chunks" },
|
||||
{ "name": "tkg", "status": "pending", "detail": "0 nodes, 0 edges" },
|
||||
{ "name": "identity_match", "status": "pending", "detail": "0 identities" },
|
||||
{ "name": "scene_metadata", "status": "pending", "detail": null },
|
||||
{ "name": "5w1h", "status": "pending", "detail": "0 scenes with 5W1H" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Stats Endpoints
|
||||
|
||||
| Method | Endpoint | Auth | Description |
|
||||
|--------|----------|------|-------------|
|
||||
| GET | `/api/v1/stats/sftpgo` | No | SFTPGo service status |
|
||||
| GET | `/api/v1/stats/ingestion-status/:file_uuid` | No | Per-file ingestion checklist |
|
||||
|
||||
### Configuration
|
||||
|
||||
See [13_config.md](13_config.md) for runtime configuration endpoints:
|
||||
|
||||
| Endpoint | Description |
|
||||
|----------|-------------|
|
||||
| `POST /api/v1/config/cache` | Toggle Redis cache |
|
||||
| `POST /api/v1/config/auto-pipeline` | Toggle auto-pipeline on register |
|
||||
| `POST /api/v1/config/watcher-auto-register` | Toggle watcher auto-register |
|
||||
|
||||
### Unmounted Routes
|
||||
|
||||
The following routes are defined in source code but are **NOT** currently mounted in the router:
|
||||
|
||||
| Endpoint | Source file |
|
||||
|----------|-------------|
|
||||
| `/api/v1/search/people` | `universal_search.rs` (mounted) |
|
||||
| `/api/v1/who` | `who.rs` |
|
||||
| `/api/v1/who/candidates` | `who.rs` |
|
||||
|
||||
---
|
||||
*Updated: 2026-05-19 23:21:51*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,563 @@
|
||||
---
|
||||
title: progress API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: progress -->
|
||||
<!-- description: Real-time progress tracking for processing pipeline, TKG build, and identity agent -->
|
||||
<!-- depends: 01_auth, 03_register, 05_process -->
|
||||
|
||||
# Progress Tracking — API Workspace Module
|
||||
|
||||
## Overview
|
||||
|
||||
The progress tracking system provides real-time visibility into all processing stages:
|
||||
|
||||
| System | Redis Key | Coverage |
|
||||
|--------|-----------|----------|
|
||||
| **Processor Progress** | `{prefix}progress:{file_uuid}` | 7 main processors (cut, asr, asrx, ocr, face, pose, appearance) |
|
||||
| **TKG Progress** | `{prefix}progress:{file_uuid}:tkg` | 18 TKG build phases (9 node types + 8 edge types + face_tracing) |
|
||||
| **Agent Progress** | `{prefix}progress:{file_uuid}:agent` | 5 Identity Agent phases |
|
||||
|
||||
---
|
||||
|
||||
## `POST /api/v1/progress/:file_uuid`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get real-time processing progress including processor status, TKG build phases, and identity agent phases.
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/progress/$FILE_UUID" \
|
||||
-H "X-API-Key: $KEY" | jq '.'
|
||||
```
|
||||
|
||||
### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3a6c1865...",
|
||||
"overall_progress": 71,
|
||||
"cpu_percent": 45.2,
|
||||
"gpu_percent": 30.1,
|
||||
"memory_percent": 62.4,
|
||||
"processors": [
|
||||
{"name": "asr", "status": "complete", "progress": 100, "current": 0, "total": 0, "message": "done"},
|
||||
{"name": "face", "status": "complete", "progress": 100, "current": 0, "total": 0, "message": "done"},
|
||||
{"name": "pose", "status": "complete", "progress": 100, "current": 0, "total": 0, "message": "done"}
|
||||
],
|
||||
"tkg_progress": {
|
||||
"file_uuid": "3a6c1865...",
|
||||
"phase": "mutual_gaze_edges",
|
||||
"phase_index": 13,
|
||||
"total_phases": 18,
|
||||
"phase_progress": 0.8,
|
||||
"overall_progress": 0.72,
|
||||
"stats": {
|
||||
"total_faces": 1250,
|
||||
"traced_faces": 1250,
|
||||
"total_traces": 45,
|
||||
"face_track_nodes": 45,
|
||||
"gaze_track_nodes": 45,
|
||||
"lip_track_nodes": 12,
|
||||
"text_region_nodes": 8,
|
||||
"appearance_nodes": 38,
|
||||
"accessory_nodes": 5,
|
||||
"object_nodes": 156,
|
||||
"hand_nodes": 22,
|
||||
"speaker_nodes": 14,
|
||||
"co_occurrence_edges": 890,
|
||||
"speaker_face_edges": 120,
|
||||
"face_face_edges": 234,
|
||||
"mutual_gaze_edges": 67,
|
||||
"total_nodes": 345,
|
||||
"total_edges": 1311
|
||||
},
|
||||
"message": "67 mutual gaze edges",
|
||||
"updated_at": "2026-07-02T10:30:00Z"
|
||||
},
|
||||
"agent_progress": {
|
||||
"file_uuid": "3a6c1865...",
|
||||
"phase": "completed",
|
||||
"phase_index": 5,
|
||||
"total_phases": 5,
|
||||
"phase_progress": 1.0,
|
||||
"overall_progress": 1.0,
|
||||
"stats": {
|
||||
"total_faces": 1250,
|
||||
"total_traces": 45,
|
||||
"clusters": 18,
|
||||
"identities_created": 18,
|
||||
"tmdb_matches": 5,
|
||||
"speaker_bindings": 12,
|
||||
"confirmations": 18
|
||||
},
|
||||
"message": "Identity Agent processing completed",
|
||||
"updated_at": "2026-07-02T10:28:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Field Descriptions
|
||||
|
||||
#### Top Level
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `overall_progress` | integer | Overall processor progress (0–100) |
|
||||
| `processors` | array | Per-processor status |
|
||||
| `tkg_progress` | object | TKG build progress (null if not started) |
|
||||
| `agent_progress` | object | Identity Agent progress (null if not started) |
|
||||
|
||||
#### TKG Progress Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `phase` | string | Current phase name (see TKG Phases below) |
|
||||
| `phase_index` | integer | Current phase index (0–17) |
|
||||
| `total_phases` | integer | Total phases: 18 |
|
||||
| `phase_progress` | float | Progress within current phase (0.0–1.0) |
|
||||
| `overall_progress` | float | Overall TKG progress (0.0–1.0) |
|
||||
| `stats` | object | Counts for all node and edge types |
|
||||
| `message` | string | Human-readable status message |
|
||||
|
||||
#### TKG Phases (18 total)
|
||||
|
||||
| Index | Phase | Description |
|
||||
|-------|-------|-------------|
|
||||
| 0 | `face_tracing` | Populate trace_id from face.json |
|
||||
| 1 | `face_track_nodes` | Build face_track nodes |
|
||||
| 2 | `gaze_track_nodes` | Build gaze_track nodes |
|
||||
| 3 | `lip_track_nodes` | Build lip_track nodes |
|
||||
| 4 | `text_region_nodes` | Build text_region nodes |
|
||||
| 5 | `appearance_nodes` | Build appearance_trace nodes |
|
||||
| 6 | `accessory_nodes` | Build accessory nodes |
|
||||
| 7 | `object_nodes` | Build yolo_object nodes |
|
||||
| 8 | `hand_nodes` | Build hand nodes |
|
||||
| 9 | `speaker_nodes` | Build speaker nodes |
|
||||
| 10 | `co_occurrence_edges` | Build co_occurrence edges |
|
||||
| 11 | `speaker_face_edges` | Build speaker_face edges |
|
||||
| 12 | `face_face_edges` | Build face_face edges |
|
||||
| 13 | `mutual_gaze_edges` | Build mutual_gaze edges |
|
||||
| 14 | `lip_sync_edges` | Build lip_sync edges |
|
||||
| 15 | `has_appearance_edges` | Build has_appearance edges |
|
||||
| 16 | `wears_edges` | Build wears edges |
|
||||
| 17 | `hand_object_edges` | Build hand_object edges |
|
||||
|
||||
#### TKG Stats Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `total_faces` | integer | Total face detections |
|
||||
| `traced_faces` | integer | Faces with trace_id assigned |
|
||||
| `total_traces` | integer | Unique trace count |
|
||||
| `face_track_nodes` | integer | Face track nodes created |
|
||||
| `gaze_track_nodes` | integer | Gaze track nodes created |
|
||||
| `lip_track_nodes` | integer | Lip track nodes created |
|
||||
| `text_region_nodes` | integer | Text region nodes created |
|
||||
| `appearance_nodes` | integer | Appearance trace nodes created |
|
||||
| `accessory_nodes` | integer | Accessory nodes created |
|
||||
| `object_nodes` | integer | YOLO object nodes created |
|
||||
| `hand_nodes` | integer | Hand nodes created |
|
||||
| `speaker_nodes` | integer | Speaker nodes created |
|
||||
| `co_occurrence_edges` | integer | Co-occurrence edges created |
|
||||
| `speaker_face_edges` | integer | Speaker-face edges created |
|
||||
| `face_face_edges` | integer | Face-face edges created |
|
||||
| `mutual_gaze_edges` | integer | Mutual gaze edges created |
|
||||
| `lip_sync_edges` | integer | Lip sync edges created |
|
||||
| `has_appearance_edges` | integer | Has-appearance edges created |
|
||||
| `wears_edges` | integer | Wears edges created |
|
||||
| `hand_object_edges` | integer | Hand-object edges created |
|
||||
| `total_nodes` | integer | Total nodes (sum of all node types) |
|
||||
| `total_edges` | integer | Total edges (sum of all edge types) |
|
||||
|
||||
---
|
||||
|
||||
## `GET /api/v1/stats/ingestion-status/:file_uuid`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get detailed ingestion status showing completion of all 24 processing steps.
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/stats/ingestion-status/$FILE_UUID" \
|
||||
-H "X-API-Key: $KEY" | jq '.steps[] | {name, status, detail}'
|
||||
```
|
||||
|
||||
### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3a6c1865...",
|
||||
"steps": [
|
||||
{"name": "rule1_sentence", "status": "done", "detail": "156 sentence chunks"},
|
||||
{"name": "auto_vectorize", "status": "done", "detail": "156 embedded"},
|
||||
{"name": "face_track", "status": "done", "detail": "45 traces / 1250 detections"},
|
||||
{"name": "trace_chunks", "status": "done", "detail": "45 trace chunks"},
|
||||
{"name": "tkg_face_track", "status": "done", "detail": "45 nodes"},
|
||||
{"name": "tkg_gaze_track", "status": "done", "detail": "45 nodes"},
|
||||
{"name": "tkg_lip_track", "status": "done", "detail": "12 nodes"},
|
||||
{"name": "tkg_text_region", "status": "done", "detail": "8 nodes"},
|
||||
{"name": "tkg_appearance", "status": "done", "detail": "38 nodes"},
|
||||
{"name": "tkg_accessory", "status": "done", "detail": "5 nodes"},
|
||||
{"name": "tkg_object", "status": "done", "detail": "156 nodes"},
|
||||
{"name": "tkg_hand", "status": "done", "detail": "22 nodes"},
|
||||
{"name": "tkg_speaker", "status": "done", "detail": "14 nodes"},
|
||||
{"name": "tkg_co_occurrence", "status": "done", "detail": "890 edges"},
|
||||
{"name": "tkg_speaker_face", "status": "done", "detail": "120 edges"},
|
||||
{"name": "tkg_face_face", "status": "done", "detail": "234 edges"},
|
||||
{"name": "tkg_mutual_gaze", "status": "done", "detail": "67 edges"},
|
||||
{"name": "tkg_lip_sync", "status": "done", "detail": "12 edges"},
|
||||
{"name": "tkg_has_appearance", "status": "done", "detail": "38 edges"},
|
||||
{"name": "tkg_wears", "status": "done", "detail": "22 edges"},
|
||||
{"name": "tkg_hand_object", "status": "done", "detail": "18 edges"},
|
||||
{"name": "rule2_relationship", "status": "done", "detail": "1331 relationship chunks"},
|
||||
{"name": "identity_match", "status": "done", "detail": "18 identities matched"},
|
||||
{"name": "scene_metadata", "status": "done", "detail": null}
|
||||
],
|
||||
"related_identities": [
|
||||
{"uuid": "a9a901056d6b46ff92da0c3c1a57dff4", "name": "John Smith"}
|
||||
],
|
||||
"strangers": 3
|
||||
}
|
||||
```
|
||||
|
||||
### Step Descriptions
|
||||
|
||||
| Step | Status When Done |
|
||||
|------|-----------------|
|
||||
| `rule1_sentence` | sentence_count > 0 |
|
||||
| `auto_vectorize` | sentence_embedded > 0 |
|
||||
| `face_track` | trace_count > 0 |
|
||||
| `trace_chunks` | trace_chunks > 0 |
|
||||
| `tkg_face_track` → `tkg_speaker` | Node count > 0 (9 steps) |
|
||||
| `tkg_co_occurrence` → `tkg_hand_object` | Edge count > 0 (8 steps) |
|
||||
| `rule2_relationship` | relationship_chunks > 0 |
|
||||
| `identity_match` | identity_count > 0 |
|
||||
| `scene_metadata` | scene_meta.json exists |
|
||||
|
||||
---
|
||||
|
||||
## `POST /api/v1/file/:file_uuid/tkg/rebuild`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Manually trigger TKG rebuild. Automatically triggers Rule 2 ingestion after TKG completes.
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tkg/rebuild" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" -d '{}'
|
||||
```
|
||||
|
||||
### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "TKG rebuild started",
|
||||
"nodes": 345,
|
||||
"edges": 1311
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## `POST /api/v1/file/:file_uuid/rule2`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Manually trigger Rule 2 ingestion (TKG edges → relationship chunks).
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/rule2" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" -d '{}'
|
||||
```
|
||||
|
||||
### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Rule 2 ingestion: 1331 relationship chunks created",
|
||||
"rule2_count": 1331
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Processing Pipeline Flow
|
||||
|
||||
```
|
||||
1. Processors (concurrent)
|
||||
├── cut, asr, ocr, face, pose, appearance → complete
|
||||
└── asrx → after cut+asr
|
||||
|
||||
2. Post-Processor Triggers (automatic)
|
||||
├── Rule 1 Ingestion (ASR+OCR → sentence chunks)
|
||||
├── Face Trace + DB Store (face_traced.json → Qdrant trace_id)
|
||||
├── TMDb Face Matching (if enabled)
|
||||
├── Heuristic Scene Metadata
|
||||
├── Identity Agent (face + ASRX)
|
||||
└── TKG Build (automatic after processors complete)
|
||||
└── Rule 2 Ingestion (automatic after TKG)
|
||||
└── Relationship chunks vectorized
|
||||
|
||||
3. Completion
|
||||
└── Job marked completed when all ingestion steps done
|
||||
```
|
||||
|
||||
## Error Codes
|
||||
|
||||
| Code | HTTP | When |
|
||||
|------|------|------|
|
||||
| E001 | 400 | Invalid file_uuid format |
|
||||
| E002 | 404 | File not found |
|
||||
| E003 | 404 | No TKG data available |
|
||||
| E010 | 500 | Qdrant connection failed |
|
||||
| E011 | 500 | Database connection failed |
|
||||
|
||||
---
|
||||
|
||||
## `GET /api/v1/stats/pipeline/:file_uuid`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get segmented pipeline progress with weighted stage breakdown. Shows overall progress as weighted sum of all pipeline stages.
|
||||
|
||||
### Pipeline Stages and Weights
|
||||
|
||||
| Stage | Weight | Description |
|
||||
|-------|--------|-------------|
|
||||
| `processors` | 30% | 7 concurrent processors (cut, asr, asrx, ocr, face, pose, appearance) |
|
||||
| `rule1_ingestion` | 5% | ASR+OCR → sentence chunks |
|
||||
| `face_tracing` | 5% | Face trace_id assignment |
|
||||
| `identity_agent` | 10% | Identity creation, TMDb matching, speaker binding |
|
||||
| `tkg_nodes` | 20% | TKG node building (9 node types) |
|
||||
| `tkg_edges` | 15% | TKG edge building (8 edge types) |
|
||||
| `rule2_ingestion` | 15% | TKG edges → relationship chunks |
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/stats/pipeline/$FILE_UUID" \
|
||||
-H "X-API-Key: $KEY" | jq '.'
|
||||
```
|
||||
|
||||
### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3a6c1865...",
|
||||
"overall_progress": 0.65,
|
||||
"stages": [
|
||||
{"name": "processors", "weight": 0.30, "progress": 1.0, "status": "completed", "detail": "7/7 complete"},
|
||||
{"name": "rule1_ingestion", "weight": 0.05, "progress": 1.0, "status": "completed", "detail": "156 chunks"},
|
||||
{"name": "face_tracing", "weight": 0.05, "progress": 1.0, "status": "completed", "detail": "45 traces"},
|
||||
{"name": "identity_agent", "weight": 0.10, "progress": 1.0, "status": "completed", "detail": "18 identities"},
|
||||
{"name": "tkg_nodes", "weight": 0.20, "progress": 1.0, "status": "completed", "detail": "345 nodes"},
|
||||
{"name": "tkg_edges", "weight": 0.15, "progress": 0.5, "status": "running", "detail": "mutual_gaze_edges: 67/8 expected"},
|
||||
{"name": "rule2_ingestion", "weight": 0.15, "progress": 0.0, "status": "pending", "detail": null}
|
||||
],
|
||||
"updated_at": "2026-07-02T10:30:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
### Field Descriptions
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `overall_progress` | float | Weighted sum of all stage progress (0.0–1.0) |
|
||||
| `stages` | array | Per-stage progress breakdown |
|
||||
| `stages[].name` | string | Stage name |
|
||||
| `stages[].weight` | float | Stage weight in overall progress |
|
||||
| `stages[].progress` | float | Stage completion (0.0–1.0) |
|
||||
| `stages[].status` | string | `"pending"`, `"running"`, `"completed"`, `"failed"` |
|
||||
| `stages[].detail` | string | Human-readable detail (optional) |
|
||||
| `updated_at` | string | ISO 8601 timestamp |
|
||||
|
||||
### Overall Progress Calculation
|
||||
|
||||
```
|
||||
overall_progress = Σ(stage.weight × stage.progress) for all stages
|
||||
```
|
||||
|
||||
Example calculation:
|
||||
- processors: 0.30 × 1.0 = 0.30
|
||||
- rule1_ingestion: 0.05 × 1.0 = 0.05
|
||||
- face_tracing: 0.05 × 1.0 = 0.05
|
||||
- identity_agent: 0.10 × 1.0 = 0.10
|
||||
- tkg_nodes: 0.20 × 1.0 = 0.20
|
||||
- tkg_edges: 0.15 × 0.5 = 0.075
|
||||
- rule2_ingestion: 0.15 × 0.0 = 0.0
|
||||
- **Total: 0.775 (77.5%)**
|
||||
|
||||
---
|
||||
|
||||
## `GET /api/v1/stats/file/:file_uuid`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get comprehensive file statistics from all data sources: JSON processing status, PostgreSQL counts, Qdrant collections, TKG nodes/edges, and Identity Agent stats.
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/stats/file/$FILE_UUID" \
|
||||
-H "X-API-Key: $KEY" | jq '.'
|
||||
```
|
||||
|
||||
### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3a6c1865...",
|
||||
"file_name": "video.mp4",
|
||||
"status": "processing",
|
||||
"processors": [
|
||||
{"name": "asr", "status": "complete", "progress": 100, "message": "done"},
|
||||
{"name": "face", "status": "complete", "progress": 100, "message": "done"}
|
||||
],
|
||||
"postgres": {
|
||||
"sentence_chunks": 156,
|
||||
"trace_chunks": 45,
|
||||
"relationship_chunks": 1331,
|
||||
"identities": 18,
|
||||
"file_identities": 18
|
||||
},
|
||||
"qdrant": {
|
||||
"faces": 1250,
|
||||
"face_traces": 45,
|
||||
"face_identities": 18,
|
||||
"text_chunks": 4562,
|
||||
"speakers": 434
|
||||
},
|
||||
"tkg": {
|
||||
"total_nodes": 345,
|
||||
"total_edges": 1311,
|
||||
"face_track_nodes": 45,
|
||||
"gaze_track_nodes": 45,
|
||||
"lip_track_nodes": 12,
|
||||
"text_region_nodes": 8,
|
||||
"appearance_nodes": 38,
|
||||
"accessory_nodes": 5,
|
||||
"object_nodes": 156,
|
||||
"hand_nodes": 22,
|
||||
"speaker_nodes": 14,
|
||||
"co_occurrence_edges": 890,
|
||||
"speaker_face_edges": 120,
|
||||
"face_face_edges": 234,
|
||||
"mutual_gaze_edges": 67,
|
||||
"lip_sync_edges": 12,
|
||||
"has_appearance_edges": 38,
|
||||
"wears_edges": 22,
|
||||
"hand_object_edges": 18
|
||||
},
|
||||
"identity_agent": {
|
||||
"clusters": 18,
|
||||
"identities_created": 18,
|
||||
"tmdb_matches": 5,
|
||||
"speaker_bindings": 12,
|
||||
"confirmations": 18
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Field Descriptions
|
||||
|
||||
#### Top Level
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `file_name` | string | Original filename |
|
||||
| `status` | string | File status: `registered`, `processing`, `completed`, `failed` |
|
||||
| `processors` | array | Per-processor status from processing_status JSONB |
|
||||
| `postgres` | object | PostgreSQL table counts |
|
||||
| `qdrant` | object | Qdrant collection point counts |
|
||||
| `tkg` | object | TKG node and edge counts by type |
|
||||
| `identity_agent` | object | Identity Agent statistics |
|
||||
|
||||
#### PostgreSQL Stats
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `sentence_chunks` | integer | Rule 1 sentence chunks count |
|
||||
| `trace_chunks` | integer | Face trace chunks count |
|
||||
| `relationship_chunks` | integer | Rule 2 relationship chunks count |
|
||||
| `identities` | integer | Unique identities bound to this file |
|
||||
| `file_identities` | integer | File-identity mapping records |
|
||||
|
||||
#### Qdrant Stats
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `faces` | integer | Total face points in `_faces` collection |
|
||||
| `face_traces` | integer | Unique trace IDs in `_faces` |
|
||||
| `face_identities` | integer | Unique identity IDs bound in `_faces` |
|
||||
| `text_chunks` | integer | Text chunk vectors in `momentry_*_rule1_v2` |
|
||||
| `speakers` | integer | Speaker segments in `momentry_*_speaker` |
|
||||
|
||||
#### TKG Stats
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `total_nodes` | integer | Sum of all node types |
|
||||
| `total_edges` | integer | Sum of all edge types |
|
||||
| `face_track_nodes` | integer | Face track nodes |
|
||||
| `gaze_track_nodes` | integer | Gaze track nodes |
|
||||
| `lip_track_nodes` | integer | Lip track nodes |
|
||||
| `text_region_nodes` | integer | Text region nodes |
|
||||
| `appearance_nodes` | integer | Appearance trace nodes |
|
||||
| `accessory_nodes` | integer | Accessory nodes |
|
||||
| `object_nodes` | integer | YOLO object nodes |
|
||||
| `hand_nodes` | integer | Hand nodes |
|
||||
| `speaker_nodes` | integer | Speaker nodes |
|
||||
| `co_occurrence_edges` | integer | Co-occurrence edges |
|
||||
| `speaker_face_edges` | integer | Speaker-face edges |
|
||||
| `face_face_edges` | integer | Face-face edges |
|
||||
| `mutual_gaze_edges` | integer | Mutual gaze edges |
|
||||
| `lip_sync_edges` | integer | Lip sync edges |
|
||||
| `has_appearance_edges` | integer | Has-appearance edges |
|
||||
| `wears_edges` | integer | Wears edges |
|
||||
| `hand_object_edges` | integer | Hand-object edges |
|
||||
|
||||
#### Identity Agent Stats
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `clusters` | integer | Face clusters from face_clustered.json |
|
||||
| `identities_created` | integer | Identities created from clusters |
|
||||
| `tmdb_matches` | integer | TMDb identity matches |
|
||||
| `speaker_bindings` | integer | Speaker-to-identity bindings |
|
||||
| `confirmations` | integer | Confirmed identity bindings |
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,281 @@
|
||||
---
|
||||
title: Job Management API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-25
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: job_management -->
|
||||
<!-- description: Job pause/resume and status management -->
|
||||
<!-- depends: 01_auth, 05_process -->
|
||||
|
||||
## Job Management
|
||||
|
||||
Control job execution with pause/resume functionality. Useful for managing system load and prioritizing jobs.
|
||||
|
||||
### `POST /api/v1/jobs/:uuid/pause`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: job-level
|
||||
|
||||
Pause a running or pending job. The worker will skip this job during polling until resumed.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `uuid` | string | Job UUID (file_uuid) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/jobs/$JOB_UUID/pause" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Job 3a6c1865... paused",
|
||||
"uuid": "3a6c1865..."
|
||||
}
|
||||
```
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | Job not found |
|
||||
| `400` | Job already completed or failed |
|
||||
| `401` | Missing or invalid API key |
|
||||
|
||||
**Note**: Cannot pause jobs with status `completed` or `failed`.
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/jobs/:uuid/resume`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: job-level
|
||||
|
||||
Resume a paused job. The job will be picked up by the worker in the next polling cycle.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `uuid` | string | Job UUID (file_uuid) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/jobs/$JOB_UUID/resume" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Job 3a6c1865... resumed",
|
||||
"uuid": "3a6c1865..."
|
||||
}
|
||||
```
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | Job not found |
|
||||
| `401` | Missing or invalid API key |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/jobs/paused`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: user-level
|
||||
|
||||
List all currently paused jobs with file names and pause timestamps.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/jobs/paused" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"jobs": [
|
||||
{
|
||||
"uuid": "3a6c1865...",
|
||||
"file_name": "video1.mp4",
|
||||
"status": "paused",
|
||||
"paused_at": "2026-10-25T10:30:00Z"
|
||||
},
|
||||
{
|
||||
"uuid": "4b7d2976...",
|
||||
"file_name": "video2.mp4",
|
||||
"status": "paused",
|
||||
"paused_at": "2026-10-25T11:15:00Z"
|
||||
}
|
||||
],
|
||||
"total": 2
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `jobs` | array | Array of paused job objects |
|
||||
| `uuid` | string | Job UUID (file_uuid) |
|
||||
| `file_name` | string | Original file name |
|
||||
| `status` | string | Always `"paused"` |
|
||||
| `paused_at` | string \| null | ISO 8601 timestamp when paused |
|
||||
| `total` | integer | Total number of paused jobs |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/jobs/:uuid/status`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: job-level
|
||||
|
||||
Get the current status of a specific job. Returns detailed status including processor progress.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `uuid` | string | Job UUID (file_uuid) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/jobs/$JOB_UUID/status" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"uuid": "3a6c1865...",
|
||||
"status": "paused",
|
||||
"current_processor": "face",
|
||||
"progress_current": 1500,
|
||||
"progress_total": 2892,
|
||||
"created_at": "2026-10-25T09:00:00Z",
|
||||
"started_at": "2026-10-25T09:05:00Z",
|
||||
"paused_at": "2026-10-25T10:30:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `uuid` | string | Job UUID |
|
||||
| `status` | string | Current status (pending, running, paused, completed, failed) |
|
||||
| `current_processor` | string \| null | Currently running processor |
|
||||
| `progress_current` | integer | Current progress value |
|
||||
| `progress_total` | integer | Total progress units |
|
||||
| `created_at` | string | Job creation timestamp |
|
||||
| `started_at` | string \| null | Job start timestamp |
|
||||
| `paused_at` | string \| null | Pause timestamp (if paused) |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/admin/sync-status`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: admin-level
|
||||
|
||||
Synchronize job statuses between database and Redis. Used for maintenance and consistency checks.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/admin/sync-status" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Status sync completed",
|
||||
"synced_count": 15
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Job Status Lifecycle
|
||||
|
||||
```
|
||||
pending → running → completed
|
||||
↓ ↓
|
||||
paused failed
|
||||
↓
|
||||
pending (resumed)
|
||||
```
|
||||
|
||||
| Status | Description | Actions Available |
|
||||
|--------|-------------|-------------------|
|
||||
| `pending` | Waiting in queue | Pause |
|
||||
| `running` | Currently processing | Pause |
|
||||
| `paused` | Paused by user | Resume |
|
||||
| `completed` | Finished successfully | None |
|
||||
| `failed` | Error occurred | None |
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. Pause Heavy Processing Job
|
||||
|
||||
```bash
|
||||
# Pause a running job to free up resources
|
||||
curl -X POST "$API/api/v1/jobs/$UUID/pause" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
### 2. Resume Previously Paused Job
|
||||
|
||||
```bash
|
||||
# Resume a paused job
|
||||
curl -X POST "$API/api/v1/jobs/$UUID/resume" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
### 3. List All Paused Jobs
|
||||
|
||||
```bash
|
||||
# Get all paused jobs
|
||||
curl -s "$API/api/v1/jobs/paused" -H "X-API-Key: $KEY" | jq '.jobs[]'
|
||||
```
|
||||
|
||||
### 4. Check Job Status
|
||||
|
||||
```bash
|
||||
# Check if a job is paused or running
|
||||
curl -s "$API/api/v1/jobs/$UUID/status" -H "X-API-Key: $KEY" | jq '.status'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
- **Redis Set**: Paused job UUIDs are stored in a Redis set (`jobs:paused`)
|
||||
- **Worker Behavior**: Worker checks Redis set before picking up jobs
|
||||
- **Persistence**: Pause state persists in both database and Redis
|
||||
- **Resume Priority**: Resumed jobs enter the queue with normal priority
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-25 | Initial documentation |
|
||||
@@ -0,0 +1,228 @@
|
||||
---
|
||||
title: Checkin API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-25
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: checkin -->
|
||||
<!-- description: Workspace checkin/checkout for file isolation -->
|
||||
<!-- depends: 01_auth, 03_register, 16_workspace -->
|
||||
|
||||
## Workspace Checkin/Checkout
|
||||
|
||||
Manage isolated workspace databases for files. Allows safe concurrent processing without conflicts.
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/checkin`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Check in a file from its isolated workspace database to the main database. Moves pre-chunks, speaker detections, and vectors from workspace to main tables.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `file_uuid` | string | File UUID (32-char hex) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/checkin" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3a6c1865...",
|
||||
"pre_chunks_moved": 152,
|
||||
"speaker_detections_moved": 45,
|
||||
"vectors_moved": 152,
|
||||
"status": "completed"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | File UUID |
|
||||
| `pre_chunks_moved` | integer | Number of pre-chunks moved |
|
||||
| `speaker_detections_moved` | integer | Number of speaker detections moved |
|
||||
| `vectors_moved` | integer | Number of vectors moved |
|
||||
| `status` | string | Always `"completed"` |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `401` | Missing or invalid API key |
|
||||
| `500` | Checkin failed (database error) |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/checkout`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Check out a file from the main database. Deletes workspace data for the file.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `file_uuid` | string | File UUID (32-char hex) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/checkout" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3a6c1865...",
|
||||
"rows_deleted": 197,
|
||||
"status": "checked_out"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | File UUID |
|
||||
| `rows_deleted` | integer | Total rows deleted from workspace |
|
||||
| `status` | string | Always `"checked_out"` |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/workspace`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Check if a workspace database exists for a file.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `file_uuid` | string | File UUID (32-char hex) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/workspace" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3a6c1865...",
|
||||
"exists": true
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | File UUID |
|
||||
| `exists` | boolean | Whether workspace database exists |
|
||||
|
||||
---
|
||||
|
||||
## Workspace Architecture
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────┐
|
||||
│ Main Database │
|
||||
│ (PostgreSQL + Qdrant vectors) │
|
||||
│ │
|
||||
│ videos, identities, chunk, ... │
|
||||
└─────────────────────────────────────────┘
|
||||
↑ checkin
|
||||
↓ checkout
|
||||
┌─────────────────────────────────────────┐
|
||||
│ Isolated Workspace Database │
|
||||
│ (SQLite per file) │
|
||||
│ │
|
||||
│ pre_chunks, speaker_detections │
|
||||
│ vectors (Qdrant _workspace collection) │
|
||||
└─────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### Workspace Benefits
|
||||
|
||||
1. **Concurrent Processing**: Multiple files can be processed simultaneously without lock conflicts
|
||||
2. **Isolation**: Processing errors don't affect main database
|
||||
3. **Rollback**: Failed processing can be discarded without cleanup
|
||||
4. **Performance**: SQLite workspace is faster for bulk inserts
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. Complete Processing and Check In
|
||||
|
||||
```bash
|
||||
# After processing completes successfully
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/checkin" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
### 2. Discard Failed Processing
|
||||
|
||||
```bash
|
||||
# If processing failed, checkout to clean up
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/checkout" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
### 3. Check Workspace Status
|
||||
|
||||
```bash
|
||||
# Before checkin, verify workspace exists
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/workspace" -H "X-API-Key: $KEY" | jq '.exists'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Workflow
|
||||
|
||||
### Normal Processing Flow
|
||||
|
||||
```
|
||||
1. Register file → status: REGISTERED
|
||||
2. Start processing → workspace created → status: PROCESSING
|
||||
3. Processing complete → workspace populated
|
||||
4. Checkin → move to main DB → status: COMPLETED
|
||||
5. Workspace deleted automatically
|
||||
```
|
||||
|
||||
### Error Recovery Flow
|
||||
|
||||
```
|
||||
1. Processing failed → workspace contains partial data
|
||||
2. Checkout → delete workspace → status: COMPLETED
|
||||
3. Re-trigger processing if needed
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
- **Workspace Location**: `{output_dir}/{file_uuid}.workspace.db`
|
||||
- **Vector Collection**: `qdrant://_workspace_{file_uuid}`
|
||||
- **Auto-cleanup**: Workspace deleted after successful checkin
|
||||
- **Idempotency**: Checkin/checkout can be called multiple times safely
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-25 | Initial documentation |
|
||||
@@ -0,0 +1,390 @@
|
||||
---
|
||||
title: search API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: search -->
|
||||
<!-- description: Vector search, BM25, smart search, universal search, LLM reranked search, frame search -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## Search APIs
|
||||
|
||||
### `POST /api/v1/search/smart`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: global / file-level
|
||||
|
||||
Semantic vector search using EmbeddingGemma-300m. Generates a query embedding via EmbeddingGemma (port 11436), then searches pgvector `story_parent` and `llm_parent` chunks by cosine similarity.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `query` | string | Yes | — | Search text |
|
||||
| `file_uuid` | string | No | — | File UUID to search within. If omitted, searches all files (global search) |
|
||||
| `limit` | integer | No | 5 | Max results to return |
|
||||
| `page` | integer | No | 1 | Page number |
|
||||
| `page_size` | integer | No | 5 | Items per page |
|
||||
|
||||
#### Example (Global Search)
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/search/smart" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $JWT" \
|
||||
-d '{"query": "Audrey Hepburn"}'
|
||||
```
|
||||
|
||||
#### Example (File-specific Search)
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/search/smart" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $JWT" \
|
||||
-d '{"file_uuid": "'"$FILE_UUID"'", "query": "Audrey Hepburn"}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"query": "Audrey Hepburn",
|
||||
"results": [
|
||||
{
|
||||
"file_uuid": "a6fb22eebefaef17e62af874997c5944",
|
||||
"parent_id": 1087822,
|
||||
"scene_order": 1087822,
|
||||
"start_frame": 104438,
|
||||
"end_frame": 104538,
|
||||
"fps": 24.0,
|
||||
"start_time": 4351.6,
|
||||
"end_time": 4355.76,
|
||||
"summary": "[4352s-4356s, 4s] Cast: Audrey Hepburn. Total: 2 lines, 10 words. Speakers: Audrey Hepburn (2 lines)",
|
||||
"similarity": 0.67
|
||||
}
|
||||
],
|
||||
"page": 1,
|
||||
"page_size": 5,
|
||||
"strategy": "semantic_vector_search"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `results[].file_uuid` | string | File UUID where result was found |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/search/universal`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: global / file-level
|
||||
|
||||
Multi-type BM25 full-text search across chunks, frames, and persons. Uses PostgreSQL `tsvector`.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `query` | string | Yes | — | Search text |
|
||||
| `file_uuid` | string | No | — | Restrict to specific file. If omitted, searches all files (global search) |
|
||||
| `types` | string[] | No | `["chunk","frame","person"]` | Search types |
|
||||
| `limit` | integer | No | 10 | Max results per type |
|
||||
| `page` | integer | No | 1 | Page number |
|
||||
| `page_size` | integer | No | 20 | Items per page |
|
||||
|
||||
#### Example (Global Search)
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/search/universal" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $JWT" \
|
||||
-d '{"query": "Cary Grant"}'
|
||||
```
|
||||
|
||||
#### Example (File-specific Search)
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/search/universal" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $JWT" \
|
||||
-d '{"file_uuid": "'"$FILE_UUID"'", "query": "Cary Grant"}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"type": "chunk",
|
||||
"file_uuid": "a6fb22eebefaef17e62af874997c5944",
|
||||
"chunk_id": "bd80fec92b0b6963d177a2c55bf713e2_2",
|
||||
"chunk_type": "story_child",
|
||||
"start_frame": 5103,
|
||||
"end_frame": 5127,
|
||||
"start_time": 212.64,
|
||||
"end_time": 213.64,
|
||||
"text": "[213s-214s] Cary Grant: \"Olá!\"",
|
||||
"score": 0.9
|
||||
},
|
||||
{
|
||||
"type": "frame",
|
||||
"file_uuid": "a6fb22eebefaef17e62af874997c5944",
|
||||
"frame_number": 5105,
|
||||
"timestamp": 212.72,
|
||||
"score": 0.7,
|
||||
"objects": null,
|
||||
"ocr_texts": null,
|
||||
"faces": null
|
||||
},
|
||||
{
|
||||
"type": "person",
|
||||
"file_uuid": "a6fb22eebefaef17e62af874997c5944",
|
||||
"identity_id": 12,
|
||||
"identity_uuid": "a9a901056d6b46ff92da0c3c1a57dff4",
|
||||
"name": "Cary Grant",
|
||||
"appearance_count": 542,
|
||||
"score": 0.95
|
||||
}
|
||||
],
|
||||
"total": 20,
|
||||
"took_ms": 18
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `results[].type` | string | Result type: `chunk`, `frame`, or `person` |
|
||||
| `results[].file_uuid` | string | File UUID where result was found (all types) |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/search/frames`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: global / file-level
|
||||
|
||||
Search frames by YOLO objects, OCR text, face IDs, or pose detections. Filters frames based on visual content detected during processing.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `file_uuid` | string | No | — | Restrict to specific file |
|
||||
| `object_class` | string | No | — | Filter by YOLO object class (e.g., `person`, `car`, `dog`) |
|
||||
| `ocr_text` | string | No | — | Filter by OCR text content (ILIKE match) |
|
||||
| `face_id` | string | No | — | Filter by face detection ID |
|
||||
| `time_range` | [float, float] | No | — | Filter by time range `[start_secs, end_secs]` |
|
||||
| `limit` | integer | No | 100 | Max results |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Search for frames containing "person" objects
|
||||
curl -s -X POST "$API/api/v1/search/frames" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"file_uuid": "'"$FILE_UUID"'", "object_class": "person", "limit": 20}'
|
||||
|
||||
# Search for frames with specific OCR text
|
||||
curl -s -X POST "$API/api/v1/search/frames" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"file_uuid": "'"$FILE_UUID"'", "ocr_text": "hello", "time_range": [10.0, 30.0]}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"frames": [
|
||||
{
|
||||
"frame_number": 1200,
|
||||
"timestamp": 50.0,
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"objects": [{"class": "person", "confidence": 0.95, "bbox": [100, 50, 300, 400]}],
|
||||
"ocr_texts": ["Hello World"],
|
||||
"faces": [{"face_id": "face_42", "confidence": 0.88}],
|
||||
"pose_persons": [{"trace_id": 2, "bbox": [120, 60, 280, 380]}]
|
||||
}
|
||||
],
|
||||
"total": 15
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `frames` | array | Array of matching frame objects |
|
||||
| `frames[].frame_number` | integer | Frame number in video |
|
||||
| `frames[].timestamp` | float | Timestamp in seconds |
|
||||
| `frames[].file_uuid` | string | File UUID |
|
||||
| `frames[].objects` | array/null | YOLO detections in this frame |
|
||||
| `frames[].ocr_texts` | array/null | OCR text strings in this frame |
|
||||
| `frames[].faces` | array/null | Face detections in this frame |
|
||||
| `frames[].pose_persons` | array/null | Pose-detected persons in this frame |
|
||||
| `total` | integer | Total matching frame count |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/search/llm-smart`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: global / file-level
|
||||
|
||||
Smart search with LLM re-ranking. First fetches candidate results via RRF (Reciprocal Rank Fusion) using the existing smart search, then uses an LLM (Gemma4 on port 8000) to re-rank candidates by relevance to the query.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `query` | string | Yes | — | Search text |
|
||||
| `file_uuid` | string | No | — | File UUID to search within |
|
||||
| `limit` | integer | No | 10 | Max results to return |
|
||||
|
||||
#### Pipeline
|
||||
|
||||
```
|
||||
1. smart_search → fetch N candidates (limit × 3, clamped 10-20)
|
||||
2. LLM rerank → re-order by relevance using Gemma4
|
||||
3. trim → return top `limit` results
|
||||
```
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/search/llm-smart" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"query": "two people having a conversation about business", "limit": 5}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"query": "two people having a conversation about business",
|
||||
"results": [
|
||||
{
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"parent_id": 1234,
|
||||
"scene_order": 1234,
|
||||
"start_frame": 5000,
|
||||
"end_frame": 5200,
|
||||
"fps": 24.0,
|
||||
"start_time": 208.3,
|
||||
"end_time": 216.7,
|
||||
"summary": "[208s-217s, 9s] Two people discussing project timeline...",
|
||||
"similarity": 0.72
|
||||
}
|
||||
],
|
||||
"page": 1,
|
||||
"page_size": 5,
|
||||
"strategy": "llm_reranked"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `strategy` | string | Always `"llm_reranked"` for this endpoint |
|
||||
| `results` | array | Re-ranked search results (same format as smart search) |
|
||||
|
||||
#### Fallback
|
||||
|
||||
If LLM reranking fails (model unavailable, timeout), falls back to RRF order without error.
|
||||
|
||||
---
|
||||
|
||||
### Visual Search
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: global / file-level
|
||||
|
||||
Search text chunks → find associated identities. Returns chunks where face detections overlap with text content.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `q` | string | Yes | — | Search text (ILIKE match) |
|
||||
| `file_uuid` | string | No | — | Restrict to specific file. If omitted, searches all files (global search) |
|
||||
| `limit` | integer | No | 50 | Max results |
|
||||
| `page` | integer | No | 1 | Page number |
|
||||
| `page_size` | integer | No | 50 | Items per page |
|
||||
|
||||
#### Example (Global Search)
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/search/identity_text?q=love" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Example (File-specific Search)
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/search/identity_text?file_uuid=$FILE_UUID&q=love" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"total": 5,
|
||||
"results": [
|
||||
{
|
||||
"file_uuid": "a6fb22eebefaef17e62af874997c5944",
|
||||
"chunk_id": "llm_parent_..._256_270",
|
||||
"start_time": 256.256,
|
||||
"end_time": 270.228,
|
||||
"text_content": "...lack of affection...",
|
||||
"identity_id": 9,
|
||||
"identity_name": "Audrey Hepburn",
|
||||
"identity_source": "tmdb",
|
||||
"trace_id": 94
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `results[].file_uuid` | string | File UUID where chunk was found |
|
||||
| `results[].identity_id` | integer | Identity ID if face was detected |
|
||||
| `results[].trace_id` | integer | Face trace ID |
|
||||
|
||||
---
|
||||
|
||||
### Visual Search (Planned)
|
||||
|
||||
| Method | Endpoint | Status | Description |
|
||||
|--------|----------|--------|-------------|
|
||||
| POST | `/api/v1/search/visual` | Not implemented | Search visual chunks |
|
||||
| POST | `/api/v1/search/visual/class` | Not implemented | Search by object class |
|
||||
| POST | `/api/v1/search/visual/density` | Not implemented | Search by object density |
|
||||
| POST | `/api/v1/search/visual/combination` | Not implemented | Search by object combination |
|
||||
| POST | `/api/v1/search/visual/stats` | Not implemented | Visual chunk statistics |
|
||||
|
||||
#### Embedding Model
|
||||
|
||||
| Detail | Value |
|
||||
|--------|-------|
|
||||
| **Model** | EmbeddingGemma-300m |
|
||||
| **Endpoint** | `POST /api/v1/embeddings` on port 11436 |
|
||||
| **Dimension** | 768 |
|
||||
| **Storage** | pgvector (`chunk.embedding` column) |
|
||||
|
||||
---
|
||||
*Updated: 2026-06-20 — Added llm-smart search, completed frames search documentation, marked visual search as planned*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,385 @@
|
||||
---
|
||||
title: VLM Search API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: vlm_search -->
|
||||
<!-- description: Vision Language Model search for scenes and traces -->
|
||||
<!-- depends: search, profile -->
|
||||
|
||||
# VLM Search API
|
||||
|
||||
Search video scenes and traces using Vision Language Model (VLM) descriptions and tags.
|
||||
|
||||
## Overview
|
||||
|
||||
VLM Search API provides endpoints for searching video scenes and face traces using Vision Language Model (VLM) descriptions and vector embeddings.
|
||||
|
||||
### VLM Dual-Source Architecture
|
||||
|
||||
VLM processing analyzes **two distinct sources**, each producing separate Qdrant collections for semantic vector search:
|
||||
|
||||
| VLM Source | Analysis Target | Qdrant Collection | Search Endpoint |
|
||||
|------------|-----------------|-------------------|-----------------|
|
||||
| **Scene VLM** | 10-second scene frames | `_scenes` | `POST /api/v1/search/vlm/scenes` |
|
||||
| **Trace VLM** | Face trace FS keyframes | `_vlm` | `POST /api/v1/search/vlm/traces` |
|
||||
|
||||
Both use **EmbeddingGemma-300m** (768D vectors) and **cosine similarity** for semantic search.
|
||||
|
||||
### VLM Data Flow
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ VLM Processing │
|
||||
├──────────────────────────┬──────────────────────────────────────┤
|
||||
│ Scene VLM │ Trace VLM │
|
||||
│ - Analyzes 10s scenes │ - Analyzes face trace FS keyframes │
|
||||
│ - Generates descriptions │ - Generates person descriptions │
|
||||
│ - Embeds to Qdrant │ - Embeds to Qdrant │
|
||||
│ `_scenes` collection │ `_vlm` collection │
|
||||
└──────────────────────────┴──────────────────────────────────────┘
|
||||
│ │
|
||||
└──────────────┬───────────────────────┘
|
||||
▼
|
||||
Qdrant Vector Search
|
||||
(Cosine similarity on 768D embeddings)
|
||||
```
|
||||
|
||||
### Implementation Files
|
||||
|
||||
- **Scene VLM**: `/Users/accusys/momentry_core/src/core/processor/scene_vlm.rs`
|
||||
- **Trace VLM**: `/Users/accusys/momentry_core/src/core/processor/vlm_summary.rs`
|
||||
- **Qdrant Upsert**: `/Users/accusys/momentry_core/src/core/db/qdrant_db.rs`
|
||||
- `upsert_scene_embedding()` → `_scenes` collection
|
||||
- `upsert_vlm_embedding()` → `_vlm` collection
|
||||
- **Search Endpoints**: `/Users/accusys/momentry_core/src/api/vlm_search.rs`
|
||||
|
||||
## Endpoints
|
||||
|
||||
### `POST /api/v1/search/vlm/scenes`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level or global
|
||||
|
||||
Search scenes using VLM-generated content and metadata.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `query` | string | Yes | — | Search query text |
|
||||
| `file_uuid` | string | No | — | Limit to specific file |
|
||||
| `filters` | object | No | — | Search filters |
|
||||
| `page` | number | No | 1 | Page number |
|
||||
| `page_size` | number | No | 20 | Results per page |
|
||||
| `min_score` | number | No | 0.0 | Minimum relevance score |
|
||||
|
||||
#### Filters Object
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `vlm_objects` | array | Filter by detected objects |
|
||||
| `vlm_tags` | array | Filter by VLM tags |
|
||||
| `time_range` | object | Filter by time range |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Search scenes for "dog playing"
|
||||
curl -s -X POST "$API/api/v1/search/vlm/scenes" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"query": "dog playing in the park",
|
||||
"page": 1,
|
||||
"page_size": 20,
|
||||
"min_score": 0.5
|
||||
}'
|
||||
```
|
||||
|
||||
```bash
|
||||
# Search scenes with filters
|
||||
curl -s -X POST "$API/api/v1/search/vlm/scenes" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"query": "outdoor scene",
|
||||
"file_uuid": "384b0ff44aaaa1f1",
|
||||
"filters": {
|
||||
"vlm_objects": ["dog", "tree"],
|
||||
"time_range": {
|
||||
"start_sec": 60.0,
|
||||
"end_sec": 120.0
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"file_uuid": "384b0ff44aaaa1f1",
|
||||
"file_name": "video.mp4",
|
||||
"scene_index": 5,
|
||||
"timestamp_sec": 125.5,
|
||||
"frame_number": 3750,
|
||||
"thumbnail_url": "/api/v1/media/384b0ff44aaaa1f1/scene/5/thumbnail",
|
||||
"vlm_description": "A dog playing in a sunny park",
|
||||
"vlm_description_localized": "陽光下的公園裡有隻狗在玩耍",
|
||||
"vlm_objects": ["dog", "grass", "tree", "park"],
|
||||
"vlm_tags": [
|
||||
{"en": "dog", "local": "犬"},
|
||||
{"en": "outdoor", "local": "戶外"},
|
||||
{"en": "sunny", "local": "晴天"}
|
||||
],
|
||||
"score": 0.92,
|
||||
"source": "vlm"
|
||||
}
|
||||
],
|
||||
"total": 15,
|
||||
"page": 1,
|
||||
"page_size": 20
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `results` | array | Search results |
|
||||
| `results[].file_uuid` | string | File UUID |
|
||||
| `results[].file_name` | string | File name |
|
||||
| `results[].scene_index` | number | Scene index |
|
||||
| `results[].timestamp_sec` | number | Scene timestamp |
|
||||
| `results[].frame_number` | number | Frame number |
|
||||
| `results[].thumbnail_url` | string | Thumbnail URL |
|
||||
| `results[].vlm_description` | string | VLM-generated description |
|
||||
| `results[].vlm_description_localized` | string | Localized description (optional) |
|
||||
| `results[].vlm_objects` | array | Detected objects |
|
||||
| `results[].vlm_tags` | array | VLM tags (bilingual) |
|
||||
| `results[].score` | number | Relevance score (0-1) |
|
||||
| `results[].source` | string | Search source (`"vlm"`) |
|
||||
| `total` | number | Total results |
|
||||
| `page` | number | Current page |
|
||||
| `page_size` | number | Page size |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/search/vlm/traces`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level or global
|
||||
|
||||
Search face traces using VLM descriptions.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `query` | string | Yes | — | Search query text |
|
||||
| `file_uuid` | string | No | — | Limit to specific file |
|
||||
| `filters` | object | No | — | Search filters |
|
||||
| `page` | number | No | 1 | Page number |
|
||||
| `page_size` | number | No | 20 | Results per page |
|
||||
| `min_score` | number | No | 0.0 | Minimum relevance score |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Search traces for "person wearing red shirt"
|
||||
curl -s -X POST "$API/api/v1/search/vlm/traces" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"query": "person wearing red shirt",
|
||||
"page": 1,
|
||||
"page_size": 20
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"file_uuid": "384b0ff44aaaa1f1",
|
||||
"trace_id": 2,
|
||||
"identity_uuid": "a9a90105-...",
|
||||
"vlm_description": "A person wearing a red t-shirt and blue jeans",
|
||||
"vlm_tags": [
|
||||
{"en": "red shirt", "local": "紅色上衣"},
|
||||
{"en": "blue jeans", "local": "藍色牛仔褲"}
|
||||
],
|
||||
"score": 0.88
|
||||
}
|
||||
],
|
||||
"total": 3,
|
||||
"page": 1,
|
||||
"page_size": 20
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/search/vlm/debug`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: system-level
|
||||
|
||||
Debug VLM search functionality (for development).
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Debug VLM search
|
||||
curl -s -X POST "$API/api/v1/search/vlm/debug" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"query": "test query"
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Implementation Details
|
||||
|
||||
**File**: `/Users/accusys/momentry_core/src/api/vlm_search.rs` (773 lines)
|
||||
|
||||
**Data Structures**:
|
||||
- `SceneSearchRequest` - Scene search parameters
|
||||
- `TraceSearchRequest` - Trace search parameters
|
||||
- `VlmTagValue` - Bilingual tag structure
|
||||
|
||||
**VLM Tags Structure**:
|
||||
```json
|
||||
{
|
||||
"en": "dog",
|
||||
"local": "犬"
|
||||
}
|
||||
```
|
||||
|
||||
**Search Process**:
|
||||
1. Parse query and filters
|
||||
2. Generate embedding for query text
|
||||
3. Search Qdrant for matching scenes/traces
|
||||
4. Apply filters (objects, tags, time range)
|
||||
5. Sort by relevance score
|
||||
6. Return paginated results
|
||||
|
||||
---
|
||||
|
||||
## VLM Integration
|
||||
|
||||
### Description Generation
|
||||
|
||||
VLM descriptions are generated during file processing:
|
||||
- **Scene VLM**: Analyzes scene frames
|
||||
- **Trace VLM**: Analyzes face trace appearances
|
||||
|
||||
### Tag Structure
|
||||
|
||||
Bilingual tags enable multilingual search:
|
||||
- **English tag**: Primary search key
|
||||
- **Local tag**: Native language display
|
||||
|
||||
### Objects vs Tags
|
||||
|
||||
- **Objects**: Detected physical objects (dog, car, tree)
|
||||
- **Tags**: Semantic concepts (outdoor, sunny, daytime)
|
||||
|
||||
---
|
||||
|
||||
## Search Tips
|
||||
|
||||
### Effective Queries
|
||||
|
||||
✅ **Good**:
|
||||
- "dog playing in the park"
|
||||
- "person wearing red shirt"
|
||||
- "outdoor sunny scene"
|
||||
|
||||
❌ **Less Effective**:
|
||||
- "video" (too generic)
|
||||
- "frame 100" (technical reference)
|
||||
|
||||
### Filter Usage
|
||||
|
||||
Use filters to narrow results:
|
||||
- `vlm_objects`: Specific objects
|
||||
- `vlm_tags`: Specific concepts
|
||||
- `time_range`: Specific time period
|
||||
|
||||
### Score Thresholds
|
||||
|
||||
- `> 0.8`: Highly relevant
|
||||
- `0.5-0.8`: Moderately relevant
|
||||
- `< 0.5`: Low relevance
|
||||
|
||||
---
|
||||
|
||||
## Error Codes
|
||||
|
||||
| Code | HTTP | When |
|
||||
|------|------|------|
|
||||
| E401 | 401 | Missing or invalid API key |
|
||||
| E400 | 400 | Invalid query or parameters |
|
||||
| E500 | 500 | Search failed |
|
||||
|
||||
---
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- [Search API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/06_search.md)
|
||||
- [Profile API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/18_profile.md)
|
||||
- [Scene VLM Stats](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/scene_vlm_stats_api.md)
|
||||
|
||||
---
|
||||
|
||||
## Common Issues
|
||||
|
||||
### No Results Found
|
||||
|
||||
**Symptoms**: Empty results array
|
||||
|
||||
**Possible Causes**:
|
||||
1. Query too specific
|
||||
2. Low `min_score` threshold
|
||||
3. No matching scenes/traces
|
||||
|
||||
**Solution**:
|
||||
- Simplify query
|
||||
- Lower `min_score`
|
||||
- Check file processing status
|
||||
|
||||
### Low Relevance Scores
|
||||
|
||||
**Symptoms**: All results have low scores (< 0.5)
|
||||
|
||||
**Possible Causes**:
|
||||
1. Query doesn't match content
|
||||
2. VLM descriptions not generated
|
||||
3. Embedding quality issue
|
||||
|
||||
**Solution**:
|
||||
- Rephrase query
|
||||
- Verify VLM processing completed
|
||||
- Check VLM model configuration
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,220 @@
|
||||
---
|
||||
title: Scene VLM Stats API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-14
|
||||
author: Core Team
|
||||
status: active
|
||||
---
|
||||
|
||||
# Scene VLM Stats API
|
||||
|
||||
**Endpoint**: `/api/v1/file/{file_uuid}/scene-vlm-stats`
|
||||
**Method**: `GET`
|
||||
**Purpose**: 快速获取文件的 Scene VLM 统计数据
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
**Scope**: File processing statistics
|
||||
**Status**: Active
|
||||
**Applicable to**: All registered files with Scene VLM processing
|
||||
|
||||
---
|
||||
|
||||
## Request
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Location | Required | Description |
|
||||
|-----------|------|----------|----------|-------------|
|
||||
| `file_uuid` | String | Path | Yes | File UUID |
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
curl http://localhost:3002/api/v1/file/dac75694ee550ff57d74f26391fcc751/scene-vlm-stats
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Response
|
||||
|
||||
### Success (200 OK)
|
||||
|
||||
```json
|
||||
{
|
||||
"total_scenes": 2,
|
||||
"status": "completed",
|
||||
"vlm_done": 2,
|
||||
"vlm_total": 2
|
||||
}
|
||||
```
|
||||
|
||||
### Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `total_scenes` | i64 | Total number of scenes detected |
|
||||
| `status` | String | Scene VLM processing status (`pending`, `processing`, `completed`) |
|
||||
| `vlm_done` | i64 | Number of scenes with VLM descriptions completed |
|
||||
| `vlm_total` | i64 | Total scenes needing VLM processing |
|
||||
|
||||
### Default Response
|
||||
|
||||
If the file has no scenes file:
|
||||
|
||||
```json
|
||||
{
|
||||
"total_scenes": 0,
|
||||
"status": "",
|
||||
"vlm_done": 0,
|
||||
"vlm_total": 0
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Performance
|
||||
|
||||
**Response Time**: < 10ms
|
||||
|
||||
**Why Fast**:
|
||||
- Directly reads `{file_uuid}.scenes.json`
|
||||
- No database queries
|
||||
- No complex calculations
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. UI Display
|
||||
|
||||
Display Scene VLM progress in Library view:
|
||||
```typescript
|
||||
const stats = await loadSceneVlmStats(fileUuid)
|
||||
console.log(`${stats.vlm_done}/${stats.vlm_total} scenes completed`)
|
||||
```
|
||||
|
||||
### 2. Performance Optimization
|
||||
|
||||
Replace expensive `get_file_stats` call:
|
||||
- **Old**: `get_file_stats` - 100-500ms
|
||||
- **New**: `scene-vlm-stats` - < 10ms
|
||||
- **Improvement**: 10-50x faster
|
||||
|
||||
### 3. Real-time Updates
|
||||
|
||||
Poll for Scene VLM progress without heavy API load:
|
||||
```typescript
|
||||
setInterval(() => {
|
||||
loadSceneVlmStats(fileUuid)
|
||||
}, 5000)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### Backend
|
||||
|
||||
**File**: `src/api/scan.rs:1647`
|
||||
|
||||
**Logic**:
|
||||
1. Check if `{file_uuid}.scenes.json` exists
|
||||
2. Read JSON file
|
||||
3. Parse and count scenes
|
||||
4. Return statistics
|
||||
|
||||
**Code**:
|
||||
```rust
|
||||
async fn get_scene_vlm_stats(
|
||||
Path(file_uuid): Path<String>,
|
||||
) -> Result<Json<SceneVlmStats>, StatusCode> {
|
||||
let scenes_path = format!("{}/{}.scenes.json", output_dir, file_uuid);
|
||||
|
||||
if !Path::new(&scenes_path).exists() {
|
||||
return Ok(Json(SceneVlmStats::default()));
|
||||
}
|
||||
|
||||
let scenes_json = std::fs::read_to_string(&scenes_path)?;
|
||||
let scenes_data: Value = serde_json::from_str(&scenes_json)?;
|
||||
|
||||
// ... parse and return stats
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
### File Not Found
|
||||
|
||||
**Status**: 200 OK
|
||||
**Response**: Default values (all zeros)
|
||||
|
||||
### Parse Error
|
||||
|
||||
**Status**: 500 Internal Server Error
|
||||
|
||||
**Note**: Rare case, indicates corrupted JSON file
|
||||
|
||||
---
|
||||
|
||||
## Related APIs
|
||||
|
||||
- `GET /api/v1/file/{file_uuid}` - Full file info (slower)
|
||||
- `GET /api/v1/file/{file_uuid}/processor-counts` - Processor counts
|
||||
- `GET /api/v1/stats/file/{file_uuid}` - Detailed stats (slower)
|
||||
|
||||
---
|
||||
|
||||
## Best Practices
|
||||
|
||||
### 1. Use for Scene VLM Progress
|
||||
|
||||
**Recommended**: Use this API for Scene VLM progress display
|
||||
**Avoid**: Using `get_file_stats` for simple Scene VLM stats
|
||||
|
||||
### 2. Caching
|
||||
|
||||
Frontend should cache results:
|
||||
```typescript
|
||||
if (fileStatsCache.value[fileUuid].scene_vlm) {
|
||||
return fileStatsCache.value[fileUuid].scene_vlm
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Error Handling
|
||||
|
||||
Always handle failures gracefully:
|
||||
```typescript
|
||||
try {
|
||||
const stats = await loadSceneVlmStats(fileUuid)
|
||||
} catch (e) {
|
||||
console.warn('Scene VLM stats failed:', e)
|
||||
// Use cached data or show 'Unknown'
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0.0 | 2026-10-14 | Initial API endpoint |
|
||||
|
||||
---
|
||||
|
||||
## Cross-References
|
||||
|
||||
- **Frontend Integration**: Studio team commit 3e7eba0
|
||||
- **Test Script**: `momentry_studio/scripts/test_scene_vlm_api.sh`
|
||||
- **Backend Code**: `src/api/scan.rs:1647`
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: 2026-10-14
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
---
|
||||
title: identity agent API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: identity_agent -->
|
||||
<!-- description: Identity agent — match from photo, match from trace -->
|
||||
<!-- depends: 01_auth, 07_identity -->
|
||||
|
||||
## Identity Agent
|
||||
|
||||
### `POST /api/v1/agents/identity/match-from-photo`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Upload a face photo to match against known identities. Detects face via InsightFace, extracts 512D embedding via CoreML FaceNet, then searches pgvector for the closest identity.
|
||||
|
||||
#### Request
|
||||
|
||||
`multipart/form-data` with field `image` (JPEG/PNG) and optional `file_uuid`.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/agents/identity/match-from-photo" \
|
||||
-H "Authorization: Bearer $JWT" \
|
||||
-F "image=@/path/to/face.jpg" \
|
||||
-F "file_uuid=$FILE_UUID"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"matches": [
|
||||
{
|
||||
"identity_uuid": "a9a90105...",
|
||||
"name": "Cary Grant",
|
||||
"similarity": 0.87
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/agents/identity/match-from-trace`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Match a face trace (tracked face across frames) against known identities. Samples 3 angles from the trace, generates embeddings, and searches pgvector.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File containing the trace |
|
||||
| `trace_id` | integer | Yes | Face trace ID to match |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/agents/identity/match-from-trace" \
|
||||
-H "Authorization: Bearer $JWT" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"file_uuid": "'"$FILE_UUID"'", "trace_id": 10}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/agents/identity/confirm`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Confirm identity binding for a trace. This marks the trace as confirmed in TKG, updates face_detections, adds to _seeds, and optionally triggers Round 2 propagation.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | Video file UUID |
|
||||
| `trace_id` | integer | Yes | Face trace ID to confirm |
|
||||
| `identity_id` | integer | Yes | Identity internal ID |
|
||||
| `identity_uuid` | string | Yes | Identity UUID |
|
||||
| `name` | string | Yes | Identity name |
|
||||
| `propagate` | boolean | No | Auto-trigger Round 2 matching (default: true) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/agents/identity/confirm" \
|
||||
-H "Authorization: Bearer $JWT" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"file_uuid": "'"$FILE_UUID"'", "trace_id": 10, "identity_id": 42, "identity_uuid": "'"$IDENTITY_UUID"'", "name": "Cary Grant", "propagate": false}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "384b0ff44aaaa1f1",
|
||||
"trace_id": 10,
|
||||
"identity_uuid": "a9a90105...",
|
||||
"name": "Cary Grant",
|
||||
"steps": {
|
||||
"tkg_updated": true,
|
||||
"qdrant_updated": 150,
|
||||
"pg_updated": 150,
|
||||
"seed_added": true
|
||||
},
|
||||
"propagation": {
|
||||
"matched": 5,
|
||||
"message": "Propagation completed"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Side Effects
|
||||
|
||||
1. TKG face_track node status → 'confirmed'
|
||||
2. Qdrant _faces: identity_uuid added to payload
|
||||
3. PG face_detections: identity_id set
|
||||
4. Trace centroid added to _seeds (source='propagation')
|
||||
5. Round 2 matching triggered (if propagate=true)
|
||||
|
||||
---
|
||||
*Updated: 2026-06-26 00:30:00*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,714 @@
|
||||
---
|
||||
title: identity history API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: identity_history -->
|
||||
<!-- description: Identity operation history, undo, and redo (PATCH, bind, unbind, bind_trace, mergeinto) -->
|
||||
<!-- depends: 01_auth, 07_identity -->
|
||||
|
||||
## Identity Operation History
|
||||
|
||||
Every mutation on an identity automatically records a before/after snapshot. Use undo/redo to revert or reapply changes, and history to inspect the operation log.
|
||||
|
||||
Three independent undo/redo systems exist:
|
||||
|
||||
| System | Storage | Operations Covered |
|
||||
|--------|---------|-------------------|
|
||||
| **PATCH** | PostgreSQL `identity_history` | `update` |
|
||||
| **Bind** | PostgreSQL `identity_history` | `bind`, `unbind`, `bind_trace` |
|
||||
| **Merge** | MongoDB `identity_merge_history` | mergeinto |
|
||||
| **Delete** | PostgreSQL `identity_history` | `delete` |
|
||||
|
||||
---
|
||||
|
||||
### 1. PATCH History & Undo/Redo
|
||||
|
||||
#### Overview
|
||||
|
||||
| Property | Value |
|
||||
|----------|-------|
|
||||
| Storage | PostgreSQL `identity_history` table |
|
||||
| Snapshot | Full identity record (all fields) before and after each PATCH |
|
||||
| Max records | 256 per identity (oldest auto-deleted when limit exceeded) |
|
||||
| Undo steps | Unlimited (no expiry, no step limit) |
|
||||
| Redo stack | Cleared on new PATCH (`is_undone=true` + `operation='update'` records are deleted) |
|
||||
|
||||
##### Stack Model
|
||||
|
||||
```
|
||||
PATCH 1 → PATCH 2 → PATCH 3 (undo stack, is_undone=false)
|
||||
↓ undo
|
||||
PATCH 1 → PATCH 2 (undo stack)
|
||||
PATCH 3 (redo stack, is_undone=true)
|
||||
↓ redo
|
||||
PATCH 1 → PATCH 2 → PATCH 3 (undo stack)
|
||||
```
|
||||
|
||||
A new PATCH after undo clears only the operation='update' redo stack (PATCH 3 is lost). Bind/merge redo stacks are not affected.
|
||||
|
||||
---
|
||||
|
||||
#### `POST /api/v1/identity/:identity_uuid/undo`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: identity-level
|
||||
|
||||
Undo the most recent PATCH operations. Restores the identity's `before_snapshot` and marks the history records as undone.
|
||||
|
||||
##### Request (JSON)
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `steps` | integer | No | `1` | Number of undo steps to apply (max records undone in one call) |
|
||||
|
||||
##### Behavior
|
||||
|
||||
- Queries `is_undone=false` records with `operation='update'`, ordered by `created_at DESC`
|
||||
- Restores `name`, `identity_type`, `source`, `status`, `metadata`, `tmdb_id`, `tmdb_profile` from the last record's `before_snapshot`
|
||||
- Marks the undone records as `is_undone=true` with `undone_at=NOW()`
|
||||
- Syncs `identity.json` to disk
|
||||
- Updates `_index.json` if name changed
|
||||
|
||||
##### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/identity/$IDENTITY_UUID/undo" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"steps": 1}'
|
||||
```
|
||||
|
||||
##### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"identity_uuid": "a9a901056d6b46ff92da0c3c1a57dff4",
|
||||
"undone_count": 1,
|
||||
"current_state": {
|
||||
"id": 9,
|
||||
"uuid": "a9a901056d6b46ff92da0c3c1a57dff4",
|
||||
"name": "Cary Grant",
|
||||
"identity_type": "people",
|
||||
"source": "tmdb",
|
||||
"status": "confirmed",
|
||||
"metadata": {},
|
||||
"tmdb_id": 112,
|
||||
"tmdb_profile": null
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `undone_count` | integer | Number of history records undone |
|
||||
| `current_state` | object | Full identity state after undo |
|
||||
|
||||
##### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `400` | No undo operations available |
|
||||
| `404` | Identity not found |
|
||||
| `500` | Database error |
|
||||
|
||||
---
|
||||
|
||||
#### `POST /api/v1/identity/:identity_uuid/redo`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: identity-level
|
||||
|
||||
Redo previously undone PATCH operations. Restores the identity's `after_snapshot` and marks the history records as no longer undone.
|
||||
|
||||
##### Request (JSON)
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `steps` | integer | No | `1` | Number of redo steps to apply |
|
||||
|
||||
##### Behavior
|
||||
|
||||
- Queries `is_undone=true` records with `operation='update'`, ordered by `created_at DESC`
|
||||
- Restores all identity fields from the last record's `after_snapshot`
|
||||
- Marks records as `is_undone=false` with `undone_at=NULL`
|
||||
- Syncs `identity.json` to disk
|
||||
- Updates `_index.json` if name changed
|
||||
|
||||
##### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/identity/$IDENTITY_UUID/redo" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"steps": 1}'
|
||||
```
|
||||
|
||||
##### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"identity_uuid": "a9a901056d6b46ff92da0c3c1a57dff4",
|
||||
"redone_count": 1,
|
||||
"current_state": {
|
||||
"id": 9,
|
||||
"uuid": "a9a901056d6b46ff92da0c3c1a57dff4",
|
||||
"name": "John Smith",
|
||||
"identity_type": "people",
|
||||
"source": "tmdb",
|
||||
"status": "confirmed",
|
||||
"metadata": { "aliases": [...] },
|
||||
"tmdb_id": 112,
|
||||
"tmdb_profile": null
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `redone_count` | integer | Number of history records redone |
|
||||
| `current_state` | object | Full identity state after redo |
|
||||
|
||||
##### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `400` | No redo operations available |
|
||||
| `404` | Identity not found |
|
||||
| `500` | Database error |
|
||||
|
||||
---
|
||||
|
||||
#### `GET /api/v1/identity/:identity_uuid/history`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: identity-level
|
||||
|
||||
Query the PATCH operation history for an identity. Returns paginated records with undo/redo stack counts (filtered to `operation='update'`).
|
||||
|
||||
##### Query Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `page` | integer | No | `1` | Page number (1-indexed) |
|
||||
| `limit` | integer | No | `20` | Items per page (max 100) |
|
||||
|
||||
##### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"identity_uuid": "a9a901056d6b46ff92da0c3c1a57dff4",
|
||||
"total": 5,
|
||||
"undo_stack_count": 3,
|
||||
"redo_stack_count": 2,
|
||||
"results": [
|
||||
{
|
||||
"history_id": 42,
|
||||
"operation": "update",
|
||||
"is_undone": false,
|
||||
"created_at": "2026-05-27T12:00:00Z",
|
||||
"undone_at": null
|
||||
},
|
||||
{
|
||||
"history_id": 41,
|
||||
"operation": "update",
|
||||
"is_undone": true,
|
||||
"created_at": "2026-05-27T11:30:00Z",
|
||||
"undone_at": "2026-05-27T13:00:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `total` | integer | Total PATCH history records for this identity |
|
||||
| `undo_stack_count` | integer | Records available for undo (`is_undone=false`) |
|
||||
| `redo_stack_count` | integer | Records available for redo (`is_undone=true`) |
|
||||
| `results[].history_id` | integer | History record ID |
|
||||
| `results[].operation` | string | Operation type (`"update"` for PATCH) |
|
||||
| `results[].is_undone` | boolean | Whether the operation has been undone |
|
||||
| `results[].created_at` | string | When the PATCH was applied |
|
||||
| `results[].undone_at` | string | When the undo occurred (null if not undone) |
|
||||
|
||||
##### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/identity/$IDENTITY_UUID/history?page=1&limit=10" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
##### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | Identity not found |
|
||||
| `500` | Database error |
|
||||
|
||||
---
|
||||
|
||||
### 2. Bind/Unbind/Trace History & Undo/Redo
|
||||
|
||||
All three operations (`bind`, `unbind`, `bind_trace`) share a single history table and undo/redo stack.
|
||||
|
||||
#### Bind Operation Overview
|
||||
|
||||
| Property | Value |
|
||||
|----------|-------|
|
||||
| Storage | PostgreSQL `identity_history` table (same table as PATCH) |
|
||||
| Snapshot | `{"file_uuid", "face_id" (or "trace_id"), "identity_id_before/after"}` |
|
||||
| Max records | 256 per identity (shared limit across all operation types) |
|
||||
| Undo steps | Unlimited (`steps` param) |
|
||||
| Redo stack | Cleared on new bind/unbind/bind_trace (`operation IN ('bind','unbind','bind_trace')` + `is_undone=true` records deleted) |
|
||||
| Stack isolation | Bind redo stack is **independent** from PATCH redo stack — clearing one does not affect the other |
|
||||
|
||||
##### Stack Model
|
||||
|
||||
```
|
||||
bind face_1 (to id=9) → unbind face_1 → bind trace 906 (to id=9)
|
||||
(undo stack, is_undone=false) (undo stack) (undo stack)
|
||||
↓ undo (first undone: bind_trace)
|
||||
bind trace 906 (is_undone=true)
|
||||
(redo stack)
|
||||
↓ redo
|
||||
bind face_1 → unbind face_1 → bind trace 906
|
||||
(undo stack)
|
||||
```
|
||||
|
||||
A new bind/unbind/trace after undo clears only the bind redo stack (operations with `IN ('bind','unbind','bind_trace')`).
|
||||
|
||||
##### Snapshot Format
|
||||
|
||||
**Before (bind):**
|
||||
```json
|
||||
{
|
||||
"file_uuid": "aeed71342a899fe4b4c57b7d41bcb692",
|
||||
"face_id": "1_5",
|
||||
"identity_id_before": null
|
||||
}
|
||||
```
|
||||
|
||||
**After (bind):**
|
||||
```json
|
||||
{
|
||||
"file_uuid": "aeed71342a899fe4b4c57b7d41bcb692",
|
||||
"face_id": "1_5",
|
||||
"identity_id_after": 9
|
||||
}
|
||||
```
|
||||
|
||||
**Before (unbind) — binding existed before:**
|
||||
```json
|
||||
{
|
||||
"file_uuid": "aeed71342a899fe4b4c57b7d41bcb692",
|
||||
"face_id": "1_5",
|
||||
"identity_id_before": 9
|
||||
}
|
||||
```
|
||||
|
||||
**After (unbind):**
|
||||
```json
|
||||
{
|
||||
"file_uuid": "aeed71342a899fe4b4c57b7d41bcb692",
|
||||
"face_id": "1_5",
|
||||
"identity_id_after": null
|
||||
}
|
||||
```
|
||||
|
||||
For `bind_trace`, the snapshot uses `trace_id` instead of `face_id`, with `identity_id_before` capturing the first face's identity in that trace.
|
||||
|
||||
---
|
||||
|
||||
#### `POST /api/v1/identity/:identity_uuid/bind/undo`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: identity-level
|
||||
|
||||
Undo the most recent bind/unbind/bind_trace operations. Restores `identity_id_before` from the snapshot and marks records as undone.
|
||||
|
||||
##### Request (JSON)
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `steps` | integer | No | `1` | Number of undo steps to apply |
|
||||
|
||||
##### Behavior
|
||||
|
||||
- Queries `is_undone=false` records with `operation IN ('bind','unbind','bind_trace')`, ordered by `created_at DESC`
|
||||
- Restores `identity_id_before` — for bind this is `null` (face was unbound), for unbind this is the original identity (face goes back), for bind_trace this is the trace's previous identity
|
||||
- Marks the undone records as `is_undone=true` with `undone_at=NOW()`
|
||||
|
||||
##### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/identity/$IDENTITY_UUID/bind/undo" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"steps": 1}'
|
||||
```
|
||||
|
||||
##### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"identity_uuid": "a9a901056d6b46ff92da0c3c1a57dff4",
|
||||
"operation": "bind",
|
||||
"undone_count": 1,
|
||||
"affected_rows": 53
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `operation` | string | The actual operation undone (`bind`, `unbind`, or `bind_trace`) |
|
||||
| `undone_count` | integer | Number of history records undone |
|
||||
| `affected_rows` | integer | Number of `face_detections` rows updated |
|
||||
|
||||
##### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `400` | No bind undo operations available |
|
||||
| `404` | Identity not found |
|
||||
| `500` | Database error |
|
||||
|
||||
---
|
||||
|
||||
#### `POST /api/v1/identity/:identity_uuid/bind/redo`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: identity-level
|
||||
|
||||
Redo previously undone bind/unbind/bind_trace operations. Restores `identity_id_after` from the snapshot.
|
||||
|
||||
##### Request (JSON)
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `steps` | integer | No | `1` | Number of redo steps to apply |
|
||||
|
||||
##### Behavior
|
||||
|
||||
- Queries `is_undone=true` records with `operation IN ('bind','unbind','bind_trace')`, ordered by `created_at DESC`
|
||||
- Restores `identity_id_after` — for bind this is the identity the face was bound to, for unbind this is `null`
|
||||
- Marks records as `is_undone=false` with `undone_at=NULL`
|
||||
|
||||
##### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/identity/$IDENTITY_UUID/bind/redo" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"steps": 1}'
|
||||
```
|
||||
|
||||
##### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"identity_uuid": "a9a901056d6b46ff92da0c3c1a57dff4",
|
||||
"operation": "unbind",
|
||||
"redone_count": 1,
|
||||
"affected_rows": 1
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `operation` | string | The actual operation redone (`bind`, `unbind`, or `bind_trace`) |
|
||||
| `redone_count` | integer | Number of history records redone |
|
||||
| `affected_rows` | integer | Number of `face_detections` rows updated |
|
||||
|
||||
##### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `400` | No bind redo operations available |
|
||||
| `404` | Identity not found |
|
||||
| `500` | Database error |
|
||||
|
||||
---
|
||||
|
||||
#### `GET /api/v1/identity/:identity_uuid/bind/history`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: identity-level
|
||||
|
||||
Query the bind/unbind/bind_trace operation history for an identity. Returns paginated records with undo/redo stack counts.
|
||||
|
||||
##### Query Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `page` | integer | No | `1` | Page number (1-indexed) |
|
||||
| `limit` | integer | No | `20` | Items per page (max 100) |
|
||||
|
||||
##### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"identity_uuid": "a9a901056d6b46ff92da0c3c1a57dff4",
|
||||
"total": 3,
|
||||
"undo_stack_count": 2,
|
||||
"redo_stack_count": 1,
|
||||
"results": [
|
||||
{
|
||||
"history_id": 52,
|
||||
"operation": "bind_trace",
|
||||
"is_undone": false,
|
||||
"created_at": "2026-05-27T14:00:00Z",
|
||||
"undone_at": null
|
||||
},
|
||||
{
|
||||
"history_id": 51,
|
||||
"operation": "unbind",
|
||||
"is_undone": true,
|
||||
"created_at": "2026-05-27T13:00:00Z",
|
||||
"undone_at": "2026-05-27T14:30:00Z"
|
||||
},
|
||||
{
|
||||
"history_id": 50,
|
||||
"operation": "bind",
|
||||
"is_undone": false,
|
||||
"created_at": "2026-05-27T12:00:00Z",
|
||||
"undone_at": null
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `total` | integer | Total bind history records for this identity |
|
||||
| `undo_stack_count` | integer | Records available for undo (`is_undone=false`) |
|
||||
| `redo_stack_count` | integer | Records available for redo (`is_undone=true`) |
|
||||
| `results[].history_id` | integer | History record ID |
|
||||
| `results[].operation` | string | Operation type (`bind`, `unbind`, or `bind_trace`) |
|
||||
| `results[].is_undone` | boolean | Whether the operation has been undone |
|
||||
| `results[].created_at` | string | When the operation was applied |
|
||||
| `results[].undone_at` | string | When the undo occurred (null if not undone) |
|
||||
|
||||
##### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/identity/$IDENTITY_UUID/bind/history?page=1&limit=10" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
##### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | Identity not found |
|
||||
| `500` | Database error |
|
||||
|
||||
---
|
||||
|
||||
### 3. Merge History & Undo/Redo
|
||||
|
||||
Merge operations use MongoDB for richer record-keeping, with a 24-hour undo deadline.
|
||||
|
||||
#### Merge Operation Overview
|
||||
|
||||
| Property | Value |
|
||||
|----------|-------|
|
||||
| Storage | MongoDB `identity_merge_history` collection |
|
||||
| Snapshot | Full source identity state + target identity state + aliases/metadata diffs |
|
||||
| Trigger | Every mergeinto with `keep_history=true` |
|
||||
| Undo deadline | 24 hours (renewed on redo) |
|
||||
| Redo support | Yes — restores undone merges with new 24hr deadline |
|
||||
| Max records | Unlimited |
|
||||
|
||||
---
|
||||
|
||||
#### `POST /api/v1/identity/merge/:merge_id/undo`
|
||||
|
||||
Already documented in [`07_identity.md`](07_identity.md#post-apiv1identitymergemerge_idundo). See that document for full details.
|
||||
|
||||
---
|
||||
|
||||
#### `POST /api/v1/identity/merge/:merge_id/redo`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: identity-level
|
||||
|
||||
Redo a previously undone merge operation within the renewed 24-hour deadline.
|
||||
|
||||
##### Request
|
||||
|
||||
No body required. The merge ID is taken from the URL path.
|
||||
|
||||
##### Behavior
|
||||
|
||||
1. Validates the merge record exists and `undone=true` (not already active)
|
||||
2. Checks the 24-hour undo deadline (if expired, the redo is rejected)
|
||||
3. Restores face bindings: moves all faces from `target_identity` back to `source_identity`
|
||||
4. Re-adds aliases that were removed by the undo (aliases with `source: "merge"` tag)
|
||||
5. Re-adds metadata fields that were removed by the undo
|
||||
6. If `keep_history=true`: sets `source_identity.status = 'merged'` again
|
||||
7. If `keep_history=false`: recreates source identity from the `undone_snapshot` stored at undo time
|
||||
8. Syncs both identity JSON files to disk
|
||||
9. Sets `undone=false`, clears `undone_snapshot`, renews `undo_deadline = NOW() + 24h`
|
||||
10. Records `redone_by` user for audit
|
||||
|
||||
##### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/identity/merge/550e8400-e29b-41d4-a716-446655440000/redo" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
##### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Redo merge completed: merged 'stranger_13894' into 'Louis Viret' (52 faces transferred)",
|
||||
"data": {
|
||||
"merge_id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"faces_transferred": 52,
|
||||
"aliases_re_added": 1,
|
||||
"metadata_fields_re_added": 2
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `merge_id` | string | The merge operation ID |
|
||||
| `faces_transferred` | integer | Number of faces transferred from source to target |
|
||||
| `aliases_re_added` | integer | Number of aliases restored to target |
|
||||
| `metadata_fields_re_added` | integer | Number of metadata fields restored to target |
|
||||
|
||||
##### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `400` | Merge not undone, deadline expired, or cannot redo |
|
||||
| `404` | Merge record not found |
|
||||
| `500` | Database error |
|
||||
|
||||
---
|
||||
|
||||
### 4. Delete History & Undo/Redo
|
||||
|
||||
#### Delete Operation Overview
|
||||
|
||||
| Property | Value |
|
||||
|----------|-------|
|
||||
| Storage | PostgreSQL `identity_history` table |
|
||||
| Snapshot | `{"identity": {...full row...}, "unbound_faces": [{file_uuid, face_id, trace_id}, ...]}` |
|
||||
| Max records | 1 active delete record per identity (redo stack cleared on new delete) |
|
||||
| Undo support | Yes — recreates identity row, re-binds faces |
|
||||
| Redo support | Yes — re-deletes the identity |
|
||||
| Identity file | Deleted on delete, recreated on undo |
|
||||
|
||||
#### Snapshot Format
|
||||
|
||||
```json
|
||||
{
|
||||
"identity": {
|
||||
"id": 9,
|
||||
"uuid": "a9a90105-6d6b-46ff-92da-0c3c1a57dff4",
|
||||
"name": "Cary Grant",
|
||||
"identity_type": "people",
|
||||
"source": "tmdb",
|
||||
"status": "confirmed",
|
||||
"metadata": {},
|
||||
"tmdb_id": 112,
|
||||
"tmdb_profile": null
|
||||
},
|
||||
"unbound_faces": [
|
||||
{
|
||||
"file_uuid": "aeed71342a899fe4b4c57b7d41bcb692",
|
||||
"face_id": "1_5",
|
||||
"trace_id": null
|
||||
},
|
||||
{
|
||||
"file_uuid": "aeed71342a899fe4b4c57b7d41bcb692",
|
||||
"face_id": "1_6",
|
||||
"trace_id": 906
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Stack Model
|
||||
|
||||
```
|
||||
DELETE identity (undo stack, is_undone=false)
|
||||
↓ undo
|
||||
Identity recreated, faces re-bound
|
||||
→ delete history marked is_undone=true
|
||||
↓ redo (re-delete)
|
||||
Identity deleted again, faces unbound
|
||||
→ delete history marked is_undone=false
|
||||
```
|
||||
|
||||
A new delete after an undo clears the delete redo stack (no redo possible for the old delete).
|
||||
|
||||
#### Undo Behavior (via existing `POST /api/v1/identity/:identity_uuid/undo`)
|
||||
|
||||
1. Normal identity lookup fails (row was deleted)
|
||||
2. Checks `identity_history` for `operation='delete' AND is_undone=false` matching the UUID in the snapshot
|
||||
3. Recreates the identity row (new internal `id`, same UUID)
|
||||
4. Re-binds all faces listed in `unbound_faces` to the new identity
|
||||
5. Deletes the `identity_history` delete record as `is_undone=true` with `undone_at=NOW()`
|
||||
6. Syncs `identity.json` to disk
|
||||
7. Updates `_index.json`
|
||||
|
||||
#### Redo Behavior (via existing `POST /api/v1/identity/:identity_uuid/redo`)
|
||||
|
||||
1. Identity lookup succeeds (identity was restored by prior undo)
|
||||
2. Checks `identity_history` for `operation='delete' AND is_undone=true` matching the identity_id
|
||||
3. Deletes `identity.json` from disk
|
||||
4. Unbinds all faces (`identity_id = NULL`)
|
||||
5. Deletes the identity row
|
||||
6. Marks the delete history record as `is_undone=false`
|
||||
7. Returns success
|
||||
|
||||
#### Error Responses (delete undo/redo)
|
||||
|
||||
| HTTP | Scenario |
|
||||
|------|----------|
|
||||
| `400` | No delete history available (either no delete or already undone/redone) |
|
||||
| `404` | Identity not found (for redo — identity wasn't restored) |
|
||||
| `500` | Database error |
|
||||
|
||||
---
|
||||
|
||||
### Comparison: PATCH vs Bind vs Merge vs Delete Undo/Redo
|
||||
|
||||
| Aspect | PATCH Undo/Redo | Bind Undo/Redo | Merge Undo/Redo | Delete Undo/Redo |
|
||||
|--------|----------------|----------------|-----------------|------------------|
|
||||
| Storage | PostgreSQL `identity_history` | PostgreSQL `identity_history` | MongoDB `identity_merge_history` | PostgreSQL `identity_history` |
|
||||
| Operation filter | `operation='update'` | `operation IN ('bind','unbind','bind_trace')` | — | `operation='delete'` |
|
||||
| Trigger | Every PATCH | Every bind/unbind/bind_trace | Every mergeinto with `keep_history=true` | Every DELETE |
|
||||
| Undo deadline | None (unlimited) | None (unlimited) | 24 hours (renewed on redo) | None (unlimited) |
|
||||
| Redo support | Yes | Yes | Yes | Yes |
|
||||
| Step undo | Yes (`steps` param) | Yes (`steps` param) | No (full undo/redo only) | No (single record) |
|
||||
| Max records | 256 per identity | 256 per identity (shared) | Unlimited | 256 per identity (shared) |
|
||||
| User tracking | `user_id` + `user_source` | `user_id` + `user_source` | `performed_by_user` + `undone_by` / `redone_by` | `user_id` + `user_source` |
|
||||
|
||||
---
|
||||
|
||||
*Updated: 2026-05-28*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,345 @@
|
||||
---
|
||||
title: Face Filter API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-25
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: face_filter -->
|
||||
<!-- description: Face detection filtering and quality management -->
|
||||
<!-- depends: 01_auth, 03_register -->
|
||||
|
||||
## Face Filter API
|
||||
|
||||
Face filtering functionality for Studio frontend to manage face detection quality across multiple detection sources.
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/faces`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get filtered face detection list for a file with pagination and source filtering.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Parameter | Type | Required | Default | Description |
|
||||
|-----------|------|----------|---------|-------------|
|
||||
| `source` | string | No | "all" | Detection source: "all", "apple_vision", "mediapipe" |
|
||||
| `page` | integer | No | 1 | Page number (1-indexed) |
|
||||
| `page_size` | integer | No | 50 | Items per page |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/faces?source=apple_vision&page=1&page_size=50" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"faces": [
|
||||
{
|
||||
"face_id": "face_001",
|
||||
"frame": 671,
|
||||
"primary_source": "apple_vision",
|
||||
"primary_confidence": 0.84,
|
||||
"detection_sources": [
|
||||
{"source_type": "apple_vision", "confidence": 0.84},
|
||||
{"source_type": "mediapipe", "confidence": 0.92}
|
||||
]
|
||||
}
|
||||
],
|
||||
"total": 1523,
|
||||
"page": 1,
|
||||
"page_size": 50
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/faces/:face_id/filter`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get detailed filter report for a specific face detection.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `file_uuid` | string | File UUID |
|
||||
| `face_id` | string | Face detection ID |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/faces/face_001/filter" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"face_id": "face_001",
|
||||
"frame": 671,
|
||||
"passed_filter": true,
|
||||
"filter_rules": {
|
||||
"min_confidence": 0.5,
|
||||
"min_size": 30,
|
||||
"source_priority": ["apple_vision", "mediapipe"]
|
||||
},
|
||||
"quality_metrics": {
|
||||
"confidence": 0.84,
|
||||
"size": 120,
|
||||
"blurriness": 0.15
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/faces/apply-filter`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Apply filter rules to all faces in a file. Returns statistics on filtered faces.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `min_confidence` | float | No | Minimum confidence threshold (0.0-1.0) |
|
||||
| `min_size` | integer | No | Minimum face size in pixels |
|
||||
| `source_priority` | string[] | No | Preferred detection sources in order |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/faces/apply-filter" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"min_confidence": 0.6,
|
||||
"min_size": 40,
|
||||
"source_priority": ["apple_vision", "mediapipe"]
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"statistics": {
|
||||
"total_faces": 1523,
|
||||
"passed_faces": 1245,
|
||||
"filtered_faces": 278,
|
||||
"by_source": {
|
||||
"apple_vision": 985,
|
||||
"mediapipe": 260
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/faces/filter-stats`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get face filter statistics for a file without applying changes.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/faces/filter-stats" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"total_faces": 1523,
|
||||
"detection_sources": {
|
||||
"apple_vision": 985,
|
||||
"mediapipe": 538
|
||||
},
|
||||
"confidence_distribution": {
|
||||
"high": 1245,
|
||||
"medium": 200,
|
||||
"low": 78
|
||||
},
|
||||
"size_distribution": {
|
||||
"large": 500,
|
||||
"medium": 700,
|
||||
"small": 323
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/faces/rules`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Create or update face filter rules for a file.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `rules` | array | Yes | Array of filter rules |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/faces/rules" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"rules": [
|
||||
{
|
||||
"name": "high_quality",
|
||||
"conditions": {
|
||||
"min_confidence": 0.7,
|
||||
"min_size": 50
|
||||
},
|
||||
"action": "accept"
|
||||
}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/faces/rules`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get all face filter rules configured for a file.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/faces/rules" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"rules": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "high_quality",
|
||||
"conditions": {
|
||||
"min_confidence": 0.7,
|
||||
"min_size": 50
|
||||
},
|
||||
"action": "accept",
|
||||
"created_at": "2026-08-09T10:00:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `DELETE /api/v1/file/:file_uuid/faces/rules/:rule_id`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Delete a specific filter rule.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `rule_id` | integer | Rule ID |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X DELETE "$API/api/v1/file/$FILE_UUID/faces/rules/1" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Detection Sources
|
||||
|
||||
| Source | Description | Quality | Speed |
|
||||
|--------|-------------|---------|-------|
|
||||
| `apple_vision` | Apple Vision Framework | High (ANE accelerated) | Fast |
|
||||
| `mediapipe` | MediaPipe Face Detection | Medium | Medium |
|
||||
|
||||
---
|
||||
|
||||
## Quality Metrics
|
||||
|
||||
| Metric | Description | Range |
|
||||
|--------|-------------|-------|
|
||||
| `confidence` | Detection confidence | 0.0-1.0 |
|
||||
| `size` | Face bounding box diagonal (pixels) | 0-∞ |
|
||||
| `blurriness` | Laplacian variance (lower = clearer) | 0.0-1.0 |
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. Filter Low-Quality Faces
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/faces/apply-filter" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"min_confidence": 0.7, "min_size": 50}'
|
||||
```
|
||||
|
||||
### 2. Prioritize Apple Vision Detections
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/faces/apply-filter" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"source_priority": ["apple_vision"]}'
|
||||
```
|
||||
|
||||
### 3. Check Filter Statistics
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/faces/filter-stats" \
|
||||
-H "X-API-Key: $KEY" | jq '.data'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-25 | Rewrote documentation in English, added YAML frontmatter |
|
||||
@@ -0,0 +1,555 @@
|
||||
---
|
||||
title: Media API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: media -->
|
||||
<!-- description: Video streaming & frame extraction -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## Video Streaming & Frame Extraction
|
||||
|
||||
All video streaming endpoints support the following common query parameters:
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `mode` | string | No | `normal` | `normal` or `debug` (draws detection overlays) |
|
||||
| `audio` | string | No | `on` | `on` or `off` |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/video`
|
||||
|
||||
Stream the full video file with range support for seeking.
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
#### Response
|
||||
|
||||
- **200**: Video stream (`Content-Type` based on file extension)
|
||||
- **206**: Partial content (range request)
|
||||
- Supports `Range` header for seeking
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/trace/:trace_id/video`
|
||||
|
||||
Stream video with highlights for a specific face trace (follows a single person across frames with bounding box overlay).
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/trace/:trace_id/representative-face`
|
||||
|
||||
Find the best single face to represent this trace. Uses a two-stage selection: SQL (area × confidence → top 10) then FFmpeg `blurdetect` (sharpness → pick the least blurry).
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/trace/1939/representative-face" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "aeed71342a899fe4b4c57b7d41bcb692",
|
||||
"trace_id": 1939,
|
||||
"face_count": 538,
|
||||
"representative": {
|
||||
"frame_number": 68193,
|
||||
"timestamp_secs": 2727.72,
|
||||
"bbox": { "x": 347, "y": 378, "width": 427, "height": 427 },
|
||||
"confidence": 0.760,
|
||||
"quality_score": 138516,
|
||||
"blur_score": 9.46
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Response Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `trace_id` | integer | Face trace ID |
|
||||
| `face_count` | integer | Total face detections in this trace |
|
||||
| `representative.frame_number` | integer | Frame number of the selected face (primary coordinate) |
|
||||
| `representative.timestamp_secs` | float | Time in seconds (derived from `frame_number / fps`) |
|
||||
| `representative.bbox` | object | Bounding box `{x, y, width, height}` |
|
||||
| `representative.confidence` | float | Detection confidence (0.0–1.0) |
|
||||
| `representative.quality_score` | float | Pre-selection score (`area × confidence`) |
|
||||
| `representative.blur_score` | float | FFmpeg blurdetect result (lower = sharper) |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/trace/:trace_id/thumbnail`
|
||||
|
||||
Extract the best face image for a trace as JPEG (320×320). Internally selects the face using the same two-stage algorithm as `representative-face`, then crops via FFmpeg. The result is cacheable for 24 hours.
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/trace/1939/thumbnail" \
|
||||
-H "X-API-Key: $KEY" -o trace_1939_face.jpg
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
- **200**: `image/jpeg` binary data (320×320 cropped face)
|
||||
- **404**: File, trace not found, or no suitable face
|
||||
- **500**: FFmpeg or database error
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/identities/:identity_uuid_a/co-occur-with/:identity_uuid_b`
|
||||
|
||||
Find the first frame where two identities appear together, with representative face thumbnails for both.
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Audrey Hepburn & Cary Grant 第一次同框
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/identities/$AUDREY_UUID/co-occur-with/$CARY_UUID" \
|
||||
-H "X-API-Key: $KEY" | jq '{identity_a: .identity_a.name, identity_b: .identity_b.name, first_frame: .first_cooccurrence.frame_number}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "aeed71342a899fe4b4c57b7d41bcb692",
|
||||
"identity_a": {
|
||||
"identity_uuid": "c3545906-c82d-4b66-aa1d-150bc02decce",
|
||||
"name": "Audrey Hepburn",
|
||||
"trace_id": 920
|
||||
},
|
||||
"identity_b": {
|
||||
"identity_uuid": "2b0ddefe-e2a9-4533-9308-b375594604d5",
|
||||
"name": "Cary Grant",
|
||||
"trace_id": 919
|
||||
},
|
||||
"first_cooccurrence": {
|
||||
"frame_number": 38165,
|
||||
"timestamp_secs": 1526.60,
|
||||
"total_cooccurrence_frames": 3136,
|
||||
"representative_face_a": {
|
||||
"frame_number": 38199,
|
||||
"bbox": { "x": 122, "y": 339, "width": 176, "height": 176 },
|
||||
"confidence": 0.832,
|
||||
"thumbnail_url": "/api/v1/file/aeed71342.../trace/920/thumbnail"
|
||||
},
|
||||
"representative_face_b": {
|
||||
"frame_number": 38291,
|
||||
"bbox": { "x": 511, "y": 315, "width": 192, "height": 192 },
|
||||
"confidence": 0.791,
|
||||
"thumbnail_url": "/api/v1/file/aeed71342.../trace/919/thumbnail"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Response Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `identity_a.name` | string | First identity name |
|
||||
| `identity_b.name` | string | Second identity name |
|
||||
| `first_cooccurrence.frame_number` | int | First frame where both appear |
|
||||
| `first_cooccurrence.timestamp_secs` | float | Time in seconds |
|
||||
| `first_cooccurrence.total_cooccurrence_frames` | int | Total frames with both present |
|
||||
| `first_cooccurrence.representative_face_a/b` | object | Best face thumbnail data for each identity |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | File or identity not found |
|
||||
| `404` | The two identities never co-occur in this file |
|
||||
| `500` | Database or FFmpeg error |
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/video/bbox`
|
||||
|
||||
Stream video with bounding box overlay for all detected objects/faces.
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Uses a built-in 5×7 bitmap font renderer to draw labels directly on video frames via FFmpeg `drawtext` filter.
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/thumbnail`
|
||||
|
||||
Extract a single frame from a video as JPEG image. Uses FFmpeg `select` filter.
|
||||
|
||||
When `frame` is omitted, the system automatically selects the best representative frame using the TKG bridge (see algorithm below).
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `frame` | integer | No | auto-detect | Zero-based frame number to extract. Omit for auto-detect. |
|
||||
| `x` | integer | No | — | Crop start X (left edge). Requires `y`, `w`, `h`. |
|
||||
| `y` | integer | No | — | Crop start Y (top edge). Requires `x`, `w`, `h`. |
|
||||
| `w` | integer | No | — | Crop width in pixels. Requires `x`, `y`, `h`. |
|
||||
| `h` | integer | No | — | Crop height in pixels. Requires `x`, `y`, `w`. |
|
||||
|
||||
All four crop params (`x`, `y`, `w`, `h`) must be provided together or omitted.
|
||||
|
||||
#### Auto-detect Algorithm
|
||||
|
||||
When `frame` is not provided, the endpoint finds the best frame using this fallback chain:
|
||||
|
||||
1. **Main characters**: find the two identities with the most face detections (TMDb source)
|
||||
2. **Mutual gaze**: if their face traces have a TKG `CO_OCCURS_WITH` edge with `mutual_gaze=true`, take `first_frame`
|
||||
3. **Co-occurrence**: fallback to the first frame where both identities appear together
|
||||
4. **Single identity**: if only one main identity exists, take its highest-quality face frame
|
||||
5. **Any identity**: fallback to the best-quality face frame across all identities
|
||||
6. **Error**: if no face exists, returns `404`
|
||||
|
||||
The selected frame is constrained to the **first half of the video** (`total_frames / 2`).
|
||||
|
||||
#### Examples
|
||||
|
||||
```bash
|
||||
# Auto-detect best representative frame
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/thumbnail" \
|
||||
-H "X-API-Key: $KEY" -o representative.jpg
|
||||
|
||||
# Extract frame 1000 (full frame)
|
||||
curl -s "$API/api/v1/file/bd80fec92b0b6963d177a2c55bf713e2/thumbnail?frame=1000" \
|
||||
-H "Authorization: Bearer $JWT" -o frame_1000.jpg
|
||||
|
||||
# Extract and crop face region (x=320, y=240, w=160, h=160)
|
||||
curl -s "$API/api/v1/file/bd80fec92b0b6963d177a2c55bf713e2/thumbnail?frame=1000&x=320&y=240&w=160&h=160" \
|
||||
-H "Authorization: Bearer $JWT" -o face_crop.jpg
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
- **200**: `image/jpeg` binary data
|
||||
- **404**: File not found / No faces in file (auto-detect)
|
||||
- **500**: FFmpeg error (e.g., frame number exceeds video duration)
|
||||
|
||||
#### Technical Details
|
||||
|
||||
| Detail | Value |
|
||||
|--------|-------|
|
||||
| **Backend** | FFmpeg (`ffmpeg-full`) |
|
||||
| **Filter** | `select=eq(n\,FRAME)` to select frame, optional `crop=W:H:X:Y` |
|
||||
| **Output** | Single JPEG via pipe (`image2pipe`, `mjpeg` codec) |
|
||||
| **Cache** | `Cache-Control: public, max-age=86400` (24h) |
|
||||
| **Frame number** | Zero-based (`frame=0` = first frame of video) |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/representative-frame`
|
||||
|
||||
Return JSON metadata about the best representative frame for the video. Uses the same auto-detect algorithm as `GET /thumbnail` (without crop support).
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/representative-frame" \
|
||||
-H "X-API-Key: $KEY" | jq '.'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "aeed71342a899fe4b4c57b7d41bcb692",
|
||||
"frame_number": 38165,
|
||||
"timestamp_secs": 1526.6,
|
||||
"face_quality": 37292.97,
|
||||
"main_identities": [
|
||||
{
|
||||
"identity_uuid": "c3545906-c82d-4b66-aa1d-150bc02decce",
|
||||
"name": "Audrey Hepburn",
|
||||
"face_count": 16456
|
||||
},
|
||||
{
|
||||
"identity_uuid": "2b0ddefe-e2a9-4533-9308-b375594604d5",
|
||||
"name": "Cary Grant",
|
||||
"face_count": 10643
|
||||
}
|
||||
],
|
||||
"traces": [
|
||||
{
|
||||
"trace_id": 919,
|
||||
"identity_uuid": "2b0ddefe-e2a9-4533-9308-b375594604d5",
|
||||
"name": "Cary Grant",
|
||||
"x": 764,
|
||||
"y": 237,
|
||||
"width": 199,
|
||||
"height": 199,
|
||||
"confidence": 0.8426
|
||||
},
|
||||
{
|
||||
"trace_id": 920,
|
||||
"identity_uuid": "c3545906-c82d-4b66-aa1d-150bc02decce",
|
||||
"name": "Audrey Hepburn",
|
||||
"x": 1143,
|
||||
"y": 312,
|
||||
"width": 215,
|
||||
"height": 215,
|
||||
"confidence": 0.8068
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Response Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `frame_number` | integer | Selected representative frame number (primary coordinate) |
|
||||
| `timestamp_secs` | float | Time in seconds (derived from `frame_number / fps`) |
|
||||
| `face_quality` | float | Quality score `area × confidence` of the best face at this frame |
|
||||
| `main_identities` | array | Top 2 most frequent TMDb identities in the file |
|
||||
| `main_identities[].name` | string | Identity display name |
|
||||
| `main_identities[].face_count` | integer | Total face detections count |
|
||||
| `traces` | array | All face traces present at the selected frame |
|
||||
| `traces[].trace_id` | integer | Face trace ID |
|
||||
| `traces[].identity_uuid` | string or null | Matched identity UUID |
|
||||
| `traces[].name` | string or null | Identity name |
|
||||
| `traces[].x, y, width, height` | integer | Bounding box coordinates |
|
||||
| `traces[].confidence` | float | Detection confidence (0.0–1.0) |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | File not found / No faces in file |
|
||||
| `500` | Database error |
|
||||
|
||||
Extract a video clip (time range) as MPEG-TS stream. Uses FFmpeg `-ss` fast seek.
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `start_frame` | integer | No* | — | Start frame (zero-based). **Frame-accurate** — use this for precision. |
|
||||
| `end_frame` | integer | No* | — | End frame (zero-based, inclusive). Requires `start_frame`. |
|
||||
| `start_time` | float | No* | — | Start time in seconds. Approximate (FPS-dependent). Fallback if frames not given. |
|
||||
| `end_time` | float | No* | — | End time in seconds. Approximate (FPS-dependent). Fallback if frames not given. |
|
||||
| `fps` | float | No | video FPS | Override frames-per-second for frame↔time calculation. Defaults to video's detected FPS. |
|
||||
| `mode` | string | No | `normal` | `normal` or `debug` (draws "CLIP" overlay) |
|
||||
| `audio` | string | No | `on` | `on` or `off` |
|
||||
|
||||
Either (`start_frame`+`end_frame`) OR (`start_time`+`end_time`) must be provided.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Clip by frame range (primary)
|
||||
curl -s "$API/api/v1/file/bd80fec92b0b6963d177a2c55bf713e2/clip?start_frame=0&end_frame=47" \
|
||||
-H "Authorization: Bearer $JWT" -o clip.ts
|
||||
|
||||
# Clip by time range (fallback)
|
||||
curl -s "$API/api/v1/file/bd80fec92b0b6963d177a2c55bf713e2/clip?start_time=30&end_time=45" \
|
||||
-H "Authorization: Bearer $JWT" -o clip.ts
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
- **200**: `video/mp2t` MPEG-TS stream
|
||||
- **400**: Missing/invalid range parameters
|
||||
- **404**: File not found
|
||||
- **500**: FFmpeg error
|
||||
|
||||
#### Technical Notes
|
||||
|
||||
| Detail | Value |
|
||||
|--------|-------|
|
||||
| **Backend** | FFmpeg (`ffmpeg-full`) |
|
||||
| **Seek** | `-ss` before `-i` (fast keyframe seek) |
|
||||
| **Format** | MPEG-TS (`mpegts` muxer, pipe-safe) |
|
||||
| **Codec** | H.264 + AAC |
|
||||
| **Cache** | `Cache-Control: public, max-age=86400` (24h) |
|
||||
|
||||
### Video vs Clip: Quality & Format Comparison
|
||||
|
||||
Both endpoints support time range extraction, but serve different use cases:
|
||||
|
||||
| Feature | `/video` | `/clip` |
|
||||
|---------|----------|---------|
|
||||
| **No params** | Streams full file (Range seek) | Returns 400 (params required) |
|
||||
| **HTTP Range** | ✅ Supported | ❌ Not supported |
|
||||
| **Encoding** | `-c copy` (zero encoding) | `-c:v libx264 -c:a aac` (re-encode) |
|
||||
| **Quality** | Original (bit-exact, zero loss) | Compressed (default CRF ≈ 23) |
|
||||
| **Format** | `video/mp4` | `video/mp2t` (MPEG-TS) |
|
||||
| **Speed** | Fast (no computation) | Slower (encoding required) |
|
||||
| **Frame control** | Time-based (`dur = (ef-sf)/fps`) | Precise (`-vframes`) |
|
||||
| **Debug mode** | ❌ | ✅ `mode=debug` overlay |
|
||||
| **Cache** | ❌ | ✅ `max-age=86400` |
|
||||
|
||||
#### Usage Recommendation
|
||||
|
||||
| Scenario | Use |
|
||||
|----------|-----|
|
||||
| Full video streaming / player seek | `/video` |
|
||||
| Quick preview clip (zero quality loss) | `/video?start_frame=...&end_frame=...` |
|
||||
| Debug frame verification / text overlay | `/clip?mode=debug` |
|
||||
| Precise frame count control | `/clip` |
|
||||
| CDN cacheable clip | `/clip` |
|
||||
|
||||
---
|
||||
|
||||
| Detail | Value |
|
||||
|--------|-------|
|
||||
| **Backend** | FFmpeg (`ffmpeg-full`) |
|
||||
| **Filter** | `select=eq(n\,FRAME)` to select frame, optional `crop=W:H:X:Y` |
|
||||
| **Output** | Single JPEG via pipe (`image2pipe`, `mjpeg` codec) |
|
||||
| **Cache** | `Cache-Control: public, max-age=86400` (24h) |
|
||||
| **Frame number** | Zero-based (`frame=0` = first frame of video) |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/stranger/:stranger_id/representative-face`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get the representative face for a stranger (unidentified face trace).
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/stranger/1/representative-face" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"stranger_id": 1,
|
||||
"face_count": 85,
|
||||
"representative": {
|
||||
"frame_number": 5000,
|
||||
"timestamp_secs": 208.33,
|
||||
"bbox": {"x": 200, "y": 100, "width": 150, "height": 150},
|
||||
"confidence": 0.92,
|
||||
"quality_score": 20700,
|
||||
"blur_score": 8.5
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/stranger/:stranger_id/thumbnail`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Extract the best face image for a stranger as JPEG (320×320).
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/stranger/1/thumbnail" \
|
||||
-H "X-API-Key: $KEY" -o stranger_1_face.jpg
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
- **200**: `image/jpeg` binary data (320×320 cropped face)
|
||||
- **404**: File or stranger not found
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/chunk/:chunk_id/thumbnail`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get thumbnail for a specific chunk. Extracts the representative frame for the chunk's time range.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/chunk/chunk_1/thumbnail" \
|
||||
-H "X-API-Key: $KEY" -o chunk_1.jpg
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
- **200**: `image/jpeg` binary data
|
||||
- **404**: File or chunk not found
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/media-proxy`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Proxy request to fetch media from external URLs. Useful for loading profile images or thumbnails from external services (TMDb, etc.) without exposing the external URL to the client.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `url` | string | Yes | External URL to proxy |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/media-proxy?url=https://image.tmdb.org/t/p/w500/abc123.jpg" \
|
||||
-H "X-API-Key: $KEY" -o tmdb_profile.jpg
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
- **200**: Proxied media data (Content-Type from external source)
|
||||
- **400**: Missing or invalid URL parameter
|
||||
- **500**: External request failed
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
*Updated: 2026-06-20 — Added stranger endpoints, chunk thumbnail, and media proxy*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,494 @@
|
||||
---
|
||||
title: profile API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: profile -->
|
||||
<!-- description: Trace profile and file profile management — read/update face trace names, key frames, aliases, and file paths -->
|
||||
<!-- depends: 01_auth, 07_identity, 15_tkg -->
|
||||
|
||||
## Profile Management
|
||||
|
||||
Endpoints for managing trace profiles (face track metadata stored in TKG) and file profiles (video metadata stored in PostgreSQL).
|
||||
|
||||
---
|
||||
|
||||
## Terminology
|
||||
|
||||
### Core Concepts
|
||||
|
||||
| Term | Definition | Identifier | Display Format |
|
||||
|------|------------|------------|----------------|
|
||||
| **Face** | A single human face detection on one frame | `face_id` | Usually not displayed |
|
||||
| **Face Sequence (Trace)** | A collection of faces across multiple frames representing the same person | `trace_id` | `FS#233` |
|
||||
| **Face Group** | A collection of traces sharing the same name/label | `label` (string) | `"Person A"` |
|
||||
|
||||
### Data Model Hierarchy
|
||||
|
||||
```
|
||||
Video
|
||||
└── Frame (F#233, F#234, ...) ← Single frame number
|
||||
└── Face ← Single detection (bbox + confidence)
|
||||
└── Face Sequence / Trace ← Same person across frames (FS#233)
|
||||
└── Face Group ← Multiple traces with same name
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
Video: "interview.mp4"
|
||||
├── Frame F#100
|
||||
│ └── Face (bbox: {100, 200, 50, 50}, confidence: 0.95)
|
||||
├── Frame F#105
|
||||
│ └── Face (bbox: {110, 205, 48, 48}, confidence: 0.92)
|
||||
├── Frame F#110
|
||||
│ └── Face (bbox: {115, 210, 52, 52}, confidence: 0.88)
|
||||
...
|
||||
|
||||
Face Sequence FS#233 = [Face@F#100, Face@F#105, Face@F#110, ...]
|
||||
↓
|
||||
Face Group "Person A" = [FS#233, FS#234, FS#235]
|
||||
```
|
||||
|
||||
### Storage
|
||||
|
||||
| Entity | Storage | Table/Collection |
|
||||
|--------|---------|------------------|
|
||||
| Face | Qdrant | `_faces` collection |
|
||||
| Face Sequence / Trace | PostgreSQL (TKG) | `tkg_nodes` where `node_type='face_track'` |
|
||||
| Face Group | PostgreSQL (TKG) | `tkg_nodes.label` field |
|
||||
|
||||
### Operations
|
||||
|
||||
| Operation | Level | API |
|
||||
|-----------|-------|-----|
|
||||
| View faces | Face | Internal (embedded in trace data) |
|
||||
| Merge traces | Trace | `POST /api/v1/trace/:file_uuid/merge` |
|
||||
| Rename group | Group | `PUT /api/v1/trace-profile/group` |
|
||||
| Merge groups | Group | `POST /api/v1/file/:file_uuid/groups/merge` |
|
||||
|
||||
### Naming Convention
|
||||
|
||||
- **Frame**: `F#{number}` — e.g., `F#233`
|
||||
- **Face Sequence / Trace**: `FS#{number}` — e.g., `FS#233`
|
||||
- **Face Group**: String name — e.g., `"Person A"`, `"Speaker 1"`
|
||||
|
||||
### `GET /api/v1/trace-profile`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Read a single face trace's profile including name, key frame, key face, and multi-language aliases.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
| `trace_id` | integer | Yes | Trace ID (numeric) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/trace-profile?file_uuid=$FILE_UUID&trace_id=7" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "9f6a9cd55a5809f977f5a6589b9045c5",
|
||||
"trace_id": 7,
|
||||
"name": "John Doe",
|
||||
"key_frame": 640,
|
||||
"key_face": "face_12345",
|
||||
"aliases": {
|
||||
"en": "John Doe",
|
||||
"zh": "約翰"
|
||||
},
|
||||
"properties": {
|
||||
"status": "bound",
|
||||
"avg_bbox": {"x": 899, "y": 212, "width": 342, "height": 342},
|
||||
"start_frame": 624,
|
||||
"end_frame": 669,
|
||||
"frame_count": 5
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | File UUID |
|
||||
| `trace_id` | integer | Trace ID |
|
||||
| `name` | string | Display name (from `tkg_nodes.label`) |
|
||||
| `key_frame` | integer | Representative frame number, or null |
|
||||
| `key_face` | string | Representative face ID, or null |
|
||||
| `aliases` | object | Multi-language name aliases |
|
||||
| `properties` | object | Full TKG node properties (bbox, frames, etc.) |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | Trace not found |
|
||||
| `401` | Missing or invalid API key |
|
||||
|
||||
---
|
||||
|
||||
### `PUT /api/v1/trace-profile`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Update a single face trace's profile fields. Only provided fields are updated; others remain unchanged.
|
||||
|
||||
#### Request Body
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
| `trace_id` | integer | Yes | Trace ID to update |
|
||||
| `name` | string | No | New display name |
|
||||
| `key_frame` | integer | No | Representative frame number |
|
||||
| `key_face` | string | No | Representative face ID |
|
||||
| `aliases` | object | No | Multi-language aliases `{"en": "...", "zh": "..."}` |
|
||||
| `properties` | object | No | Additional properties to merge into existing JSONB |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X PUT "$API/api/v1/trace-profile" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"file_uuid": "9f6a9cd55a5809f977f5a6589b9045c5",
|
||||
"trace_id": 7,
|
||||
"name": "John Doe",
|
||||
"key_frame": 640,
|
||||
"key_face": "face_12345",
|
||||
"aliases": {"en": "John Doe", "zh": "約翰"}
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Trace profile updated",
|
||||
"file_uuid": "9f6a9cd55a5809f977f5a6589b9045c5",
|
||||
"trace_id": 7
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `PUT /api/v1/trace-profile/group`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Batch update the `name` (label) for multiple traces in a face group. Used when renaming a group.
|
||||
|
||||
#### Request Body
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
| `trace_ids` | integer[] | Yes | List of trace IDs to update |
|
||||
| `name` | string | Yes | New group name for all traces |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X PUT "$API/api/v1/trace-profile/group" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"file_uuid": "9f6a9cd55a5809f977f5a6589b9045c5",
|
||||
"trace_ids": [7, 2, 13],
|
||||
"name": "Group A"
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Updated 3 traces in group",
|
||||
"file_uuid": "9f6a9cd55a5809f977f5a6589b9045c5",
|
||||
"updated_count": 3
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/groups/merge`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Merge multiple face groups into one target group. All traces from source groups are reassigned to the target group name.
|
||||
|
||||
#### Request Body
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
| `source_groups` | string[] | Yes | List of group names to merge from |
|
||||
| `target_group_name` | string | Yes | Target group name to merge into |
|
||||
|
||||
#### Examples
|
||||
|
||||
**Merge 2 groups**:
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/groups/merge" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"file_uuid": "c36f35685177c981aa139b66bbbccc5b",
|
||||
"source_groups": ["Person A"],
|
||||
"target_group_name": "Person B"
|
||||
}'
|
||||
```
|
||||
|
||||
**Merge 4 groups**:
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/groups/merge" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"file_uuid": "c36f35685177c981aa139b66bbbccc5b",
|
||||
"source_groups": ["Person A", "Person C", "Person D"],
|
||||
"target_group_name": "Person B"
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "c36f35685177c981aa139b66bbbccc5b",
|
||||
"source_groups": ["Person A", "Person C", "Person D"],
|
||||
"target_group_name": "Person B",
|
||||
"traces_merged": 12,
|
||||
"message": "Merged 3 group(s) into 'Person B'"
|
||||
}
|
||||
```
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | Condition |
|
||||
|------|-----------|
|
||||
| `400` | Target group in source_groups list |
|
||||
| `400` | Empty source_groups array |
|
||||
| `500` | Database error |
|
||||
|
||||
#### Behavior
|
||||
|
||||
1. Find all traces with `label IN (source_groups)`
|
||||
2. Update their labels to `target_group_name`
|
||||
3. All source groups disappear (no traces left)
|
||||
4. Target group contains all traces from merged groups
|
||||
|
||||
---
|
||||
|
||||
### Merging Groups: Two Methods
|
||||
|
||||
#### Method 1: Use Merge Groups API (Recommended)
|
||||
|
||||
```bash
|
||||
POST /api/v1/file/:file_uuid/groups/merge
|
||||
{
|
||||
"file_uuid": "...",
|
||||
"source_groups": ["Person A", "Person C"],
|
||||
"target_group_name": "Person B"
|
||||
}
|
||||
```
|
||||
|
||||
**Pros**: Simple, only requires group names, supports multi-group merge
|
||||
**Cons**: New API (requires backend update)
|
||||
|
||||
#### Method 2: Use Batch Update API (Existing)
|
||||
|
||||
```bash
|
||||
PUT /api/v1/trace-profile/group
|
||||
{
|
||||
"file_uuid": "...",
|
||||
"trace_ids": [13, 14, 15, 43, 44],
|
||||
"name": "Person B"
|
||||
}
|
||||
```
|
||||
|
||||
**Pros**: Works with existing API
|
||||
**Cons**: Frontend must collect all trace_ids from both groups
|
||||
|
||||
#### Example: Merge Group A and C into Group B
|
||||
|
||||
**Before**:
|
||||
```
|
||||
Group A: [13, 14, 15]
|
||||
Group B: [43, 44]
|
||||
Group C: [67, 68]
|
||||
```
|
||||
|
||||
**Method 1 (Recommended)**:
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/groups/merge" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"file_uuid": "c36f35685177c981aa139b66bbbccc5b",
|
||||
"source_groups": ["Person A", "Person C"],
|
||||
"target_group_name": "Person B"
|
||||
}'
|
||||
```
|
||||
|
||||
**Method 2 (Existing API)**:
|
||||
```bash
|
||||
curl -X PUT "$API/api/v1/trace-profile/group" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"file_uuid": "c36f35685177c981aa139b66bbbccc5b",
|
||||
"trace_ids": [13, 14, 15, 43, 44, 67, 68],
|
||||
"name": "Person B"
|
||||
}'
|
||||
```
|
||||
|
||||
**After**:
|
||||
```
|
||||
Group A: [] (disappeared)
|
||||
Group B: [43, 44, 13, 14, 15, 67, 68]
|
||||
Group C: [] (disappeared)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file-profile`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Read a file's metadata including path, name, status, and technical details.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file-profile?file_uuid=$FILE_UUID" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "49884ce1c341953d1ad7bf67a77c30cc",
|
||||
"file_name": "Dedicatoria.mp4",
|
||||
"file_path": "/Users/accusys/momentry/var/sftpgo/data/demo/Dedicatoria.mp4",
|
||||
"status": "completed",
|
||||
"duration": 93.33,
|
||||
"width": 1280,
|
||||
"height": 720,
|
||||
"fps": 30.0,
|
||||
"total_frames": 0
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | File UUID |
|
||||
| `file_name` | string | File name |
|
||||
| `file_path` | string | Full filesystem path |
|
||||
| `status` | string | `pending`, `processing`, `completed`, `failed` |
|
||||
| `duration` | float | Duration in seconds |
|
||||
| `width` | integer | Video width in pixels |
|
||||
| `height` | integer | Video height in pixels |
|
||||
| `fps` | float | Frames per second |
|
||||
| `total_frames` | integer | Total frame count |
|
||||
|
||||
---
|
||||
|
||||
### `PUT /api/v1/file-profile`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Update file metadata, typically used when a file is moved to a new location.
|
||||
|
||||
#### Request Body
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
| `file_path` | string | No | New filesystem path |
|
||||
| `file_name` | string | No | New file name |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X PUT "$API/api/v1/file-profile" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"file_uuid": "49884ce1c341953d1ad7bf67a77c30cc",
|
||||
"file_path": "/new/location/Dedicatoria.mp4"
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "File profile updated",
|
||||
"file_uuid": "49884ce1c341953d1ad7bf67a77c30cc"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Data Storage
|
||||
|
||||
| Profile Type | Storage | Table |
|
||||
|-------------|---------|-------|
|
||||
| **trace_profile** | PostgreSQL (TKG) | `tkg_nodes` where `node_type='face_track'` |
|
||||
| **file_profile** | PostgreSQL | `videos` |
|
||||
|
||||
### Trace Profile Fields
|
||||
|
||||
| Field | TKG Column | Description |
|
||||
|-------|-----------|-------------|
|
||||
| `name` | `label` | Display name for the trace |
|
||||
| `key_frame` | `properties->'key_frame'` | Representative frame number |
|
||||
| `key_face` | `properties->'key_face'` | Representative face ID |
|
||||
| `aliases` | `properties->'aliases'` | Multi-language name aliases |
|
||||
|
||||
---
|
||||
*Updated: 2026-07-25 — Added Merge Groups API (POST /groups/merge), added Terminology section (Face, Face Sequence, Face Group)*
|
||||
*Updated: 2026-07-21 — Fixed external_id matching (trace_N + face_track_N formats), fixed parameter ordering in UPDATE query*
|
||||
*Updated: 2026-07-18 — New profile module: trace-profile (GET, PUT, PUT group) and file-profile (GET, PUT)*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,184 @@
|
||||
---
|
||||
title: Pose & Appearance API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: pose_appearance -->
|
||||
<!-- description: Pose skeleton and appearance color endpoints for face detail display -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## Pose & Appearance
|
||||
|
||||
Endpoints for retrieving pose keypoints and appearance color data for face detail modal display.
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/pose`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get pose keypoints for a specific frame. Returns 17 COCO keypoints with deduplication (highest confidence selected for each keypoint name).
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `frame` | integer | Yes | Frame number |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/pose?frame=303" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"frame": 303,
|
||||
"keypoints": [
|
||||
{"name": "nose", "x": 315.91, "y": 364.25, "confidence": 0.616},
|
||||
{"name": "left_eye", "x": 312.45, "y": 362.80, "confidence": 0.616},
|
||||
{"name": "right_eye", "x": 316.21, "y": 361.38, "confidence": 0.616},
|
||||
{"name": "left_ear", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "right_ear", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "left_shoulder", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "right_shoulder", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "left_elbow", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "right_elbow", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "left_wrist", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "right_wrist", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "left_hip", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "right_hip", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "left_knee", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "right_knee", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "left_ankle", "x": 0.0, "y": 0.0, "confidence": 0.0},
|
||||
{"name": "right_ankle", "x": 0.0, "y": 0.0, "confidence": 0.0}
|
||||
],
|
||||
"pose_class": "unknown",
|
||||
"confidence": null
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `frame` | integer | Frame number |
|
||||
| `keypoints` | array | 17 COCO keypoints (deduplicated) |
|
||||
| `keypoints[].name` | string | Keypoint name |
|
||||
| `keypoints[].x` | float | X coordinate in pixels |
|
||||
| `keypoints[].y` | float | Y coordinate in pixels |
|
||||
| `keypoints[].confidence` | float | Detection confidence 0-1 (0 means not detected) |
|
||||
| `pose_class` | string | Always `"unknown"` in POC |
|
||||
| `confidence` | null | Always `null` in POC |
|
||||
|
||||
#### COCO-17 Keypoint Names
|
||||
|
||||
```
|
||||
nose, left_eye, right_eye, left_ear, right_ear,
|
||||
left_shoulder, right_shoulder, left_elbow, right_elbow,
|
||||
left_wrist, right_wrist, left_hip, right_hip,
|
||||
left_knee, right_knee, left_ankle, right_ankle
|
||||
```
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| 404 | Frame not found or pose.json not found |
|
||||
| 401 | Missing or invalid API key |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/appearance`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get appearance color data for a specific frame. Returns HSV histogram for color analysis.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `frame` | integer | Yes | Frame number |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/appearance?frame=303" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"frame": 303,
|
||||
"dominant_colors": [],
|
||||
"hsv_histogram": [
|
||||
[0.59, 0.0, 0.0, ...],
|
||||
[0.97, 0.02, 0.01, ...],
|
||||
[0.004, 0.02, 0.03, ...]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `frame` | integer | Frame number |
|
||||
| `dominant_colors` | array | Empty array in POC (`[]`) |
|
||||
| `hsv_histogram` | array | 3x30 HSV histogram bins (H, S, V channels) |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| 404 | Frame not found or appearance.json not found |
|
||||
| 401 | Missing or invalid API key |
|
||||
|
||||
---
|
||||
|
||||
## Data Source
|
||||
|
||||
| Processor | File | Location |
|
||||
|-----------|------|----------|
|
||||
| Pose | `{file_uuid}.pose.json` | `{OUTPUT_DIR}/` |
|
||||
| Appearance | `{file_uuid}.appearance.json` | `{OUTPUT_DIR}/` |
|
||||
|
||||
---
|
||||
|
||||
## POC Limitations
|
||||
|
||||
| Feature | POC Status | Future |
|
||||
|---------|------------|--------|
|
||||
| Pose classification | `"unknown"` | ML model for standing/sitting/etc. |
|
||||
| Dominant colors | Empty array `[]` | HSV extraction algorithm |
|
||||
| Multiple persons | First person only | Match by trace_id |
|
||||
| Confidence | `null` | Aggregated confidence score |
|
||||
|
||||
---
|
||||
*Updated: 2026-07-19 — New pose and appearance endpoints for face detail display*
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,219 @@
|
||||
---
|
||||
title: tmdb API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: tmdb -->
|
||||
<!-- description: TMDb enrichment endpoints — prefetch, probe, resource, check -->
|
||||
<!-- depends: 01_auth, 03_register -->
|
||||
|
||||
## TMDb Enrichment
|
||||
|
||||
> **Offline operation**: TMDb prefetch now checks local identity files first (`identities/_index.json` + `*.tmdb.json`).
|
||||
> If local files exist, no external API call is made. Internet is only needed for initial data seeding.
|
||||
|
||||
### Overview
|
||||
|
||||
TMDb enrichment is an optional identity enrichment step that can be run after Pipeline face detection completes. The workflow is:
|
||||
|
||||
1. **Prefetch** (requires internet): Download movie cast data from TMDb API → cache to `{file_uuid}.tmdb.json`
|
||||
2. **Probe**: Read local cache → create identities for **all** cast members (`source='tmdb'`) + save `identity.json` + download profile image to `{OUTPUT}/identities/{uuid}/profile.jpg`
|
||||
3. **Match**: The worker automatically matches video faces against TMDb identities when `MOMENTRY_TMDB_PROBE_ENABLED=true`
|
||||
|
||||
### `POST /api/v1/agents/tmdb/prefetch`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Fetch TMDb cast data for a registered file and cache it locally. This is the only step requiring internet access.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID to enrich |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/agents/tmdb/prefetch" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"file_uuid": "'"$FILE_UUID"'"}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{"success": true, "file_uuid": "...", "cache_path": "/output/...tmdb.json"}
|
||||
```
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/tmdb-probe`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Read local TMDb cache and create/update identities. Requires prefetch to have been run first.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tmdb-probe" \
|
||||
-H "X-API-Key: $KEY" | jq '{identities_created, movie_title}'
|
||||
```
|
||||
|
||||
#### Response (200 — identities created)
|
||||
|
||||
```json
|
||||
{"success": true, "identities_created": 15, "movie_title": "Charade"}
|
||||
```
|
||||
|
||||
#### Response (200 — no cache)
|
||||
|
||||
```json
|
||||
{"success": false, "message": "No TMDb cache found. Run tmdb-prefetch first."}
|
||||
```
|
||||
|
||||
### `GET /api/v1/resource/tmdb`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
View TMDb resource status including configuration, identity counts, and cache file count.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/resource/tmdb" -H "X-API-Key: $KEY" \
|
||||
| jq '{identities_seeded, cache_files}'
|
||||
```
|
||||
|
||||
### `POST /api/v1/resource/tmdb/check`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Ping the TMDb API to verify connectivity and measure latency.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/resource/tmdb/check" \
|
||||
-H "X-API-Key: $KEY" | jq '.status'
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"api_key_configured": true,
|
||||
"enabled": false,
|
||||
"api_reachable": true,
|
||||
"api_latency_ms": 120
|
||||
}
|
||||
```
|
||||
|
||||
### `POST /api/v1/tmdb/fetch`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Fetch TMDb data by filename, create identities with profile images and embeddings. Similar to prefetch+probe combined, but also downloads profile images and generates embeddings.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `filename` | string | Yes | Movie filename to search TMDb for |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/tmdb/fetch" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"filename": "charade.mp4"}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"movie_title": "Charade (1963)",
|
||||
"tmdb_id": 1234,
|
||||
"identities_created": 15,
|
||||
"profile_images_downloaded": 12
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/agents/tmdb/match/:file_uuid`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Match TMDb identities to face traces using Qdrant vector similarity. Compares face embeddings against TMDb identity embeddings to find the best matches.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/agents/tmdb/match/$FILE_UUID" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"matches": [
|
||||
{
|
||||
"trace_id": 0,
|
||||
"identity_uuid": "a9a90105-6d6b-46ff-92da-0c3c1a57dff4",
|
||||
"identity_name": "Audrey Hepburn",
|
||||
"confidence": 0.92,
|
||||
"tmdb_id": 1234
|
||||
}
|
||||
],
|
||||
"total_matches": 5
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `matches[].trace_id` | integer | Face trace ID |
|
||||
| `matches[].identity_uuid` | string | Matched TMDb identity UUID |
|
||||
| `matches[].identity_name` | string | Identity display name |
|
||||
| `matches[].confidence` | float | Cosine similarity score (0.0–1.0) |
|
||||
| `matches[].tmdb_id` | integer | TMDb person ID |
|
||||
| `total_matches` | integer | Total successful matches |
|
||||
|
||||
---
|
||||
|
||||
### TMDb Auto-Match
|
||||
|
||||
When `MOMENTRY_TMDB_PROBE_ENABLED=true`, the worker automatically runs TMDb matching during the post-process phase:
|
||||
|
||||
1. **Register phase**: Searches TMDb by filename, creates identities with `tmdb_id`/`tmdb_profile`
|
||||
2. **Post-process phase**: Matches detected faces against TMDb identities via cosine similarity using Qdrant
|
||||
|
||||
No manual API call needed if auto-match is enabled.
|
||||
|
||||
---
|
||||
*Updated: 2026-06-20 — Added tmdb/fetch and tmdb/match endpoints*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,229 @@
|
||||
---
|
||||
title: agent API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
# Agent Endpoints
|
||||
|
||||
Agent endpoints provide AI-powered capabilities including translation, identity analysis, and 5W1H extraction.
|
||||
|
||||
## POST /api/v1/agents/translate
|
||||
|
||||
Translate text between languages using Gemma4 (llama.cpp, port 8082).
|
||||
|
||||
### Request
|
||||
|
||||
```json
|
||||
{
|
||||
"text": "Hello, welcome to Momentry Core.",
|
||||
"target_language": "Traditional Chinese",
|
||||
"source_language": "English"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `text` | string | ✅ | Text to translate |
|
||||
| `target_language` | string | ✅ | Target language name (e.g. "Traditional Chinese", "Japanese") |
|
||||
| `source_language` | string | ❌ | Source language (default: "auto") |
|
||||
|
||||
### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"translated_text": "您好,歡迎使用 Momentry Core。",
|
||||
"source_language_detected": "English",
|
||||
"model_used": "google_gemma-4-26B-A4B-it-Q5_K_M.gguf"
|
||||
}
|
||||
```
|
||||
|
||||
### Supported Language Pairs (tested)
|
||||
|
||||
| Source | Target | Quality |
|
||||
|--------|--------|---------|
|
||||
| English | Traditional Chinese | ✅ |
|
||||
| English | Japanese | ✅ |
|
||||
| Chinese | English | ✅ |
|
||||
| English | French | ✅ |
|
||||
| Chinese | Japanese | ✅ |
|
||||
|
||||
### Model
|
||||
|
||||
- **Model**: Gemma4 26B (Q5_K_M)
|
||||
- **Engine**: llama.cpp at `localhost:8082`
|
||||
- **Endpoint**: `/v1/chat/completions` (OpenAI-compatible)
|
||||
- **Temperature**: 0.1
|
||||
- **Max tokens**: 1024
|
||||
|
||||
### Errors
|
||||
|
||||
| Status | Condition |
|
||||
|--------|-----------|
|
||||
| 500 | LLM unreachable or response parse failure |
|
||||
| 401 | Missing/invalid auth |
|
||||
|
||||
---
|
||||
|
||||
## POST /api/v1/agents/5w1h/analyze
|
||||
|
||||
Extract 5W1H (Who, What, When, Where, Why, How) from a scene. Uses Gemma4 LLM on port 8082.
|
||||
|
||||
### Request
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3abeee81d94597629ed8cb943f182e94",
|
||||
"scene_id": 42
|
||||
}
|
||||
```
|
||||
|
||||
### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"5w1h": {
|
||||
"who": ["Cary Grant"],
|
||||
"what": ["discussing plans"],
|
||||
"when": ["1963"],
|
||||
"where": ["Paris"],
|
||||
"why": ["vacation"],
|
||||
"how": ["in person"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## POST /api/v1/agents/5w1h/batch
|
||||
|
||||
Batch analyze all scenes in a file for 5W1H extraction. Uses the pipeline's `parent_chunk_5w1h.py --mode llm`.
|
||||
|
||||
### Request
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "3abeee81d94597629ed8cb943f182e94"
|
||||
}
|
||||
```
|
||||
|
||||
## GET /api/v1/agents/5w1h/status
|
||||
|
||||
Get status of the 5W1H agent pipeline for a file.
|
||||
|
||||
---
|
||||
|
||||
## Embedding Model
|
||||
|
||||
| Detail | Value |
|
||||
|--------|-------|
|
||||
| **Model** | EmbeddingGemma-300m |
|
||||
| **Endpoint** | `POST /v1/embeddings` on port 11436 |
|
||||
| **Dimension** | 768 |
|
||||
| **Used by** | `parent_chunk_5w1h.py --embed`, story, 5W1H, search |
|
||||
|
||||
---
|
||||
|
||||
## POST /api/v1/agents/search
|
||||
|
||||
Conversational search assistant. Uses Gemma4 function calling to automatically decide which tools to call based on the user's natural language query. Supports multi-turn conversation.
|
||||
|
||||
### Request
|
||||
|
||||
```json
|
||||
{
|
||||
"query": "Audrey Hepburn 和 Cary Grant 第一次同框在哪個 frame?",
|
||||
"conversation_id": null,
|
||||
"file_uuid": null
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `query` | string | ✅ | 自然語言查詢 |
|
||||
| `conversation_id` | string | ❌ | 延續對話時傳入;新對話不傳 |
|
||||
| `file_uuid` | string | ❌ | Portal 有選中檔案時可指定 |
|
||||
|
||||
### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"conversation_id": "conv_abc123",
|
||||
"answer": "在 Charade (1963) 中,Audrey Hepburn 與 Cary Grant 第一次同框在第 38619 幀(約 1544.76 秒)。",
|
||||
"need_input": false,
|
||||
"sources": [
|
||||
{
|
||||
"tool": "tkg_query",
|
||||
"result": "{\"first_cooccurrence\":{\"frame\":38619,\"timestamp_secs\":1544.76}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `conversation_id` | string | 後續對話需要傳入此 ID |
|
||||
| `answer` | string | Agent 的自然語言回答(或反問) |
|
||||
| `need_input` | boolean | `true` 表示 agent 需要更多資訊才能回答 |
|
||||
| `suggestions` | string[] | 建議用戶提供的線索(當 `need_input=true`) |
|
||||
| `sources` | array | 引用的工具執行結果 |
|
||||
|
||||
### Conversation Flow
|
||||
|
||||
```
|
||||
Round 1: POST /agents/search { query: "我想看男女主角同框" }
|
||||
→ need_input: true, suggestions: ["片名", "演員", "年代"]
|
||||
→ answer: "請問是哪部電影?請提供更多線索"
|
||||
|
||||
Round 2: POST /agents/search { query: "奧黛麗赫本", conversation_id: "..." }
|
||||
→ need_input: false
|
||||
→ answer: "找到 Charade (1963),Audrey Hepburn 和 Cary Grant..."
|
||||
```
|
||||
|
||||
### Available Tools
|
||||
|
||||
Agent 內部使用 Gemma4 function calling 自動調用以下工具:
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `find_file` | 透過片名/演員/年份關鍵字搜尋影片,回傳 file_uuid + has_data 狀態 |
|
||||
| `list_files` | 列出近期註冊的影片 |
|
||||
| `tkg_query` | 查詢人物互動資料(7 種子類型:top_identities、first_cooccurrence、identity_details、mutual_gaze、interaction_network、identity_traces、file_info) |
|
||||
| `smart_search` | 文字內容 ILIKE 搜尋 chunk(可指定 file_uuid 限制範圍) |
|
||||
| `get_identity_detail` | 查詢單一身份的詳細資料(角色、TMDb 資訊) |
|
||||
| `get_file_info` | 查詢影片基本資訊(片長、解析度) |
|
||||
| `get_representative_frame` | 查詢影片最具代表性的 frame 資訊 |
|
||||
|
||||
### Design Principles
|
||||
|
||||
- **用戶不需要知道 file_uuid** — Agent 會自動用 `find_file` 搜尋或反問
|
||||
- **不推薦無資料的影片** — `has_data=false` 的影片不會被推薦給用戶
|
||||
- **多輪對話** — 透過 `conversation_id` 延續上下文,agent 會記得之前的交流
|
||||
- **並行工具呼叫** — Gemma4 可以一次呼叫多個工具再綜合回答
|
||||
|
||||
### Model
|
||||
|
||||
| Detail | Value |
|
||||
|--------|-------|
|
||||
| **LLM** | Gemma4 26B (Q5_K_M) |
|
||||
| **Engine** | llama.cpp at `localhost:8082` |
|
||||
| **Endpoint** | `/v1/chat/completions` (OpenAI-compatible) |
|
||||
| **Temperature** | 0.1 |
|
||||
| **Max rounds** | 5 (tool call iterations) |
|
||||
| **Conversation TTL** | 30 minutes |
|
||||
|
||||
---
|
||||
*Updated: 2026-05-22*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,552 @@
|
||||
---
|
||||
title: tkg API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: tkg -->
|
||||
<!-- description: Temporal Knowledge Graph — rebuild, nodes, edges, processor counts -->
|
||||
<!-- depends: 05_process, 07_identity -->
|
||||
|
||||
## Temporal Knowledge Graph (TKG)
|
||||
|
||||
TKG is a time-aligned knowledge graph built from multi-processor outputs (face, yolo, ocr, pose, asrx, gaze, lip, appearance). It produces 9 node types and 14 edge types stored in `dev.tkg_nodes` and `dev.tkg_edges`.
|
||||
|
||||
**Node naming convention:** All trace types use `_track` suffix. Text uses `_region` (non-temporal).
|
||||
|
||||
**See also:** `docs_v1.0/DESIGN/TKG_FORMATION_V1.0.md` for formation phases, flow diagrams, and query examples.
|
||||
|
||||
### Node Types
|
||||
|
||||
| Node Type | External ID Format | Description | Key Properties |
|
||||
|-----------|-------------------|-------------|----------------|
|
||||
| `face_track` | `trace_{trace_id}` | A tracked face identity over time | `trace_id`, `frame_count`, `status`, `avg_bbox`, `avg_yaw`, `avg_pitch`, `avg_roll`, `start_frame`, `end_frame`, `pose_count` |
|
||||
| `gaze_track` | `gaze_track_{id}` | Gaze direction over time | `direction` (frontal/left/right/up/down + diagonals) |
|
||||
| `lip_track` | `lip_track_{id}` | Lip movement synced with speech | `speaker_id`, `lip_area_range` |
|
||||
| `text_region` | `text_region_{id}` | Spoken text aligned to time | `speaker_id`, `text`, `start_time`, `end_time` |
|
||||
| `appearance_trace` | `appearance_{trace_id}` | Human appearance (clothing) over time | `clothing_color`, `upper_cloth`, `lower_cloth` |
|
||||
| `accessory` | `accessory_{id}` | Detected accessories | `type` (glasses/hat/etc.), `confidence` |
|
||||
| `object` | `object_{class}_{id}` | YOLO-detected object | `class`, `confidence`, `frame_count` |
|
||||
| `speaker` | `speaker_{speaker_id}` | ASRX speaker segment | `speaker_id`, `segment_count`, `total_duration` |
|
||||
|
||||
---
|
||||
|
||||
### Identity Agent Integration (face_track nodes)
|
||||
|
||||
Identity Agent marks face_track nodes with identity binding status.
|
||||
|
||||
#### face_track Status Values
|
||||
|
||||
| Status | Description | Properties |
|
||||
|--------|-------------|------------|
|
||||
| `pending` | No identity suggestion | Default state |
|
||||
| `suggested` | Identity Agent suggested | `pending_identity_name`, `pending_identity_uuid`, `suggested_by`, `confidence` |
|
||||
| `confirmed` | User confirmed binding | `identity_uuid`, `identity_id`, `identity_ref`, `identity_name` |
|
||||
| `stranger` | Stranger cluster member | `stranger_id`, `stranger_ref` |
|
||||
|
||||
#### Suggested By Values
|
||||
|
||||
| Value | Description |
|
||||
|-------|-------------|
|
||||
| `tmdb` | TMDb seed matched |
|
||||
| `propagation` | Confirmed trace propagation |
|
||||
| `manual` | User manual selection |
|
||||
|
||||
#### Example face_track Node
|
||||
|
||||
```json
|
||||
{
|
||||
"node_type": "face_track",
|
||||
"external_id": "face_track_1",
|
||||
"label": "Face Track 1",
|
||||
"properties": {
|
||||
"trace_id": 1,
|
||||
"frame_count": 45,
|
||||
"start_frame": 100,
|
||||
"end_frame": 300,
|
||||
"avg_bbox": {"x": 100, "y": 200, "width": 80, "height": 100},
|
||||
"status": "suggested",
|
||||
"pending_identity_name": "Tom Hanks",
|
||||
"pending_identity_uuid": "xxx-xxx",
|
||||
"suggested_by": "tmdb",
|
||||
"confidence": 0.91
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Edge Types
|
||||
|
||||
| Edge Type | Storage Name | Source → Target | Description |
|
||||
|-----------|--------------|-----------------|-------------|
|
||||
| `co_occurs` | `CO_OCCURS_WITH` | object ↔ object | Two objects appear together in same frame |
|
||||
| `speaker_face` | `SPEAKS_AS` | speaker → face_track | Speaker matched to face track via lip sync |
|
||||
| `face_face` | `INTERACTS_WITH` | face_track ↔ face_track | Two face tracks interact (mutual gaze) |
|
||||
| `mutual_gaze` | `MUTUAL_GAZE` | gaze_track ↔ gaze_track | Two people looking at each other |
|
||||
| `lip_sync` | `LIP_SYNC` | lip_track → text_region | Lip movement aligned with spoken text |
|
||||
| `has_appearance` | `HAS_APPEARANCE` | face_track → appearance_trace | Face has specific appearance |
|
||||
| `wears` | `WEARS` | face_track → accessory | Face wears an accessory |
|
||||
| `hand_object` | `HOLDS` | hand → object | Hand holding object |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/tkg/rebuild`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Rebuild the Temporal Knowledge Graph for a file. Reads processor JSON outputs (face, yolo, ocr, pose, asrx, gaze, lip, appearance) and generates TKG nodes and edges. Clears existing nodes/edges for the file first, then rebuilds from scratch.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tkg/rebuild" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"result": {
|
||||
"face_track_nodes": 16,
|
||||
"gaze_track_nodes": 16,
|
||||
"lip_track_nodes": 12,
|
||||
"text_region_nodes": 24,
|
||||
"appearance_trace_nodes": 8,
|
||||
"skin_tone_trace_nodes": 5,
|
||||
"accessory_nodes": 3,
|
||||
"object_nodes": 26,
|
||||
"speaker_nodes": 4,
|
||||
"co_occurrence_edges": 94,
|
||||
"speaker_face_edges": 12,
|
||||
"face_face_edges": 8,
|
||||
"mutual_gaze_edges": 2,
|
||||
"lip_sync_edges": 10,
|
||||
"has_appearance_edges": 16,
|
||||
"wears_edges": 3
|
||||
},
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | True if rebuild completed |
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `result` | object | Node and edge counts by type |
|
||||
| `error` | string/null | Error message if failed |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/tkg/nodes`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Query TKG nodes with pagination and optional type filter.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `node_type` | string | No | all | Filter by node type: `face_track`, `gaze_track`, `lip_track`, `text_region`, `appearance_trace`, `skin_tone_trace`, `accessory`, `object`, `speaker` |
|
||||
| `page` | integer | No | 1 | Page number |
|
||||
| `page_size` | integer | No | 100 | Items per page (max 500) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get all face_track nodes
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tkg/nodes" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"node_type": "face_track", "page": 1, "page_size": 50}'
|
||||
|
||||
# Get all nodes
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tkg/nodes" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"total": 16,
|
||||
"page": 1,
|
||||
"page_size": 50,
|
||||
"nodes": [
|
||||
{
|
||||
"id": 1,
|
||||
"node_type": "face_track",
|
||||
"external_id": "face_track_0",
|
||||
"label": "Face Track 0",
|
||||
"properties": {
|
||||
"trace_id": 0,
|
||||
"frame_count": 142,
|
||||
"avg_confidence": 0.87,
|
||||
"best_confidence": 0.92,
|
||||
"avg_capture_quality": 0.61,
|
||||
"best_capture_quality": 0.78,
|
||||
"key_frame": 120,
|
||||
"key_face": "tkg:face/0:point_xyz",
|
||||
"avg_bbox": {"x": 200, "y": 150, "width": 60, "height": 60},
|
||||
"best_bbox": {"x": 210, "y": 155, "width": 62, "height": 60}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Always true on 200 |
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `total` | integer | Total matching node count |
|
||||
| `page` | integer | Current page |
|
||||
| `page_size` | integer | Items per page |
|
||||
| `nodes` | array | Array of node objects |
|
||||
| `nodes[].id` | integer | Database primary key |
|
||||
| `nodes[].node_type` | string | Node type (see table above) |
|
||||
| `nodes[].external_id` | string | External identifier (e.g., `trace_0`, `gaze_1`) |
|
||||
| `nodes[].label` | string | Human-readable label |
|
||||
| `nodes[].properties` | object | Type-specific properties as JSON |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/tkg/edges`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Query TKG edges with pagination and optional filters.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `edge_type` | string | No | all | Filter by edge type: `co_occurs`, `speaker_face`, `face_face`, `mutual_gaze`, `lip_sync`, `has_appearance`, `wears` |
|
||||
| `source_type` | string | No | — | Filter by source node type |
|
||||
| `target_type` | string | No | — | Filter by target node type |
|
||||
| `page` | integer | No | 1 | Page number |
|
||||
| `page_size` | integer | No | 100 | Items per page (max 500) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get all co_occurs edges
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tkg/edges" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"edge_type": "co_occurs"}'
|
||||
|
||||
# Get edges between face_track and speaker nodes
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tkg/edges" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"source_type": "speaker", "target_type": "face_track"}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"total": 94,
|
||||
"page": 1,
|
||||
"page_size": 100,
|
||||
"edges": [
|
||||
{
|
||||
"id": 1,
|
||||
"edge_type": "co_occurs",
|
||||
"source_node_id": 10,
|
||||
"target_node_id": 15,
|
||||
"properties": {
|
||||
"frame_count": 45,
|
||||
"confidence": 0.92
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Always true on 200 |
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `total` | integer | Total matching edge count |
|
||||
| `page` | integer | Current page |
|
||||
| `page_size` | integer | Items per page |
|
||||
| `edges` | array | Array of edge objects |
|
||||
| `edges[].id` | integer | Database primary key |
|
||||
| `edges[].edge_type` | string | Edge type |
|
||||
| `edges[].source_node_id` | integer | Source node ID (FK to tkg_nodes) |
|
||||
| `edges[].target_node_id` | integer | Target node ID (FK to tkg_nodes) |
|
||||
| `edges[].properties` | object | Edge-specific properties as JSON |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/tkg/node/:node_id`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get detail for a specific TKG node including its connected edges.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/tkg/node/1" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"node": {
|
||||
"id": 1,
|
||||
"node_type": "face_track",
|
||||
"external_id": "face_track_0",
|
||||
"label": "Face Track 0",
|
||||
"properties": {
|
||||
"trace_id": 0,
|
||||
"frame_count": 142,
|
||||
"avg_confidence": 0.87
|
||||
}
|
||||
},
|
||||
"connected_edges": [
|
||||
{
|
||||
"id": 5,
|
||||
"edge_type": "co_occurs",
|
||||
"source_node_id": 1,
|
||||
"target_node_id": 10,
|
||||
"properties": {"frame_count": 45}
|
||||
}
|
||||
],
|
||||
"edge_count": 3
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Always true on 200 |
|
||||
| `node` | object | Node detail (same format as nodes query) |
|
||||
| `connected_edges` | array | Edges connected to this node |
|
||||
| `edge_count` | integer | Total connected edge count |
|
||||
|
||||
#### Error Codes
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | Node not found |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/processor-counts`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Get counts of processor JSON output files for a file. Scans the output directory for `{file_uuid}.{processor}.json` files and extracts frame counts, segment counts, and chunk counts from each file.
|
||||
|
||||
Supports short UUID prefix matching (e.g., `d3f9ae8e` → resolves to full `d3f9ae8e471a1fc4d47022c66091b920`).
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/processor-counts" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"output_dir": "/Users/accusys/momentry/output_dev",
|
||||
"processors": [
|
||||
{
|
||||
"processor": "cut",
|
||||
"has_json": true,
|
||||
"frame_count": 5391,
|
||||
"segment_count": null,
|
||||
"chunk_count": null,
|
||||
"last_modified": "2026-06-16T18:48:01.987241061+00:00"
|
||||
},
|
||||
{
|
||||
"processor": "face",
|
||||
"has_json": true,
|
||||
"frame_count": 1112,
|
||||
"segment_count": null,
|
||||
"chunk_count": null,
|
||||
"last_modified": "2026-06-18T17:21:37.408383765+00:00"
|
||||
},
|
||||
{
|
||||
"processor": "asrx",
|
||||
"has_json": true,
|
||||
"frame_count": null,
|
||||
"segment_count": 6,
|
||||
"chunk_count": null,
|
||||
"last_modified": "2026-06-18T17:21:40.872063642+00:00"
|
||||
},
|
||||
{
|
||||
"processor": "story",
|
||||
"has_json": true,
|
||||
"frame_count": null,
|
||||
"segment_count": null,
|
||||
"chunk_count": 12,
|
||||
"last_modified": "2026-06-18T17:22:00.000000000+00:00"
|
||||
},
|
||||
{
|
||||
"processor": "mediapipe",
|
||||
"has_json": false,
|
||||
"frame_count": null,
|
||||
"segment_count": null,
|
||||
"chunk_count": null,
|
||||
"last_modified": null
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | Full 32-char hex UUID (resolved from prefix) |
|
||||
| `output_dir` | string | Output directory scanned |
|
||||
| `processors` | array | Per-processor output info |
|
||||
| `processors[].processor` | string | Processor name |
|
||||
| `processors[].has_json` | boolean | Whether JSON file exists |
|
||||
| `processors[].frame_count` | integer/null | Total frames processed (frame-based processors) |
|
||||
| `processors[].segment_count` | integer/null | Segment count (ASRX segments, etc.) |
|
||||
| `processors[].chunk_count` | integer/null | Chunk count (Story chunks, etc.) |
|
||||
| `processors[].last_modified` | string/null | ISO 8601 timestamp of last modification |
|
||||
|
||||
#### Error Codes
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | File UUID not found in database |
|
||||
|
||||
---
|
||||
|
||||
### Trace Management
|
||||
|
||||
Endpoints for managing face traces: list, delete, restore, and merge.
|
||||
|
||||
#### `DELETE /api/v1/file/:file_uuid/trace/:trace_id`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
Soft-delete a face trace (default) or hard-delete with `{"hard_delete": true}`.
|
||||
|
||||
Soft delete marks Qdrant points with `status: "deleted"` and TKG nodes with `status: "deleted"` in properties. Deleted traces are excluded from the traces list.
|
||||
|
||||
Hard delete permanently removes Qdrant points and TKG nodes.
|
||||
|
||||
**Request Body** (optional):
|
||||
|
||||
| Field | Type | Default | Description |
|
||||
|-------|------|---------|-------------|
|
||||
| `hard_delete` | boolean | `false` | Permanently delete instead of marking |
|
||||
|
||||
**Example**:
|
||||
```bash
|
||||
# Soft delete
|
||||
curl -X DELETE "$API/api/v1/file/$FILE_UUID/trace/8" \
|
||||
-H "X-API-Key: $KEY" -H "Content-Type: application/json" -d '{}'
|
||||
|
||||
# Hard delete
|
||||
curl -X DELETE "$API/api/v1/file/$FILE_UUID/trace/8" \
|
||||
-H "X-API-Key: $KEY" -H "Content-Type: application/json" \
|
||||
-d '{"hard_delete": true}'
|
||||
```
|
||||
|
||||
**Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "9f6a9cd55a5809f977f5a6589b9045c5",
|
||||
"trace_id": 8,
|
||||
"hard_delete": false,
|
||||
"qdrant_marked": true,
|
||||
"tkg_nodes_marked": 1
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### `POST /api/v1/file/:file_uuid/trace/:trace_id/restore`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
Undo a soft-deleted trace. Clears `status: "deleted"` from Qdrant points and TKG node properties.
|
||||
|
||||
**Example**:
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/trace/8/restore" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
**Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "9f6a9cd55a5809f977f5a6589b9045c5",
|
||||
"trace_id": 8,
|
||||
"qdrant_restored": true,
|
||||
"tkg_nodes_restored": 1
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### `POST /api/v1/file/:file_uuid/trace/:source_trace_id/merge/:target_trace_id`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
Merge all face points from source trace into target trace. Updates Qdrant `trace_id` and deletes source TKG node.
|
||||
|
||||
**Example**:
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/trace/16/merge/3" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
**Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "9f6a9cd55a5809f977f5a6589b9045c5",
|
||||
"source_trace_id": 16,
|
||||
"target_trace_id": 3,
|
||||
"points_moved": 58,
|
||||
"tkg_nodes_deleted": 1
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*Updated: 2026-07-21 01:00:00*
|
||||
*Updated: 2026-08-12 — face_track node properties now include capture_quality fields (avg/best) and key_frame/key_face are selected by best capture quality*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,375 @@
|
||||
---
|
||||
title: Trace Agent API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: trace_agent -->
|
||||
<!-- description: Face trace and TKG (Temporal Knowledge Graph) operations -->
|
||||
<!-- depends: identity, profile -->
|
||||
|
||||
# Trace Agent API
|
||||
|
||||
Manage face traces, temporal knowledge graphs, and trace-related operations.
|
||||
|
||||
## Overview
|
||||
|
||||
Trace Agent API provides endpoints for:
|
||||
- **Trace Management**: List, query, and analyze face traces
|
||||
- **Face Retrieval**: Get faces from traces, representative faces
|
||||
- **Thumbnails**: Generate and retrieve trace thumbnails
|
||||
- **TKG Operations**: Build, query, and manage Temporal Knowledge Graphs
|
||||
- **Co-occurrence**: Analyze identity co-occurrence in videos
|
||||
|
||||
## Endpoints
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/traces`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
List all traces for a file, sorted by various criteria.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `file_uuid` | string | Yes | — | File UUID (path parameter) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# List traces for a file
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/traces" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"traces": [
|
||||
{
|
||||
"trace_id": 1,
|
||||
"face_count": 50,
|
||||
"first_frame": 100,
|
||||
"last_frame": 1500,
|
||||
"identity_uuid": "a9a90105-..."
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/trace/:trace_id/faces`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Get all faces for a specific trace.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
| `trace_id` | number | Yes | Trace ID |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get faces for trace 1
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/trace/1/faces" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/trace/:trace_id/representative-face`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Get the representative (best quality) face for a trace.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get representative face
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/trace/1/representative-face" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/trace/:trace_id/thumbnail`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Get thumbnail for a trace.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get trace thumbnail
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/trace/1/thumbnail" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/stranger/:stranger_id/representative-face`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Get representative face for a stranger (unidentified person).
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get stranger representative face
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/stranger/1/representative-face" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/stranger/:stranger_id/thumbnail`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Get thumbnail for a stranger.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get stranger thumbnail
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/stranger/1/thumbnail" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/identities/:identity_uuid_a/co-occur-with/:identity_uuid_b`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Get co-occurrence information between two identities in a file.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `file_uuid` | string | Yes | File UUID |
|
||||
| `identity_uuid_a` | string | Yes | First identity UUID |
|
||||
| `identity_uuid_b` | string | Yes | Second identity UUID |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Check co-occurrence
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/identities/$IDENTITY_UUID_A/co-occur-with/$IDENTITY_UUID_B" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/tkg/rebuild`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Rebuild Temporal Knowledge Graph for a file.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Rebuild TKG
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tkg/rebuild" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/tkg`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Get TKG operations for a file.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get TKG operations
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/tkg" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `DELETE /api/v1/file/:file_uuid/tkg`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Delete TKG for a file.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Delete TKG
|
||||
curl -s -X DELETE "$API/api/v1/file/$FILE_UUID/tkg" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/rule2`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Ingest Rule 2 for TKG.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Ingest Rule 2
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/rule2" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/representative-frame`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Get representative frame for a file.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get representative frame
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/representative-frame" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/tkg/nodes`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Query TKG nodes.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Query TKG nodes
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tkg/nodes" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/tkg/edges`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: file-level
|
||||
|
||||
Query TKG edges.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Query TKG edges
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/tkg/edges" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Implementation Details
|
||||
|
||||
**File**: `/Users/accusys/momentry_core/src/api/trace_agent_api.rs` (2918 lines)
|
||||
|
||||
**Data Structures**:
|
||||
- `Trace` - Face trace object
|
||||
- `Face` - Single face detection
|
||||
- `TKG` - Temporal Knowledge Graph
|
||||
- `Stranger` - Unidentified person
|
||||
|
||||
**Database Tables**:
|
||||
- `face_detections` - Face detection records
|
||||
- `traces` - Trace metadata
|
||||
- `tkg_nodes` - TKG nodes
|
||||
- `tkg_edges` - TKG edges
|
||||
|
||||
---
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- [Identity API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/07_identity.md)
|
||||
- [Profile API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/18_profile.md)
|
||||
- [TKG API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/15_tkg.md)
|
||||
|
||||
---
|
||||
|
||||
## Common Issues
|
||||
|
||||
### Trace Not Found
|
||||
|
||||
**Symptoms**: 404 error when accessing trace
|
||||
|
||||
**Solution**: Check if trace exists in database or re-process the file
|
||||
|
||||
### TKG Build Failed
|
||||
|
||||
**Symptoms**: TKG rebuild returns error
|
||||
|
||||
**Solution**: Check file processing status and logs
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation (summary) |
|
||||
|
||||
**Note**: This is a summary documentation. Full endpoint details require additional work.
|
||||
@@ -0,0 +1,245 @@
|
||||
---
|
||||
title: Cluster Agent API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-25
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: cluster_agent -->
|
||||
<!-- description: Asynchronous face clustering agent -->
|
||||
<!-- depends: 01_auth, 03_register, 07_identity -->
|
||||
|
||||
## Cluster Agent
|
||||
|
||||
Asynchronous face clustering agent that automatically groups similar faces into identities. Runs as a background job.
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/cluster-agent`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Trigger asynchronous face clustering for a file. Returns immediately with a job ID. Clustering runs in the background.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `file_uuid` | string | File UUID (32-char hex) |
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `confirm` | boolean | Yes | false | Must be `true` to trigger clustering |
|
||||
| `min_confidence` | float | No | 0.6 | Minimum face confidence to include |
|
||||
| `algorithm` | string | No | "dbscan" | Clustering algorithm ("dbscan", "kmeans") |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/cluster-agent" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"confirm": true, "min_confidence": 0.6}'
|
||||
```
|
||||
|
||||
#### Response (202 Accepted)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"job_id": "cluster_abc123",
|
||||
"file_uuid": "3a6c1865...",
|
||||
"status": "queued",
|
||||
"message": "Cluster job queued for processing"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Always true on 202 |
|
||||
| `job_id` | string | Job ID for status tracking |
|
||||
| `file_uuid` | string | File UUID |
|
||||
| `status` | string | Job status ("queued", "running", "completed", "failed") |
|
||||
| `message` | string | Human-readable status |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `400` | `confirm` not set to `true` |
|
||||
| `404` | File not found |
|
||||
| `409` | Job already running for this file |
|
||||
| `401` | Missing or invalid API key |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/cluster-job/:job_id`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: job-level
|
||||
|
||||
Get status of a cluster job. Returns progress, statistics, and results if completed.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `job_id` | string | Job ID returned from trigger endpoint |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/cluster-job/cluster_abc123" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"job_id": "cluster_abc123",
|
||||
"file_uuid": "3a6c1865...",
|
||||
"status": "completed",
|
||||
"progress": {
|
||||
"total_faces": 1523,
|
||||
"processed": 1523,
|
||||
"percentage": 100
|
||||
},
|
||||
"result": {
|
||||
"clusters_found": 12,
|
||||
"identities_created": 8,
|
||||
"identities_updated": 4
|
||||
},
|
||||
"started_at": "2026-10-25T10:00:00Z",
|
||||
"completed_at": "2026-10-25T10:05:30Z"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `job_id` | string | Job ID |
|
||||
| `file_uuid` | string | File UUID |
|
||||
| `status` | string | "running", "completed", "failed", "cancelled" |
|
||||
| `progress` | object | Progress information |
|
||||
| `result` | object | Final results (if completed) |
|
||||
| `error` | string | Error message (if failed) |
|
||||
| `started_at` | string | ISO 8601 timestamp |
|
||||
| `completed_at` | string | ISO 8601 timestamp (if completed) |
|
||||
|
||||
---
|
||||
|
||||
### `DELETE /api/v1/cluster-job/:job_id`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: job-level
|
||||
|
||||
Cancel a running cluster job. Cannot cancel completed or failed jobs.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `job_id` | string | Job ID |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X DELETE "$API/api/v1/cluster-job/cluster_abc123" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"job_id": "cluster_abc123",
|
||||
"status": "cancelled",
|
||||
"message": "Job cancelled successfully"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Clustering Process
|
||||
|
||||
### How It Works
|
||||
|
||||
1. **Face Collection**: Gather all face detections from the file
|
||||
2. **Embedding Extraction**: Get face embeddings (512-dim vectors)
|
||||
3. **Similarity Clustering**: Group similar faces using DBSCAN
|
||||
4. **Identity Assignment**: Create or update identities for clusters
|
||||
5. **Face Binding**: Bind faces to their cluster identity
|
||||
|
||||
### Clustering Algorithm
|
||||
|
||||
**DBSCAN Parameters**:
|
||||
- `eps`: 0.3 (distance threshold)
|
||||
- `min_samples`: 5 (minimum cluster size)
|
||||
|
||||
**Quality Metrics**:
|
||||
- Intra-cluster similarity: Average pairwise similarity within cluster
|
||||
- Inter-cluster separation: Average distance to nearest cluster
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. Automatic Identity Creation
|
||||
|
||||
```bash
|
||||
# After processing, trigger clustering
|
||||
curl -X POST "$API/api/v1/file/$FILE_UUID/cluster-agent" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"confirm": true}'
|
||||
```
|
||||
|
||||
### 2. Monitor Clustering Progress
|
||||
|
||||
```bash
|
||||
# Poll job status
|
||||
curl -s "$API/api/v1/cluster-job/$JOB_ID" -H "X-API-Key: $KEY" | jq '.status'
|
||||
```
|
||||
|
||||
### 3. Cancel Slow Clustering
|
||||
|
||||
```bash
|
||||
# If clustering takes too long
|
||||
curl -X DELETE "$API/api/v1/cluster-job/$JOB_ID" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Performance
|
||||
|
||||
| File Size | Face Count | Processing Time |
|
||||
|-----------|------------|-----------------|
|
||||
| 10 min video | 500 faces | ~30 seconds |
|
||||
| 30 min video | 1500 faces | ~2 minutes |
|
||||
| 90 min video | 4500 faces | ~8 minutes |
|
||||
|
||||
**Notes**:
|
||||
- Processing time scales linearly with face count
|
||||
- Uses in-memory job registry (cleared on server restart)
|
||||
- Concurrent jobs are supported but resource-intensive
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Error | Cause | Solution |
|
||||
|-------|-------|----------|
|
||||
| `400 Bad Request` | `confirm` not set | Add `"confirm": true` to request body |
|
||||
| `404 Not Found` | File not found | Verify file_uuid |
|
||||
| `409 Conflict` | Job already running | Wait for current job to complete or cancel it |
|
||||
| `500 Internal Error` | Clustering failed | Check server logs for details |
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-25 | Initial documentation |
|
||||
@@ -0,0 +1,78 @@
|
||||
---
|
||||
title: error codes API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: error_codes -->
|
||||
<!-- description: Standard API error codes -->
|
||||
<!-- depends: -->
|
||||
|
||||
## Error Response Format
|
||||
|
||||
All API errors follow this JSON structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"error": {
|
||||
"code": "E001_NOT_FOUND",
|
||||
"message": "Resource not found",
|
||||
"details": {"resource": "file_uuid", "value": "abc"}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Error Code List
|
||||
|
||||
### Generic Errors (E0xx)
|
||||
|
||||
| Code | HTTP | Description |
|
||||
|------|------|-------------|
|
||||
| `E001_NOT_FOUND` | 404 | Resource not found (file, identity, chunk) |
|
||||
| `E002_DUPLICATE` | 409 | Resource already exists |
|
||||
| `E003_VALIDATION` | 400 | Request parameter validation failed |
|
||||
| `E004_UNAUTHORIZED` | 401 | Invalid API key or token |
|
||||
| `E005_INTERNAL` | 500 | Internal server error |
|
||||
|
||||
### Processor Errors (E1xx)
|
||||
|
||||
| Code | HTTP | Description |
|
||||
|------|------|-------------|
|
||||
| `E101_PROCESSOR_FAIL` | 500 | Python script execution failed |
|
||||
| `E102_TIMEOUT` | 504 | Processing timeout |
|
||||
| `E103_RESUME_FAIL` | 500 | Resume failed (checkpoint not found) |
|
||||
| `E104_NO_VIDEO` | 400 | Video file path not found |
|
||||
|
||||
### Identity Errors (E2xx)
|
||||
|
||||
| Code | HTTP | Description |
|
||||
|------|------|-------------|
|
||||
| `E201_FACE_NOT_FOUND` | 404 | Face detection not found |
|
||||
| `E202_MERGE_CONFLICT` | 409 | Identity merge conflict |
|
||||
| `E203_CANDIDATE_EMPTY` | 404 | No candidates available for confirmation |
|
||||
|
||||
### TMDb Errors (E3xx)
|
||||
|
||||
| Code | HTTP | Description |
|
||||
|------|------|-------------|
|
||||
| `E301_TMDB_NO_KEY` | 400 | `TMDB_API_KEY` environment variable not set |
|
||||
| `E302_TMDB_UNREACHABLE` | 502 | TMDb API unreachable or timed out |
|
||||
| `E303_TMDB_CACHE_NOT_FOUND` | 200 | No local TMDb cache; run prefetch first |
|
||||
| `E304_TMDB_PROBE_FAILED` | 500 | TMDb probe execution failed |
|
||||
| `E305_TMDB_MOVIE_NOT_FOUND` | 404 | No matching TMDb movie found from filename |
|
||||
|
||||
---
|
||||
*Updated: 2026-05-19 12:49:24*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,108 @@
|
||||
---
|
||||
title: config API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: config -->
|
||||
<!-- description: System configuration — cache, auto-pipeline, watcher-auto-register toggles -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## System Configuration
|
||||
|
||||
Runtime configuration toggles for system behavior. All endpoints require authentication and system-level scope.
|
||||
|
||||
### `POST /api/v1/config/cache`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Toggle the Redis cache on or off.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `enabled` | boolean | Yes | `true` to enable, `false` to disable |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/config/cache" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"enabled": false}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/config/auto-pipeline`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Toggle automatic processing pipeline trigger on file registration (disabled by default).
|
||||
When enabled, registering a video file automatically creates a monitor job and starts processing.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `enabled` | boolean | Yes | `true` to enable auto-pipeline, `false` to disable |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Enable auto-pipeline
|
||||
curl -s -X POST "$API/api/v1/config/auto-pipeline" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"enabled": true}'
|
||||
|
||||
# Disable auto-pipeline
|
||||
curl -s -X POST "$API/api/v1/config/auto-pipeline" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"enabled": false}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/config/watcher-auto-register`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Toggle automatic registration of newly detected files in the watcher (disabled by default).
|
||||
When enabled, the file watcher automatically pre-processes and registers new files into the database.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `enabled` | boolean | Yes | `true` to enable watcher auto-register, `false` to disable |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Enable watcher auto-register
|
||||
curl -s -X POST "$API/api/v1/config/watcher-auto-register" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{"enabled": true}'
|
||||
```
|
||||
|
||||
---
|
||||
*Updated: 2026-05-19 12:49:24*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,166 @@
|
||||
---
|
||||
title: workspace API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: workspace -->
|
||||
<!-- description: Workspace checkout/checkin — lock, clear, restore file data -->
|
||||
<!-- depends: 04_lookup, 05_process -->
|
||||
|
||||
## Workspace Checkin/Checkout
|
||||
|
||||
Workspace checkin/checkout provides a transactional editing model for file data:
|
||||
- **Checkout**: Clears PG tables (face_detections, speaker_detections, pre_chunks) and Qdrant vectors, creating an isolated workspace SQLite for editing.
|
||||
- **Checkin**: Restores data from the workspace SQLite back to PG and Qdrant, marking the file as `Indexed`.
|
||||
|
||||
This allows safe concurrent editing — while a file is checked out, its main database records are cleared, preventing conflicts.
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/checkout`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Checkout a file workspace. Clears face detections, speaker detections, pre_chunks from PostgreSQL, deletes Qdrant vectors, and creates a workspace SQLite database for isolated editing.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/checkout" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"rows_deleted": 1523,
|
||||
"status": "checked_out"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `rows_deleted` | integer | Total rows cleared from PG tables |
|
||||
| `status` | string | `"checked_out"` |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `500` | Checkout failed (DB error, workspace creation error) |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/file/:file_uuid/checkin`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Checkin a file workspace. Restores face detections, speaker detections, pre_chunks from workspace SQLite back to PostgreSQL, re-indexes vectors to Qdrant, and sets video status to `Indexed`.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/file/$FILE_UUID/checkin" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"pre_chunks_moved": 45,
|
||||
"face_detections_moved": 1200,
|
||||
"speaker_detections_moved": 320,
|
||||
"vectors_moved": 45,
|
||||
"status": "indexed"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `pre_chunks_moved` | integer | Pre-chunks restored from workspace |
|
||||
| `face_detections_moved` | integer | Face detections restored from workspace |
|
||||
| `speaker_detections_moved` | integer | Speaker detections restored from workspace |
|
||||
| `vectors_moved` | integer | Vectors re-indexed to Qdrant |
|
||||
| `status` | string | `"indexed"` |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `500` | Checkin failed (DB error, workspace not found, vector index error) |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/file/:file_uuid/workspace`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: file-level
|
||||
|
||||
Check if a workspace SQLite database exists for a file.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/file/$FILE_UUID/workspace" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "d3f9ae8e471a1fc4d47022c66091b920",
|
||||
"exists": true
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `file_uuid` | string | 32-char hex UUID |
|
||||
| `exists` | boolean | True if workspace SQLite exists |
|
||||
|
||||
---
|
||||
|
||||
### Workflow
|
||||
|
||||
```
|
||||
REGISTERED ──→ CHECKED_OUT ──→ INDEXED
|
||||
│ │ │
|
||||
│ checkout checkin
|
||||
│ │ │
|
||||
│ clear PG + Qdrant restore from SQLite
|
||||
│ create workspace re-index vectors
|
||||
│ set status set status
|
||||
```
|
||||
|
||||
1. **Register** file → status: `REGISTERED`
|
||||
2. **Process** file → processors run, data stored in PG + Qdrant
|
||||
3. **Checkout** file → clear editable data, create workspace SQLite → status: `CHECKED_OUT`
|
||||
4. **Edit** workspace via Agent Search / identity binding
|
||||
5. **Checkin** file → restore from workspace SQLite → status: `INDEXED`
|
||||
6. **Rebuild TKG** if needed after checkin
|
||||
|
||||
---
|
||||
|
||||
*Updated: 2026-06-20 12:00:00*
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,389 @@
|
||||
---
|
||||
title: Service Management API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: service_management -->
|
||||
<!-- description: Service lifecycle management endpoints -->
|
||||
<!-- depends: health -->
|
||||
|
||||
# Service Management API
|
||||
|
||||
Manage Momentry core services, including start, stop, and health check operations.
|
||||
|
||||
## Overview
|
||||
|
||||
Service Management API provides endpoints for:
|
||||
- **Start Service**: Launch inference services (e.g., MBE)
|
||||
- **Stop Service**: Terminate running services
|
||||
- **Health Check**: Monitor service status
|
||||
|
||||
## Endpoints
|
||||
|
||||
### `POST /api/v2/service/start`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: system-level
|
||||
|
||||
Start a Momentry service.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `name` | string | Yes | — | Service name (e.g., `"mbe"`) |
|
||||
| `model` | string | No | — | Model path or name |
|
||||
| `port` | number | No | 8080 | Service port |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Start MBE service with default model
|
||||
curl -s -X POST "$API/api/v2/service/start" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "mbe"}'
|
||||
```
|
||||
|
||||
```bash
|
||||
# Start MBE service with custom model and port
|
||||
curl -s -X POST "$API/api/v2/service/start" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "mbe",
|
||||
"model": "/Users/accusys/models/gemma-4-12b-it-Q4_K_M.gguf",
|
||||
"port": 8080
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"result": "started",
|
||||
"pid": 12345
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `result` | string | `"started"` or `"failed"` |
|
||||
| `pid` | number | Process ID if successful |
|
||||
| `error` | string | Error message if failed |
|
||||
|
||||
#### Implementation Details
|
||||
|
||||
**File**: `/Users/accusys/momentry_core/src/api/service_management.rs`
|
||||
|
||||
**Process**:
|
||||
1. Validates service name (currently only `"mbe"` supported)
|
||||
2. Checks if port is already in use
|
||||
3. Stops existing process on that port
|
||||
4. Spawns llama-server with specified model
|
||||
5. Waits up to 60 seconds for service to be ready
|
||||
6. Returns process ID on success
|
||||
|
||||
**Supported Services**:
|
||||
- `"mbe"` - MarkBase Engine (llama.cpp server)
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v2/service/stop`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: system-level
|
||||
|
||||
Stop a running service.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `name` | string | Yes | — | Service name (e.g., `"mbe"`) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Stop MBE service
|
||||
curl -s -X POST "$API/api/v2/service/stop" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "mbe"}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
**Success**:
|
||||
```json
|
||||
{
|
||||
"result": "stopped"
|
||||
}
|
||||
```
|
||||
|
||||
**Failure**:
|
||||
```json
|
||||
{
|
||||
"result": "failed",
|
||||
"error": "No service running on port 8080"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `result` | string | `"stopped"` or `"failed"` |
|
||||
| `error` | string | Error message if failed |
|
||||
|
||||
#### Implementation Details
|
||||
|
||||
**File**: `/Users/accusys/momentry_core/src/api/service_management.rs`
|
||||
|
||||
**Process**:
|
||||
1. Validates service name
|
||||
2. Finds process ID by port (8080)
|
||||
3. Sends kill signal
|
||||
4. Returns success/failure
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/mbe/health`
|
||||
|
||||
**Auth**: Public
|
||||
|
||||
**Scope**: system-level
|
||||
|
||||
Check MBE (MarkBase Engine) health status.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Check MBE health
|
||||
curl -s "$API/api/v1/mbe/health"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
**Online**:
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"model": "gemma-4-12b-it-Q4_K_M.gguf",
|
||||
"uptime": 3600
|
||||
}
|
||||
```
|
||||
|
||||
**Offline**:
|
||||
```json
|
||||
{
|
||||
"status": "offline"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `status` | string | `"ok"` or `"offline"` |
|
||||
| `model` | string | Model name if online |
|
||||
| `uptime` | number | Uptime in seconds (currently always 0) |
|
||||
|
||||
#### Implementation Details
|
||||
|
||||
**File**: `/Users/accusys/momentry_core/src/api/service_management.rs`
|
||||
|
||||
**Process**:
|
||||
1. Checks if port 8080 is in use
|
||||
2. Calls `/v1/models` endpoint
|
||||
3. Extracts model name from response
|
||||
4. Returns health status
|
||||
|
||||
**Health Check Endpoint**: `http://127.0.0.1:8080/v1/models`
|
||||
|
||||
---
|
||||
|
||||
## Error Codes
|
||||
|
||||
| Code | HTTP | When |
|
||||
|------|------|------|
|
||||
| E401 | 401 | Missing or invalid API key |
|
||||
| E400 | 400 | Invalid service name |
|
||||
| E500 | 500 | Service start/stop failed |
|
||||
|
||||
---
|
||||
|
||||
## Usage Patterns
|
||||
|
||||
### Start Service → Check Health
|
||||
|
||||
```bash
|
||||
# Start MBE
|
||||
curl -s -X POST "$API/api/v2/service/start" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "mbe"}'
|
||||
|
||||
# Wait a few seconds
|
||||
sleep 5
|
||||
|
||||
# Check health
|
||||
curl -s "$API/api/v1/mbe/health"
|
||||
```
|
||||
|
||||
### Stop Service → Verify Stopped
|
||||
|
||||
```bash
|
||||
# Stop MBE
|
||||
curl -s -X POST "$API/api/v2/service/stop" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "mbe"}'
|
||||
|
||||
# Check health (should be offline)
|
||||
curl -s "$API/api/v1/mbe/health"
|
||||
```
|
||||
|
||||
### Restart Service
|
||||
|
||||
```bash
|
||||
# Stop if running
|
||||
curl -s -X POST "$API/api/v2/service/stop" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "mbe"}'
|
||||
|
||||
# Wait for cleanup
|
||||
sleep 3
|
||||
|
||||
# Start with new configuration
|
||||
curl -s -X POST "$API/api/v2/service/start" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "mbe", "port": 8080}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuration
|
||||
|
||||
### Default Settings
|
||||
|
||||
**MBE (llama-server)**:
|
||||
- **Port**: 8080
|
||||
- **Model**: `/Users/accusys/models/gemma-4-12b-it-Q4_K_M.gguf`
|
||||
- **mmproj**: `/Users/accusys/models/mmproj-F16.gguf`
|
||||
- **Binary**: `/Users/accusys/llama.cpp/build/bin/llama-server`
|
||||
|
||||
**Launch Parameters**:
|
||||
```bash
|
||||
llama-server \
|
||||
-m <model_path> \
|
||||
--mmproj <mmproj_path> \
|
||||
--host 0.0.0.0 \
|
||||
--port 8080 \
|
||||
-ngl 99 \
|
||||
-c 8192 \
|
||||
--temp 0.1 \
|
||||
-b 4096 \
|
||||
-ub 4096
|
||||
```
|
||||
|
||||
### Environment Variables
|
||||
|
||||
The start process sets:
|
||||
- `PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`
|
||||
|
||||
---
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- [Health API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/02_health.md)
|
||||
- [MarkBase Documentation](/Users/accusys/markbase/README.md)
|
||||
- [LLM Services Guide](/Users/accusys/momentry_core/docs_v1.0/OPERATIONS/LLM_SERVICES/)
|
||||
|
||||
---
|
||||
|
||||
## Common Issues
|
||||
|
||||
### Service Fails to Start
|
||||
|
||||
**Symptoms**: `{"result": "failed", "error": "..."}`
|
||||
|
||||
**Possible Causes**:
|
||||
1. Model file not found
|
||||
2. Port already in use by another process
|
||||
3. Insufficient permissions
|
||||
4. Binary not found
|
||||
|
||||
**Solution**:
|
||||
```bash
|
||||
# Check model file exists
|
||||
ls -la /Users/accusys/models/gemma-4-12b-it-Q4_K_M.gguf
|
||||
|
||||
# Check port availability
|
||||
lsof -i :8080
|
||||
|
||||
# Check binary exists
|
||||
ls -la /Users/accusys/llama.cpp/build/bin/llama-server
|
||||
```
|
||||
|
||||
### Health Check Returns "offline"
|
||||
|
||||
**Symptoms**: `{"status": "offline"}`
|
||||
|
||||
**Possible Causes**:
|
||||
1. Service not started
|
||||
2. Service crashed after startup
|
||||
3. Network/firewall issue
|
||||
|
||||
**Solution**:
|
||||
```bash
|
||||
# Start service
|
||||
curl -s -X POST "$API/api/v2/service/start" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "mbe"}'
|
||||
|
||||
# Check process status
|
||||
ps aux | grep llama-server
|
||||
|
||||
# Check logs
|
||||
tail -f ~/momentry_core/logs/momentry_3002.log
|
||||
```
|
||||
|
||||
### Service Keeps Restarting
|
||||
|
||||
**Symptoms**: PID changes frequently, service unstable
|
||||
|
||||
**Possible Causes**:
|
||||
1. Out of memory
|
||||
2. Model too large
|
||||
3. Hardware issue
|
||||
|
||||
**Solution**:
|
||||
```bash
|
||||
# Check memory usage
|
||||
top -pid $(pgrep -f llama-server)
|
||||
|
||||
# Try smaller model or reduce parameters
|
||||
curl -s -X POST "$API/api/v2/service/start" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "mbe", "model": "<smaller_model_path>"}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,399 @@
|
||||
---
|
||||
title: Monitor API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: monitor -->
|
||||
<!-- description: Queue/Worker/Pipeline monitoring endpoints -->
|
||||
<!-- depends: health -->
|
||||
|
||||
# Monitor API
|
||||
|
||||
Monitor Momentry's job queue, worker status, and processing pipeline in real-time.
|
||||
|
||||
## Overview
|
||||
|
||||
Monitor API provides endpoints for:
|
||||
- **Queue Statistics**: Job counts by status
|
||||
- **Running Jobs**: Detailed view of active jobs with processor progress
|
||||
- **Worker Status**: System resources and worker process health
|
||||
|
||||
## Endpoints
|
||||
|
||||
### `GET /api/v1/monitor/queue_stats`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: system-level
|
||||
|
||||
Get job queue statistics grouped by status.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get queue statistics
|
||||
curl -s "$API/api/v1/monitor/queue_stats" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"pending": 5,
|
||||
"running": 2,
|
||||
"completed": 150,
|
||||
"failed": 3
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `pending` | number | Jobs waiting to be processed |
|
||||
| `running` | number | Jobs currently being processed |
|
||||
| `completed` | number | Jobs successfully completed |
|
||||
| `failed` | number | Jobs that failed |
|
||||
|
||||
#### Implementation Details
|
||||
|
||||
**File**: `/Users/accusys/momentry_core/src/api/monitor.rs`
|
||||
|
||||
**Database Query**:
|
||||
```sql
|
||||
SELECT status, COUNT(*) as count
|
||||
FROM monitor_jobs
|
||||
GROUP BY status
|
||||
```
|
||||
|
||||
**Status Values**:
|
||||
- `"pending"` - Queued for processing
|
||||
- `"running"` - Currently being processed
|
||||
- `"completed"` - Successfully finished
|
||||
- `"failed"` - Processing failed
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/monitor/running_jobs`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: system-level
|
||||
|
||||
Get detailed information about currently running jobs, including processor progress.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get running jobs
|
||||
curl -s "$API/api/v1/monitor/running_jobs" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"jobs": [
|
||||
{
|
||||
"job_id": 123,
|
||||
"file_uuid": "384b0ff44aaaa1f1",
|
||||
"file_name": "video.mp4",
|
||||
"status": "running",
|
||||
"started_at": "2026-10-24T15:30:00Z",
|
||||
"duration_secs": 120,
|
||||
"processors": [
|
||||
{
|
||||
"name": "asr",
|
||||
"phase": 2,
|
||||
"status": "running",
|
||||
"progress": 75,
|
||||
"duration": 45.3
|
||||
},
|
||||
{
|
||||
"name": "face",
|
||||
"phase": 2,
|
||||
"status": "pending",
|
||||
"progress": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `jobs` | array | List of running jobs |
|
||||
| `jobs[].job_id` | number | Job ID |
|
||||
| `jobs[].file_uuid` | string | File UUID |
|
||||
| `jobs[].file_name` | string | File name |
|
||||
| `jobs[].status` | string | Job status (`"running"`) |
|
||||
| `jobs[].started_at` | string | ISO 8601 timestamp |
|
||||
| `jobs[].duration_secs` | number | Duration in seconds |
|
||||
| `jobs[].processors` | array | List of processors for this job |
|
||||
| `jobs[].processors[].name` | string | Processor type |
|
||||
| `jobs[].processors[].phase` | number | Processing phase (1-4) |
|
||||
| `jobs[].processors[].status` | string | Processor status |
|
||||
| `jobs[].processors[].progress` | number | Progress percentage (0-100) |
|
||||
| `jobs[].processors[].duration` | number | Duration in seconds (optional) |
|
||||
|
||||
#### Implementation Details
|
||||
|
||||
**File**: `/Users/accusys/momentry_core/src/api/monitor.rs`
|
||||
|
||||
**Database Query**:
|
||||
```sql
|
||||
SELECT j.id, j.uuid, j.status, j.started_at, v.file_name
|
||||
FROM monitor_jobs j
|
||||
LEFT JOIN videos v ON v.file_uuid = j.uuid
|
||||
WHERE j.status = 'running'
|
||||
ORDER BY j.started_at DESC
|
||||
```
|
||||
|
||||
**Processor Phases**:
|
||||
| Phase | Processors | Description |
|
||||
|-------|-----------|-------------|
|
||||
| 1 | `cut` | Video segmentation |
|
||||
| 2 | `asr`, `asr_asrx`, `face`, `ocr` | Core processing |
|
||||
| 3 | `scene`, `face_trace`, `face_cluster` | Analysis & clustering |
|
||||
| 4 | `tkg` | Knowledge graph |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/monitor/worker_status`
|
||||
|
||||
**Auth**: Required
|
||||
|
||||
**Scope**: system-level
|
||||
|
||||
Get worker process status and system resource usage.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get worker status
|
||||
curl -s "$API/api/v1/monitor/worker_status" \
|
||||
-H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"cpu_percent": 45.5,
|
||||
"gpu_percent": 60.0,
|
||||
"memory_mb": 8192,
|
||||
"memory_percent": 52.3,
|
||||
"active_processors": 3,
|
||||
"max_processors": 6,
|
||||
"processors": [
|
||||
{
|
||||
"name": "asr",
|
||||
"job_id": 123,
|
||||
"status": "running"
|
||||
},
|
||||
{
|
||||
"name": "face",
|
||||
"job_id": 124,
|
||||
"status": "running"
|
||||
}
|
||||
],
|
||||
"worker_pid": 12345,
|
||||
"uptime_secs": 3600,
|
||||
"last_poll_at": "2026-10-24T15:30:00Z",
|
||||
"poll_interval_secs": 5,
|
||||
"is_alive": true
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `cpu_percent` | number | CPU usage percentage |
|
||||
| `gpu_percent` | number | GPU utilization percentage |
|
||||
| `memory_mb` | number | Memory used in MB |
|
||||
| `memory_percent` | number | Memory usage percentage |
|
||||
| `active_processors` | number | Number of active processors |
|
||||
| `max_processors` | number | Maximum concurrent processors |
|
||||
| `processors` | array | List of active processors |
|
||||
| `processors[].name` | string | Processor type |
|
||||
| `processors[].job_id` | number | Job ID being processed |
|
||||
| `processors[].status` | string | Processor status |
|
||||
| `worker_pid` | number | Worker process ID |
|
||||
| `uptime_secs` | number | Worker uptime in seconds |
|
||||
| `last_poll_at` | string | Last activity timestamp (optional) |
|
||||
| `poll_interval_secs` | number | Expected poll interval |
|
||||
| `is_alive` | boolean | Worker process is running |
|
||||
|
||||
#### Implementation Details
|
||||
|
||||
**File**: `/Users/accusys/momentry_core/src/api/monitor.rs`
|
||||
|
||||
**Data Sources**:
|
||||
- System resources: `SystemResources::check()`
|
||||
- Worker PID: `pgrep -f "momentry worker"`
|
||||
- Active processors: `processor_results` table
|
||||
- Last activity: `monitor_jobs` table
|
||||
|
||||
**Resource Monitoring**:
|
||||
- CPU: System-wide usage
|
||||
- GPU: Metal/ANE utilization (macOS)
|
||||
- Memory: Used vs total memory
|
||||
|
||||
---
|
||||
|
||||
## Usage Patterns
|
||||
|
||||
### Dashboard Monitoring
|
||||
|
||||
```bash
|
||||
# Get all monitoring data
|
||||
curl -s "$API/api/v1/monitor/queue_stats" -H "X-API-Key: $KEY" | jq
|
||||
curl -s "$API/api/v1/monitor/running_jobs" -H "X-API-Key: $KEY" | jq
|
||||
curl -s "$API/api/v1/monitor/worker_status" -H "X-API-Key: $KEY" | jq
|
||||
```
|
||||
|
||||
### Real-time Updates
|
||||
|
||||
```bash
|
||||
# Poll every 5 seconds
|
||||
watch -n 5 'curl -s "$API/api/v1/monitor/queue_stats" -H "X-API-Key: $KEY" | jq'
|
||||
```
|
||||
|
||||
### Health Check
|
||||
|
||||
```bash
|
||||
# Check if worker is alive
|
||||
curl -s "$API/api/v1/monitor/worker_status" -H "X-API-Key: $KEY" | jq '.is_alive'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Error Codes
|
||||
|
||||
| Code | HTTP | When |
|
||||
|------|------|------|
|
||||
| E401 | 401 | Missing or invalid API key |
|
||||
| E500 | 500 | Database query failed |
|
||||
|
||||
---
|
||||
|
||||
## Database Tables
|
||||
|
||||
### `monitor_jobs`
|
||||
|
||||
Primary job queue table.
|
||||
|
||||
| Column | Type | Description |
|
||||
|--------|------|-------------|
|
||||
| `id` | integer | Job ID |
|
||||
| `uuid` | string | File UUID |
|
||||
| `status` | string | Job status |
|
||||
| `started_at` | timestamp | Start time |
|
||||
| `updated_at` | timestamp | Last update |
|
||||
|
||||
### `processor_results`
|
||||
|
||||
Processor execution results.
|
||||
|
||||
| Column | Type | Description |
|
||||
|--------|------|-------------|
|
||||
| `job_id` | integer | Job ID |
|
||||
| `processor_type` | string | Processor name |
|
||||
| `status` | string | Processor status |
|
||||
| `progress_current` | integer | Current progress |
|
||||
| `progress_total` | integer | Total steps |
|
||||
| `duration_secs` | float | Duration in seconds |
|
||||
|
||||
---
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- [Health API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/02_health.md)
|
||||
- [Pipeline API](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/10_pipeline.md)
|
||||
- [Job Management](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/modules/17_progress.md)
|
||||
|
||||
---
|
||||
|
||||
## Common Issues
|
||||
|
||||
### Worker Shows as Not Alive
|
||||
|
||||
**Symptoms**: `is_alive: false`
|
||||
|
||||
**Possible Causes**:
|
||||
1. Worker process not running
|
||||
2. Worker crashed
|
||||
3. `pgrep` command failed
|
||||
|
||||
**Solution**:
|
||||
```bash
|
||||
# Check worker process
|
||||
ps aux | grep momentry
|
||||
|
||||
# Start worker
|
||||
momentry worker
|
||||
|
||||
# Check logs
|
||||
tail -f ~/momentry_core/logs/worker_3002.log
|
||||
```
|
||||
|
||||
### Queue Has Stuck Jobs
|
||||
|
||||
**Symptoms**: Jobs stuck in "running" status
|
||||
|
||||
**Possible Causes**:
|
||||
1. Worker crashed
|
||||
2. Processor timeout
|
||||
3. Database lock
|
||||
|
||||
**Solution**:
|
||||
```bash
|
||||
# Check running jobs
|
||||
curl -s "$API/api/v1/monitor/running_jobs" -H "X-API-Key: $KEY"
|
||||
|
||||
# Reset stuck jobs (requires database access)
|
||||
# UPDATE monitor_jobs SET status = 'pending' WHERE status = 'running' AND updated_at < NOW() - INTERVAL '1 hour';
|
||||
```
|
||||
|
||||
### High Resource Usage
|
||||
|
||||
**Symptoms**: `cpu_percent` or `memory_percent` very high
|
||||
|
||||
**Possible Causes**:
|
||||
1. Too many concurrent jobs
|
||||
2. Large video files
|
||||
3. Memory leak
|
||||
|
||||
**Solution**:
|
||||
```bash
|
||||
# Check active processors
|
||||
curl -s "$API/api/v1/monitor/worker_status" -H "X-API-Key: $KEY" | jq '.processors'
|
||||
|
||||
# Reduce max_processors if needed
|
||||
# Restart worker
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial documentation |
|
||||
@@ -0,0 +1,310 @@
|
||||
---
|
||||
title: Admin Config API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-25
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: admin_config -->
|
||||
<!-- description: System configuration management -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## Admin Configuration
|
||||
|
||||
Admin configuration management for system-wide settings, VLM prompts, and runtime parameters.
|
||||
|
||||
### `GET /api/v1/admin/config`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: admin-level
|
||||
|
||||
Get the full system configuration. Returns all configuration parameters including VLM prompts, processing settings, and system defaults.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/admin/config" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"vlm_prompts": {
|
||||
"face_trace": {
|
||||
"system_prompt": "Analyze the person's appearance...",
|
||||
"user_prompt_template": "Describe this person..."
|
||||
}
|
||||
},
|
||||
"processing": {
|
||||
"default_processors": ["cut", "asr", "face"],
|
||||
"face_min_confidence": 0.5,
|
||||
"face_min_size": 30
|
||||
},
|
||||
"system": {
|
||||
"max_concurrent_jobs": 3,
|
||||
"output_dir": "/Users/accusys/momentry/output"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/admin/config`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: admin-level
|
||||
|
||||
Partially update system configuration. Only provided fields are modified; others remain unchanged.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `processing` | object | No | Processing configuration |
|
||||
| `system` | object | No | System configuration |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/admin/config" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"processing": {
|
||||
"face_min_confidence": 0.6
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Config updated"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/admin/config/vlm_prompts`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: admin-level
|
||||
|
||||
Get all VLM (Vision Language Model) prompts used for image analysis.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/admin/config/vlm_prompts" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"face_trace": {
|
||||
"system_prompt": "You are an expert in person appearance analysis...",
|
||||
"user_prompt_template": "Describe the person in this image..."
|
||||
},
|
||||
"scene": {
|
||||
"system_prompt": "You are a scene description expert...",
|
||||
"user_prompt_template": "Describe the scene..."
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/admin/config/vlm_prompts/:key`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: admin-level
|
||||
|
||||
Get a specific VLM prompt by key.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `key` | string | Prompt key (e.g., "face_trace", "scene") |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/admin/config/vlm_prompts/face_trace" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"system_prompt": "You are an expert in person appearance analysis...",
|
||||
"user_prompt_template": "Describe the person in this image..."
|
||||
}
|
||||
```
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `404` | Prompt key not found |
|
||||
| `401` | Missing or invalid API key |
|
||||
|
||||
---
|
||||
|
||||
### `PUT /api/v1/admin/config/vlm_prompts/:key`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: admin-level
|
||||
|
||||
Update a specific VLM prompt. This affects all subsequent VLM analysis operations.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `system_prompt` | string | Yes | System prompt for the LLM |
|
||||
| `user_prompt_template` | string | Yes | User prompt template (may include placeholders) |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X PUT "$API/api/v1/admin/config/vlm_prompts/face_trace" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"system_prompt": "You are an expert in fashion and appearance analysis...",
|
||||
"user_prompt_template": "Analyze the person'\''s clothing and accessories in detail..."
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Prompt 'face_trace' updated"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/admin/config/reload`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: admin-level
|
||||
|
||||
Reload configuration from disk. Useful when the configuration file has been manually edited.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/admin/config/reload" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Config reloaded"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/admin/settings`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: admin-level
|
||||
|
||||
Alias for `/api/v1/admin/config`. Provided for frontend compatibility.
|
||||
|
||||
---
|
||||
|
||||
## Configuration Structure
|
||||
|
||||
### VLM Prompts
|
||||
|
||||
VLM prompts control how the system analyzes images and video frames:
|
||||
|
||||
| Prompt Key | Purpose | Used By |
|
||||
|------------|---------|---------|
|
||||
| `face_trace` | Person appearance description | Face trace processor |
|
||||
| `scene` | Scene description | Scene VLM processor |
|
||||
| `appearance` | Detailed appearance analysis | Appearance processor |
|
||||
|
||||
### Processing Settings
|
||||
|
||||
| Field | Type | Default | Description |
|
||||
|-------|------|---------|-------------|
|
||||
| `default_processors` | string[] | all | Default processors for new files |
|
||||
| `face_min_confidence` | float | 0.5 | Minimum face detection confidence |
|
||||
| `face_min_size` | integer | 30 | Minimum face size in pixels |
|
||||
|
||||
### System Settings
|
||||
|
||||
| Field | Type | Default | Description |
|
||||
|-------|------|---------|-------------|
|
||||
| `max_concurrent_jobs` | integer | 3 | Maximum parallel processing jobs |
|
||||
| `output_dir` | string | - | Output directory path |
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. Adjust Face Detection Sensitivity
|
||||
|
||||
```bash
|
||||
curl -X POST "$API/api/v1/admin/config" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"processing": {
|
||||
"face_min_confidence": 0.7,
|
||||
"face_min_size": 50
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
### 2. Customize VLM Prompts
|
||||
|
||||
```bash
|
||||
curl -X PUT "$API/api/v1/admin/config/vlm_prompts/face_trace" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"system_prompt": "Focus on clothing colors and patterns",
|
||||
"user_prompt_template": "Describe the person'\''s outfit..."
|
||||
}'
|
||||
```
|
||||
|
||||
### 3. Reload Configuration After Manual Edit
|
||||
|
||||
```bash
|
||||
# Edit config file on disk
|
||||
vim /path/to/config.json
|
||||
|
||||
# Reload into running system
|
||||
curl -X POST "$API/api/v1/admin/config/reload" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Security Notes
|
||||
|
||||
- **Admin-only access**: All endpoints require admin-level authentication
|
||||
- **Persistent changes**: Configuration changes persist across server restarts
|
||||
- **Hot reload**: Changes take effect immediately without server restart
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-25 | Initial documentation |
|
||||
@@ -0,0 +1,120 @@
|
||||
---
|
||||
title: Docs API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-25
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: docs -->
|
||||
<!-- description: API documentation web server -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## Documentation Web Server
|
||||
|
||||
Web-based API documentation served by the server. Supports both static HTML and WASM-based interactive documentation.
|
||||
|
||||
### `GET /doc`
|
||||
|
||||
**Auth**: Not required
|
||||
|
||||
Redirect to WASM documentation.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -L http://localhost:3002/doc
|
||||
```
|
||||
|
||||
#### Response
|
||||
|
||||
301 Redirect → `/doc-wasm`
|
||||
|
||||
---
|
||||
|
||||
### `GET /doc-wasm`
|
||||
|
||||
**Auth**: Not required
|
||||
|
||||
Serve WASM-based interactive documentation.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl http://localhost:3002/doc-wasm
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
HTML page with WASM documentation viewer.
|
||||
|
||||
---
|
||||
|
||||
### `GET /doc-wasm/*file`
|
||||
|
||||
**Auth**: Not required
|
||||
|
||||
Serve WASM binary files and static assets for documentation.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `file` | string | File path (e.g., "pkg/md_wasm_bg.wasm") |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl http://localhost:3002/doc-wasm/pkg/md_wasm_bg.wasm --output md_wasm_bg.wasm
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
Binary file with appropriate MIME type:
|
||||
- `.wasm` → `application/wasm`
|
||||
- `.js` → `application/javascript`
|
||||
- `.css` → `text/css`
|
||||
- `.md` → `text/markdown`
|
||||
|
||||
---
|
||||
|
||||
## Documentation Types
|
||||
|
||||
### WASM Documentation (Default)
|
||||
|
||||
- **Location**: `docs_v1.0/doc_wasm/`
|
||||
- **Technology**: Rust WASM + pulldown-cmark
|
||||
- **Features**: Interactive search, Mermaid diagrams, Material Design
|
||||
- **Authentication**: Optional (configurable)
|
||||
|
||||
### Static Documentation
|
||||
|
||||
- **Location**: `docs_v1.0/API_WORKSPACE/` and `docs_v1.0/CLI_WORKSPACE/`
|
||||
- **Format**: Markdown files
|
||||
- **Served via**: WASM renderer
|
||||
|
||||
---
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `MOMENTRY_DOCS_DIR` | `{binary_dir}/docs_v1.0/doc_wasm` | Documentation root directory |
|
||||
|
||||
---
|
||||
|
||||
## Security
|
||||
|
||||
- **Path Traversal Protection**: Rejects paths containing `..` or `//`
|
||||
- **Directory Restriction**: Only serves files within `MOMENTRY_DOCS_DIR`
|
||||
- **No Authentication**: Documentation is public (unless protected by reverse proxy)
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-25 | Initial documentation |
|
||||
@@ -0,0 +1,161 @@
|
||||
---
|
||||
title: Markbase Compat API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-25
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: markbase_compat -->
|
||||
<!-- description: MarkBase compatibility layer for Studio -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## MarkBase Compatibility
|
||||
|
||||
Compatibility layer for MarkBase API, enabling Studio to access user data folders.
|
||||
|
||||
### `GET /api/v1/markbase/folders/:username`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: user-level
|
||||
|
||||
List all folders for a user.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `username` | string | User name |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/markbase/folders/admin" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"name": "Documents",
|
||||
"parent": ""
|
||||
},
|
||||
{
|
||||
"name": "Media",
|
||||
"parent": ""
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/markbase/files/:username/:folder`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: user-level
|
||||
|
||||
List all files in a user's folder.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `username` | string | User name |
|
||||
| `folder` | string | Folder name |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/markbase/files/admin/Documents" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"name": "video1.mp4",
|
||||
"type": "file",
|
||||
"size": 1048576,
|
||||
"modified": "2026-10-25T10:00:00Z",
|
||||
"is_dir": false
|
||||
},
|
||||
{
|
||||
"name": "subfolder",
|
||||
"type": "directory",
|
||||
"size": 0,
|
||||
"modified": "2026-10-25T09:00:00Z",
|
||||
"is_dir": true
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/markbase/file/:username/:path`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: user-level
|
||||
|
||||
Get details or download a specific file.
|
||||
|
||||
#### Path Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `username` | string | User name |
|
||||
| `path` | string | File path within user directory |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/markbase/file/admin/Documents/video1.mp4" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
--output video1.mp4
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
File content with appropriate MIME type.
|
||||
|
||||
---
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
var/studio/data/
|
||||
├── {username}/
|
||||
│ └── files/
|
||||
│ ├── Documents/
|
||||
│ │ ├── video1.mp4
|
||||
│ │ └── video2.mp4
|
||||
│ └── Media/
|
||||
│ └── audio.mp3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `MOMENTRY_STUDIO_DATA_DIR` | `{binary_dir}/var/studio/data` | Studio data directory |
|
||||
|
||||
---
|
||||
|
||||
## Compatibility Notes
|
||||
|
||||
- **Purpose**: Provides MarkBase-compatible API for Studio integration
|
||||
- **Backward Compatibility**: Maintains existing Studio functionality
|
||||
- **Future**: May be deprecated when Studio migrates to new API structure
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-25 | Initial documentation |
|
||||
@@ -0,0 +1,246 @@
|
||||
---
|
||||
title: CLIP API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-25
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: clip -->
|
||||
<!-- description: CLIP-based image classification and object detection -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## CLIP Vision Model
|
||||
|
||||
### `POST /api/v1/clip/classify`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Classify an image against a list of text labels using CLIP (Contrastive Language-Image Pre-training). Returns top-k predictions with confidence scores.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `image_path` | string | Yes | - | Absolute path to the image file |
|
||||
| `labels` | string | Yes | - | Comma-separated text labels (e.g., "dog,cat,car,person") |
|
||||
| `top_k` | integer | No | 5 | Number of top predictions to return |
|
||||
| `model` | string | No | default | CLIP model variant to use |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/clip/classify" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"image_path": "/path/to/image.jpg",
|
||||
"labels": "dog,cat,car,person,building",
|
||||
"top_k": 3
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"predictions": [
|
||||
{
|
||||
"label": "dog",
|
||||
"confidence": 0.892
|
||||
},
|
||||
{
|
||||
"label": "person",
|
||||
"confidence": 0.073
|
||||
},
|
||||
{
|
||||
"label": "cat",
|
||||
"confidence": 0.021
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `success` | boolean | Operation success status |
|
||||
| `predictions` | array | Array of label-confidence pairs, sorted by confidence (descending) |
|
||||
| `label` | string | Text label |
|
||||
| `confidence` | float | Confidence score (0.0-1.0) |
|
||||
|
||||
#### Error Responses
|
||||
|
||||
| HTTP | When |
|
||||
|------|------|
|
||||
| `400` | Invalid image path or labels |
|
||||
| `401` | Missing or invalid API key |
|
||||
| `500` | CLIP model inference error |
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/clip/detect`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Detect specific objects in an image using zero-shot object detection. Returns detected objects with confidence scores above the threshold.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `image_path` | string | Yes | - | Absolute path to the image file |
|
||||
| `objects` | string | Yes | - | Comma-separated object names to detect |
|
||||
| `threshold` | float | No | 0.15 | Confidence threshold (0.0-1.0) |
|
||||
| `model` | string | No | default | CLIP model variant to use |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/clip/detect" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"image_path": "/path/to/scene.jpg",
|
||||
"objects": "person,car,bicycle",
|
||||
"threshold": 0.3
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"detected": [
|
||||
{
|
||||
"label": "person",
|
||||
"confidence": 0.921
|
||||
},
|
||||
{
|
||||
"label": "car",
|
||||
"confidence": 0.876
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Note**: Only objects with confidence >= `threshold` are returned. If no objects are detected, `detected` will be an empty array.
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/clip/batch`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: system-level
|
||||
|
||||
Batch classify multiple images against the same set of labels. Efficient for processing large image sets.
|
||||
|
||||
#### Request Parameters
|
||||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `image_paths` | string | Yes | - | Comma-separated absolute paths to image files |
|
||||
| `labels` | string | Yes | - | Comma-separated text labels |
|
||||
| `top_k` | integer | No | 5 | Number of top predictions per image |
|
||||
| `model` | string | No | default | CLIP model variant to use |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
curl -s -X POST "$API/api/v1/clip/batch" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"image_paths": "/path/to/img1.jpg,/path/to/img2.jpg,/path/to/img3.jpg",
|
||||
"labels": "indoor,outdoor,nature,urban",
|
||||
"top_k": 2
|
||||
}'
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"results": {
|
||||
"/path/to/img1.jpg": [
|
||||
{"label": "indoor", "confidence": 0.945},
|
||||
{"label": "urban", "confidence": 0.032}
|
||||
],
|
||||
"/path/to/img2.jpg": [
|
||||
{"label": "outdoor", "confidence": 0.876},
|
||||
{"label": "nature", "confidence": 0.089}
|
||||
],
|
||||
"/path/to/img3.jpg": [
|
||||
{"label": "nature", "confidence": 0.923},
|
||||
{"label": "outdoor", "confidence": 0.054}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. Scene Classification
|
||||
|
||||
```bash
|
||||
# Classify scene type
|
||||
curl -X POST "$API/api/v1/clip/classify" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"image_path": "/output/video_frame.jpg",
|
||||
"labels": "indoor,outdoor,day,night",
|
||||
"top_k": 2
|
||||
}'
|
||||
```
|
||||
|
||||
### 2. Object Detection
|
||||
|
||||
```bash
|
||||
# Detect people and vehicles
|
||||
curl -X POST "$API/api/v1/clip/detect" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"image_path": "/output/frame_001.jpg",
|
||||
"objects": "person,car,bicycle,motorcycle",
|
||||
"threshold": 0.3
|
||||
}'
|
||||
```
|
||||
|
||||
### 3. Batch Frame Analysis
|
||||
|
||||
```bash
|
||||
# Analyze multiple video frames
|
||||
curl -X POST "$API/api/v1/clip/batch" \
|
||||
-H "X-API-Key: $KEY" \
|
||||
-d '{
|
||||
"image_paths": "/output/frame_001.jpg,/output/frame_002.jpg,/output/frame_003.jpg",
|
||||
"labels": "action,dialogue,scenery",
|
||||
"top_k": 1
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
- **Model**: Uses CLIP ViT-B/32 by default
|
||||
- **Performance**: ~50ms per image on CPU, ~5ms on GPU
|
||||
- **Supported Formats**: JPEG, PNG, WebP, BMP
|
||||
- **Max Image Size**: 4K resolution (3840x2160)
|
||||
- **Batch Limit**: Recommended max 100 images per batch
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-25 | Initial documentation |
|
||||
@@ -0,0 +1,180 @@
|
||||
---
|
||||
title: Billing API
|
||||
version: 1.3.5
|
||||
api_version: 1.3.5
|
||||
git_tag: v1.3.5
|
||||
date: 2026-10-25
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
<!-- module: billing -->
|
||||
<!-- description: Token usage tracking and billing -->
|
||||
<!-- depends: 01_auth -->
|
||||
|
||||
## Billing & Usage Tracking
|
||||
|
||||
Track LLM token usage across different services (Agent, VLM, TKG, etc.).
|
||||
|
||||
### `GET /api/v1/billing/usage`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: user-level
|
||||
|
||||
Get token usage for a specific billing period. Returns input/output token counts and service breakdown.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Parameter | Type | Required | Default | Description |
|
||||
|-----------|------|----------|---------|-------------|
|
||||
| `period` | string | No | Current month | Billing period in YYYY-MM format |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get current month usage
|
||||
curl -s "$API/api/v1/billing/usage" -H "X-API-Key: $KEY"
|
||||
|
||||
# Get specific month
|
||||
curl -s "$API/api/v1/billing/usage?period=2026-09" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"key_id": null,
|
||||
"period": "2026-10",
|
||||
"tokens": {
|
||||
"input": 15234,
|
||||
"output": 8921,
|
||||
"total": 24155
|
||||
},
|
||||
"services": {
|
||||
"agent": 8500,
|
||||
"vlm": 12000,
|
||||
"tkg": 3655
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `key_id` | string \| null | API key ID (null for user-level aggregate) |
|
||||
| `period` | string | Billing period (YYYY-MM) |
|
||||
| `tokens` | object | Token statistics |
|
||||
| `tokens.input` | integer | Total input tokens |
|
||||
| `tokens.output` | integer | Total output tokens |
|
||||
| `tokens.total` | integer | Total tokens (input + output) |
|
||||
| `services` | object | Token usage per service |
|
||||
|
||||
---
|
||||
|
||||
### `GET /api/v1/billing/history`
|
||||
|
||||
**Auth**: Required
|
||||
**Scope**: user-level
|
||||
|
||||
Get token usage history for the past N months.
|
||||
|
||||
#### Query Parameters
|
||||
|
||||
| Parameter | Type | Required | Default | Description |
|
||||
|-----------|------|----------|---------|-------------|
|
||||
| `months` | integer | No | 12 | Number of months to retrieve |
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
# Get last 12 months
|
||||
curl -s "$API/api/v1/billing/history" -H "X-API-Key: $KEY"
|
||||
|
||||
# Get last 6 months
|
||||
curl -s "$API/api/v1/billing/history?months=6" -H "X-API-Key: $KEY"
|
||||
```
|
||||
|
||||
#### Response (200)
|
||||
|
||||
```json
|
||||
{
|
||||
"periods": [
|
||||
{
|
||||
"key_id": null,
|
||||
"period_month": "2026-10",
|
||||
"total_input_tokens": 15234,
|
||||
"total_output_tokens": 8921,
|
||||
"total_tokens": 24155,
|
||||
"service_breakdown": {
|
||||
"agent": 8500,
|
||||
"vlm": 12000,
|
||||
"tkg": 3655
|
||||
}
|
||||
},
|
||||
{
|
||||
"key_id": null,
|
||||
"period_month": "2026-09",
|
||||
"total_input_tokens": 18234,
|
||||
"total_output_tokens": 9456,
|
||||
"total_tokens": 27690,
|
||||
"service_breakdown": {
|
||||
"agent": 10200,
|
||||
"vlm": 13500,
|
||||
"tkg": 3990
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Service Categories
|
||||
|
||||
| Service | Description | Token Type |
|
||||
|---------|-------------|------------|
|
||||
| `agent` | Agent chat, search, 5W1H | Input + Output |
|
||||
| `vlm` | Vision Language Model (image analysis) | Input + Output |
|
||||
| `tkg` | Temporal Knowledge Graph queries | Input + Output |
|
||||
| `embedding` | Text embeddings | Input only |
|
||||
| `chat` | General chat/completions | Input + Output |
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. Monitor Current Month Usage
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/billing/usage" -H "X-API-Key: $KEY" | jq '.tokens'
|
||||
```
|
||||
|
||||
### 2. Generate Monthly Report
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/billing/history?months=12" -H "X-API-Key: $KEY" | \
|
||||
jq -r '.periods[] | "\(.period_month),\(.total_tokens)"'
|
||||
```
|
||||
|
||||
### 3. Check Service Breakdown
|
||||
|
||||
```bash
|
||||
curl -s "$API/api/v1/billing/usage" -H "X-API-Key: $KEY" | \
|
||||
jq '.services | to_entries | sort_by(.value) | reverse | .[]'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Billing Notes
|
||||
|
||||
- **Token counting**: Both input and output tokens are counted
|
||||
- **Aggregation**: Usage is aggregated per user or per API key
|
||||
- **Persistence**: Billing data persists across server restarts
|
||||
- **Reset**: Billing periods reset monthly on the 1st
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-25 | Initial documentation |
|
||||
@@ -0,0 +1,201 @@
|
||||
---
|
||||
title: Pipeline Progress API
|
||||
version: 2.1.0
|
||||
date: 2026-10-14
|
||||
author: Core Team
|
||||
status: implemented
|
||||
---
|
||||
|
||||
# Pipeline Progress API
|
||||
|
||||
| Field | Value |
|
||||
|-------|-------|
|
||||
| Scope | Core HTTP API (axum) |
|
||||
| Status | Implemented |
|
||||
| Applicable to | Momentry Studio frontend, Core API consumers |
|
||||
| Source | `/Users/accusys/momentry_core/src/api/file_progress.rs` |
|
||||
| Config | `/Users/accusys/momentry_core/config/pipeline_flows.json` |
|
||||
| Auth | Protected (session cookie, JWT, or API key) |
|
||||
|
||||
This document describes the phase-based pipeline progress API consumed by the
|
||||
Studio frontend (`/Users/accusys/momentry_studio/src/store.ts`). All progress
|
||||
values are normalized to the range **0.0 – 1.0** (the frontend multiplies by 100
|
||||
for display).
|
||||
|
||||
> Note: an early design draft specified a richer 0–100 nested response
|
||||
> (`progress.phases[]`). The implemented contract is the flat, 0–1 shape that
|
||||
> Studio actually consumes. This document reflects the implementation.
|
||||
|
||||
---
|
||||
|
||||
## Endpoints
|
||||
|
||||
### 1. Get phase configuration (static)
|
||||
|
||||
`GET /api/v1/pipeline/phases`
|
||||
|
||||
Returns the phase/processor definition graph derived from
|
||||
`/Users/accusys/momentry_core/config/pipeline_flows.json` (`phases` array plus
|
||||
`flows.register.stages` for per-processor `weight` and `depends_on`).
|
||||
|
||||
```json
|
||||
{
|
||||
"phases": [
|
||||
{
|
||||
"name": "Foundation",
|
||||
"weight": 0.15,
|
||||
"processors": [
|
||||
{ "name": "cut", "weight": 1.0, "depends_on": [] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Core Processing",
|
||||
"weight": 0.6,
|
||||
"processors": [
|
||||
{ "name": "asr", "weight": 0.35, "depends_on": [] },
|
||||
{ "name": "face", "weight": 0.35, "depends_on": [] },
|
||||
{ "name": "ocr", "weight": 0.3, "depends_on": [] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Deep Analysis",
|
||||
"weight": 0.2,
|
||||
"processors": [
|
||||
{ "name": "asrx", "weight": 0.4, "depends_on": ["asr"] },
|
||||
{ "name": "scene", "weight": 0.35, "depends_on": ["cut"] },
|
||||
{ "name": "face_cluster", "weight": 0.25, "depends_on": ["face"] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Knowledge Building",
|
||||
"weight": 0.05,
|
||||
"processors": [
|
||||
{ "name": "tkg", "weight": 1.0, "depends_on": ["asrx", "face_cluster"] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- `name` is the phase key (`name_en` in config; falls back to Chinese `name`).
|
||||
- Phase and processor `weight` are the `progress_weight` from config
|
||||
(defaulting to `1.0` when absent).
|
||||
|
||||
### 2. Get per-file progress
|
||||
|
||||
`GET /api/v1/file/{file_uuid}/progress`
|
||||
|
||||
```json
|
||||
{
|
||||
"file_uuid": "9c77a341a1194167e8ff6a06816f1ff6",
|
||||
"overall_progress": 0.486,
|
||||
"current_phase": "Core Processing",
|
||||
"phases": {
|
||||
"Foundation": {
|
||||
"status": "completed",
|
||||
"progress": 1.0,
|
||||
"processors": {
|
||||
"cut": { "name": "cut", "status": "completed", "progress": 1.0 }
|
||||
}
|
||||
},
|
||||
"Core Processing": {
|
||||
"status": "running",
|
||||
"progress": 0.56,
|
||||
"processors": {
|
||||
"asr": { "name": "asr", "status": "completed", "progress": 1.0 },
|
||||
"face": { "name": "face", "status": "running", "progress": 0.6 },
|
||||
"ocr": { "name": "ocr", "status": "pending", "progress": 0.0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `overall_progress`: weighted sum of phase progress (0.0 – 1.0).
|
||||
- `current_phase`: first phase (in config order) with `progress < 1.0`; `null`
|
||||
when all phases are complete.
|
||||
- `phases`: keyed by phase `name`. `status` is one of
|
||||
`pending | running | completed | failed`. Processor-level `status` may also be
|
||||
`skipped` (from `processor_results`).
|
||||
- Unknown `file_uuid` returns HTTP 200 with `overall_progress: 0.0` and all
|
||||
phases pending.
|
||||
|
||||
---
|
||||
|
||||
## Data Sources
|
||||
|
||||
| Source | Purpose |
|
||||
|--------|---------|
|
||||
| `videos.status`, `videos.processing_status` (JSONB) | File-level status; `processing_status.phase` (`PROCESSING`/`COMPLETED`) and `active_processors` decide applicability |
|
||||
| Redis `{prefix}job:{file_uuid}:processor:{name}` (hash) | Real-time per-processor `status`, `current`, `total` |
|
||||
| Postgres `processor_results` (`WHERE uuid = $1`, latest row per `processor`) | Terminal per-processor status |
|
||||
| Redis `{prefix}progress:{file_uuid}:tkg` (JSON) | TKG progress (`overall_progress`, `phase`) |
|
||||
| Redis `{prefix}progress:{file_uuid}:phase_hwm` (JSON) | Monotonic high-water mark per phase |
|
||||
|
||||
`{prefix}` is `MOMENTRY_REDIS_PREFIX` (`momentry:` in production).
|
||||
|
||||
---
|
||||
|
||||
## Progress Calculation
|
||||
|
||||
**Phase progress**
|
||||
|
||||
```
|
||||
phase_progress = Σ(processor.weight × processor.progress) / Σ(processor.weight)
|
||||
(over only "applicable" processors)
|
||||
```
|
||||
|
||||
A processor is **applicable** when any of the following holds:
|
||||
|
||||
- the file is completed (`videos.status = completed` or `phase = COMPLETED`);
|
||||
- the processor already produced a signal (Redis hash or `processor_results`);
|
||||
- the processor is listed in `processing_status.active_processors`.
|
||||
|
||||
This prevents a phase from reporting 100% while sibling processors are still
|
||||
pending, and prevents stalling on processors that never run for this job.
|
||||
Processors with status `skipped` are treated as done (progress `1.0`).
|
||||
|
||||
**Overall progress**
|
||||
|
||||
```
|
||||
overall_progress = Σ(phase.weight × phase.progress)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Monotonic Guarantee
|
||||
|
||||
Each poll recomputes progress from scratch, so a naive implementation can
|
||||
regress (e.g. a processor recount moving backwards). To prevent this, the API
|
||||
stores a per-phase high-water mark in
|
||||
`{prefix}progress:{file_uuid}:phase_hwm` and clamps every response so a phase
|
||||
never decreases within a run. The high-water mark is cleared by the worker when
|
||||
a new job starts
|
||||
(`/Users/accusys/momentry_core/src/worker/job_worker.rs`).
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
curl -X GET "http://localhost:3002/api/v1/file/9c77a341a1194167e8ff6a06816f1ff6/progress" \
|
||||
-H "Authorization: Bearer muser_..."
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Related Documents
|
||||
|
||||
- `/Users/accusys/momentry_core/config/pipeline_flows.json`
|
||||
- `/Users/accusys/momentry_core/src/api/file_progress.rs`
|
||||
- `/Users/accusys/momentry_core/docs_v1.0/OPERATIONS/Pipeline_Configuration_Guide.md`
|
||||
- `/Users/accusys/momentry_core/AGENTS.md`
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Change |
|
||||
|---------|------|--------|
|
||||
| 2.1.0 | 2026-10-14 | Rewritten to match implemented flat 0–1 contract (Studio-aligned); documented sources, calculation, and monotonic HWM |
|
||||
| 2.0.0 | 2026-10-14 | Initial design (0–100 nested response) |
|
||||
@@ -0,0 +1 @@
|
||||
# This file ensures the CLI_WORKSPACE directory is tracked by Git
|
||||
@@ -0,0 +1,116 @@
|
||||
---
|
||||
title: CLI Documentation
|
||||
version: 1.0
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
# Momentry CLI Documentation
|
||||
|
||||
## Overview
|
||||
|
||||
Momentry CLI provides command-line tools for video processing, identity management, search, and system administration.
|
||||
|
||||
## Command Categories
|
||||
|
||||
### File Processing
|
||||
|
||||
| Command | Module | Description |
|
||||
|---------|--------|-------------|
|
||||
| `register` | [101_CLI_Register.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/101_CLI_Register.md) | Register video files |
|
||||
| `process` | [102_CLI_Process.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/102_CLI_Process.md) | Process registered files |
|
||||
| `chunk` | [103_CLI_Chunk.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/103_CLI_Chunk.md) | Chunk processing |
|
||||
| `store-asrx` | [104_CLI_StoreAsrx.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/104_CLI_StoreAsrx.md) | Store ASRX data |
|
||||
| `story` | [105_CLI_Story.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/105_CLI_Story.md) | Story generation |
|
||||
|
||||
### Vision & Detection
|
||||
|
||||
| Command | Module | Description |
|
||||
|---------|--------|-------------|
|
||||
| `detect` | [106_CLI_Detect.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/106_CLI_Detect.md) | Object detection |
|
||||
| `vision` | [107_CLI_Vision.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/107_CLI_Vision.md) | Vision processing |
|
||||
| `vectorize` | [108_CLI_Vectorize.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/108_CLI_Vectorize.md) | Vectorization |
|
||||
|
||||
### Pipeline & Execution
|
||||
|
||||
| Command | Module | Description |
|
||||
|---------|--------|-------------|
|
||||
| `phase1` | [109_CLI_Phase1.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/109_CLI_Phase1.md) | Phase 1 pipeline |
|
||||
| `complete` | [110_CLI_Complete.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/110_CLI_Complete.md) | Complete processing |
|
||||
|
||||
### Media & Playback
|
||||
|
||||
| Command | Module | Description |
|
||||
|---------|--------|-------------|
|
||||
| `play` | [111_CLI_Play.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/111_CLI_Play.md) | Media playback |
|
||||
| `watch` | [112_CLI_Watch.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/112_CLI_Watch.md) | File watching |
|
||||
|
||||
### System & Administration
|
||||
|
||||
| Command | Module | Description |
|
||||
|---------|--------|-------------|
|
||||
| `system` | [113_CLI_System.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/113_CLI_System.md) | System commands |
|
||||
| `server` | [114_CLI_Server.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/114_CLI_Server.md) | Server management |
|
||||
| `worker` | [115_CLI_Worker.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/115_CLI_Worker.md) | Worker management |
|
||||
| `query` | [116_CLI_Query.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/116_CLI_Query.md) | Query operations |
|
||||
| `status` | [120_CLI_Status.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/120_CLI_Status.md) | Status checks |
|
||||
| `backup` | [121_CLI_Backup.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/121_CLI_Backup.md) | Backup operations |
|
||||
| `api-key` | [122_CLI_ApiKey.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/122_CLI_ApiKey.md) | API key management |
|
||||
| `gitea` | [123_CLI_Gitea.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/123_CLI_Gitea.md) | Gitea operations |
|
||||
|
||||
### Lookup & Resolution
|
||||
|
||||
| Command | Module | Description |
|
||||
|---------|--------|-------------|
|
||||
| `lookup` | [117_CLI_Lookup.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/117_CLI_Lookup.md) | Lookup operations |
|
||||
| `resolve` | [118_CLI_Resolve.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/118_CLI_Resolve.md) | Resolution |
|
||||
| `thumbnails` | [119_CLI_Thumbnails.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/119_CLI_Thumbnails.md) | Thumbnail generation |
|
||||
|
||||
### Agent
|
||||
|
||||
| Command | Module | Description |
|
||||
|---------|--------|-------------|
|
||||
| `agent` | [124_CLI_Agent.md](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/124_CLI_Agent.md) | Agent operations |
|
||||
|
||||
## Usage Patterns
|
||||
|
||||
### Basic Pattern
|
||||
|
||||
```bash
|
||||
momentry <command> [options] [arguments]
|
||||
```
|
||||
|
||||
### Common Options
|
||||
|
||||
- `--help` - Show help for a command
|
||||
- `--verbose` - Enable verbose output
|
||||
- `--dry-run` - Preview without execution
|
||||
|
||||
### Examples
|
||||
|
||||
```bash
|
||||
# Register a video
|
||||
momentry register /path/to/video.mp4
|
||||
|
||||
# Process a registered file
|
||||
momentry process --file-uuid <uuid>
|
||||
|
||||
# Start the server
|
||||
momentry server --port 3002
|
||||
|
||||
# Query identities
|
||||
momentry query identities --name "John"
|
||||
```
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- [API Documentation](/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE/README.md)
|
||||
- [User Guides](/Users/accusys/momentry_core/docs_v1.0/GUIDES/)
|
||||
- [Reference Documentation](/Users/accusys/momentry_core/docs_v1.0/REFERENCE/)
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Date | Changes |
|
||||
|---------|------|---------|
|
||||
| 1.0 | 2026-10-24 | Initial CLI documentation structure |
|
||||
@@ -0,0 +1,140 @@
|
||||
---
|
||||
title: CLI Command Template
|
||||
version: 1.0
|
||||
date: 2026-10-24
|
||||
author: Core Team
|
||||
status: Active
|
||||
---
|
||||
|
||||
# {Command Name} — CLI Command Documentation
|
||||
|
||||
> Use this template when adding or editing CLI command documentation.
|
||||
|
||||
## Command Metadata
|
||||
|
||||
Every CLI command doc MUST start with:
|
||||
|
||||
```markdown
|
||||
<!-- command: <command_name> -->
|
||||
<!-- category: file_processing | vision_detection | pipeline | media | system | lookup | agent -->
|
||||
<!-- related_api: <comma-separated list of related API endpoints> -->
|
||||
```
|
||||
|
||||
## Command Template
|
||||
|
||||
### `momentry <command> [options] [arguments]`
|
||||
|
||||
**Category**: file_processing | vision_detection | pipeline | media | system | lookup | agent
|
||||
|
||||
**Purpose**: One-line description of what this command does.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```bash
|
||||
momentry <command> [required-args] [options]
|
||||
```
|
||||
|
||||
#### Arguments
|
||||
|
||||
| Argument | Type | Required | Description |
|
||||
|----------|------|----------|-------------|
|
||||
| `<arg1>` | string | Yes | Description |
|
||||
| `<arg2>` | number | No | Description |
|
||||
|
||||
#### Options
|
||||
|
||||
| Option | Short | Type | Default | Description |
|
||||
|--------|-------|------|---------|-------------|
|
||||
| `--option1` | `-o` | string | — | Description |
|
||||
| `--verbose` | `-v` | flag | false | Enable verbose output |
|
||||
| `--dry-run` | `-d` | flag | false | Preview without execution |
|
||||
| `--help` | `-h` | flag | — | Show help |
|
||||
|
||||
#### Examples
|
||||
|
||||
##### Basic Usage
|
||||
|
||||
```bash
|
||||
# brief description
|
||||
momentry <command> <argument>
|
||||
```
|
||||
|
||||
##### With Options
|
||||
|
||||
```bash
|
||||
# brief description
|
||||
momentry <command> <argument> --option1 value
|
||||
```
|
||||
|
||||
##### Common Patterns
|
||||
|
||||
```bash
|
||||
# Pattern 1: Common use case
|
||||
momentry <command> <arg1>
|
||||
|
||||
# Pattern 2: With verbose output
|
||||
momentry <command> <arg1> --verbose
|
||||
```
|
||||
|
||||
#### Output
|
||||
|
||||
**Success**:
|
||||
```
|
||||
Expected output format on success
|
||||
```
|
||||
|
||||
**Error**:
|
||||
```
|
||||
Expected error message format
|
||||
```
|
||||
|
||||
#### Exit Codes
|
||||
|
||||
| Code | Meaning |
|
||||
|------|---------|
|
||||
| 0 | Success |
|
||||
| 1 | General error |
|
||||
| 2 | Invalid arguments |
|
||||
| 3 | File not found |
|
||||
|
||||
#### Related API Endpoints
|
||||
|
||||
- `POST /api/v1/...` - Brief description
|
||||
- `GET /api/v1/...` - Brief description
|
||||
|
||||
See also:
|
||||
- [Related Command 1](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/XXX_CLI_Command1.md)
|
||||
- [Related Command 2](/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE/modules/XXX_CLI_Command2.md)
|
||||
|
||||
#### Common Issues
|
||||
|
||||
##### Issue 1: Description
|
||||
|
||||
**Symptoms**: Error message or unexpected behavior
|
||||
|
||||
**Solution**: Steps to resolve
|
||||
|
||||
##### Issue 2: Description
|
||||
|
||||
**Symptoms**: Error message or unexpected behavior
|
||||
|
||||
**Solution**: Steps to resolve
|
||||
|
||||
## Rules
|
||||
|
||||
1. **Absolute Paths**: Use absolute paths in all examples
|
||||
- ✅ `/Users/accusys/momentry_core/src/...`
|
||||
- ❌ `src/...`
|
||||
|
||||
2. **Variables**: Use clear variable names in examples
|
||||
- ✅ `$FILE_UUID`, `$IDENTITY_UUID`
|
||||
- ❌ `$1`, `$2`
|
||||
|
||||
3. **Examples**: Include at least 3 examples
|
||||
- Basic usage
|
||||
- With options
|
||||
- Common patterns
|
||||
|
||||
4. **Related Docs**: Link to related API and CLI docs using absolute paths
|
||||
|
||||
5. **File Naming**: `NNN_CLI_CommandName.md` where NNN = execution order (101-999)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user