fix: face group name read consistency, sync_file_status fix, cleanup ghost records, identity_agent replaced with face_dedup
- get_face_groups_handler: COALESCE(tp.name, tn.label) for name consistency - sync_file_status: compare JSON vs pre_chunks (not chunk table) - face consistency: compare frames.len() not total_faces - cleanup 2 ghost records with NULL file_name/file_path - replace identity_agent with face_dedup in pipeline stages - remove identity_agent_api.rs and all references - update required_processors to match actual processors - update AGENTS.md with team responsibilities - add Studio pipeline changes documentation
This commit is contained in:
+91
-37
@@ -80,50 +80,71 @@ pub struct AgentSearchResponse {
|
||||
|
||||
const SYSTEM_PROMPT: &str = r#"你是 Momentry 影片分析助手。回答用戶關於影片內容的問題。
|
||||
|
||||
## Greeting and Conversation Handling (CRITICAL - Check First)
|
||||
- If user input is ONLY a greeting ("hi", "hello", "hey", "你好", "您好", "hallo"):
|
||||
- **DO NOT call any search tools**
|
||||
- Respond in English: "Hello! I'm Momentry video analysis assistant. I can help you search video content, find people, and analyze scenes. What would you like to know?"
|
||||
- If user asks "how are you" or "thanks", respond briefly in English without tools
|
||||
- **Only use search tools when user asks about VIDEO CONTENT**
|
||||
|
||||
## Response Language (MANDATORY)
|
||||
- **DEFAULT: English** - You MUST respond in English unless user explicitly requests another language
|
||||
- This applies to ALL responses: greetings, search results, explanations
|
||||
- Example: If user asks "gun", respond in English about gun-related content
|
||||
- Only respond in Chinese if user writes in Chinese AND explicitly requests Chinese response
|
||||
|
||||
## 核心原則:預設搜尋所有影片,不主動反問
|
||||
- **所有查詢都預設搜尋全部影片**,不要問用戶「哪部影片」
|
||||
- 如果搜尋到多部影片,直接列出所有結果,不要反問用戶選擇
|
||||
- 只有當多個搜尋工具都返回空、且問題明顯指向特定影片時,才問用戶
|
||||
- 搜尋工具(find_file, list_files, smart_search, universal_search)的 file_uuid 參數可省略以搜尋全部
|
||||
- 搜尋工具(smart_search, semantic_search, trace_search)的 file_uuid 參數可省略以搜尋全部
|
||||
|
||||
## 工具使用規則(重要:優先使用 smart_search)
|
||||
1. **內容/關鍵字問題優先使用 smart_search** — 可以找到影片內的具體文字內容(OCR、ASR)
|
||||
2. **如果 smart_search 找到結果,附帶顯示 chunk 文字內容**(包含 [OCR]、[ASRX] 標記)
|
||||
3. find_file 僅用於搜尋片名,不適合搜尋內容關鍵字
|
||||
4. 人物問題使用 tkg_query
|
||||
5. 人物台詞/發言問題使用 identities_search(輸入人名→回傳台詞片段)
|
||||
6. 人物對話互動(誰跟誰說話)使用 tkg_query 的 speaker_interaction
|
||||
7. 人物台詞內容使用 tkg_query 的 speaker_dialogue
|
||||
8. 用文字反查人物使用 identity_text(輸入關鍵字→找出誰說/提到這段話)
|
||||
9. 畫面分析使用 analyze_frame — 可以分析影片中的任何畫面內容(場景、人物表情、動作、物件等)
|
||||
10. **人物外貌/衣著/顏色問題使用 vlm_describe** — 用 trace_id 查人臉裁切圖,經 VLM 分析描述衣著顏色、款式、配件等
|
||||
11. **vlm_describe 使用流程**:先用 tkg_query top_identities/identity_traces 找到該人的 trace_id,再呼叫 vlm_describe(file_uuid + trace_id)
|
||||
12. **可以同時呼叫多個工具,但需符合以下條件:**
|
||||
- ✅ 查詢多部影片的相同資訊(如:3部影片的人物列表)
|
||||
- ✅ 需要組合多個來源的資訊才能回答(如:file_info + tkg_query)
|
||||
- ❌ 不要為了「嘗試所有可能」而盲目並行呼叫
|
||||
- ❌ 如果單一工具已返回足夠答案,不需要額外呼叫
|
||||
- ❌ 如果 smart_search 已找到相關 chunk,不需要再呼叫 find_file
|
||||
- ❌ 如果單一工具已返回足夠答案,不需要額外呼叫
|
||||
## 搜尋工具選擇策略(重要:根據問題類型選擇正確工具)
|
||||
|
||||
## 回答規則
|
||||
### 優先順序(按此順序選擇工具)
|
||||
1. **semantic_search** - 語意搜尋 → **優先使用(適合大多數查詢)**
|
||||
2. **smart_search** - 精確關鍵字匹配(僅在需要精確匹配時使用)
|
||||
3. **trace_search** - 人物外貌、衣著、地點
|
||||
4. **find_file** - 僅搜尋片名(不搜尋內容)
|
||||
|
||||
### semantic_search(語意搜尋)- 優先使用
|
||||
- **使用時機**:大多數查詢(理解意圖、概念性問題、一般話題)
|
||||
- **範例**:「gun」、「car」、「他在做什麼」、「發生了什麼事」
|
||||
- **回傳**:語意相關的 Top 10 chunk 卡片(text_preview, score, frame_range)
|
||||
|
||||
### smart_search(精確關鍵字匹配)
|
||||
- **使用時機**:需要精確匹配專有名詞、特定詞彙(如人名、地名、專業術語)
|
||||
- **範例**:「Cary Grant」、「Paris」、「確切的台詞引用」
|
||||
- **回傳**:包含關鍵字的 Top 10 chunk 卡片(text_content, frame_range)
|
||||
|
||||
### trace_search(人物軌跡 VLM 搜尋)
|
||||
- **使用時機**:搜尋人物外貌、衣著、地點、場景
|
||||
- **範例**:「穿藍色衣服的人」、「在展場出現的人」、「戴眼鏡的人」
|
||||
- **回傳**:符合的 face trace 卡片(name, vlm_description, vlm_clothing, vlm_tags, frame_range)
|
||||
|
||||
### face_profile_search(用名字或 VLM 註記搜尋人臉)
|
||||
- **使用時機**:用「人名」或「VLM 註記」搜尋已命名的人臉畫面
|
||||
- **範例**:「找出 Susan 的畫面」、「穿藍色衣服的人」、「在展場的人」
|
||||
- **搜尋欄位**:name, vlm_description, vlm_clothing, vlm_tags, vlm_location, vlm_setting
|
||||
- **回傳**:符合的 face profile 卡片(name, key_frame, key_face, frame_range, time_range)
|
||||
|
||||
### find_file(僅搜尋片名)
|
||||
- **使用時機**:僅搜尋影片檔名
|
||||
- **範例**:「find a video named action」
|
||||
- **注意**:不適合搜尋內容,內容搜尋請用 semantic_search
|
||||
|
||||
## 回答格式
|
||||
- 回答長度依問題類型調整:
|
||||
- 簡單查詢(如「列出影片」)→ 簡潔列表回答(1-2句)
|
||||
- 分析問題(如「描述情節」)→ 詳細回答(3-5句)
|
||||
- 計數問題(如「有幾個場景」)→ 直接回答數字 + 簡短說明
|
||||
- 回答格式:
|
||||
- ✅ 如果找到影片,附上 file_uuid
|
||||
- ✅ 對於人物問題,說出角色名和演員名(如果有)
|
||||
- ✅ 引用資料時附上具體數字(frame 編號、時間秒數)
|
||||
- ❌ 不要輸出 JSON 格式,用自然語言回答
|
||||
- ❌ 不要編造資料,如果找不到就明確說「找不到」
|
||||
- 簡單查詢 → 簡潔列表回答(1-2句)
|
||||
- 分析問題 → 詳細回答(3-5句)
|
||||
- **回傳 Top 10 卡片**:每個搜尋工具會回傳最多 10 張卡片
|
||||
- 卡片包含:file_uuid, chunk_id/trace_id, start_time, end_time, score, text_preview/vlm_description
|
||||
- 用自然語言回答,附上 file_name 和時間範圍
|
||||
|
||||
## 停止規則(重要)
|
||||
## 停止規則
|
||||
- **如果已經找到足夠資訊回答用戶問題,立即停止呼叫工具,直接回答**
|
||||
- **如果連續 2 次呼叫工具都返回空結果或相同資訊,停止並告知用戶「找不到更多相關資訊」**
|
||||
- **如果用戶問題不明確或範圍過大,停止並提供簡潔摘要**
|
||||
- **如果單一工具呼叫返回完整答案,不需要額外呼叫其他工具補充**
|
||||
- **優化效率:避免重複呼叫相同工具或查詢相同內容**"#;
|
||||
- **如果連續 2 次呼叫工具都返回空結果,停止並告知「找不到更多相關資訊」**
|
||||
- **優化效率:避免重複呼叫相同工具**"#;
|
||||
|
||||
fn make_tools(pool: &sqlx::PgPool) -> Vec<ToolDef> {
|
||||
vec![
|
||||
@@ -161,11 +182,31 @@ fn make_tools(pool: &sqlx::PgPool) -> Vec<ToolDef> {
|
||||
),
|
||||
function_calling::make_tool(
|
||||
"smart_search",
|
||||
"語意搜尋 chunk 文字內容。適合需要理解意圖的查詢。",
|
||||
"關鍵字搜尋 chunk 文字內容(ILIKE)。適合精確匹配專有名詞、特定詞彙。",
|
||||
serde_json::json!({
|
||||
"file_uuid": {"type": "string", "description": "限制搜尋範圍(可選)"},
|
||||
"query": {"type": "string", "description": "搜尋關鍵字"},
|
||||
"limit": {"type": "integer", "default": 5}
|
||||
"limit": {"type": "integer", "default": 10}
|
||||
}),
|
||||
vec!["query"],
|
||||
),
|
||||
function_calling::make_tool(
|
||||
"semantic_search",
|
||||
"語意搜尋(embedding + Qdrant)。適合理解意圖的查詢,如「他在做什麼」、「發生了什麼事」。",
|
||||
serde_json::json!({
|
||||
"file_uuid": {"type": "string", "description": "限制搜尋範圍(可選)"},
|
||||
"query": {"type": "string", "description": "搜尋關鍵字(會轉為 embedding)"},
|
||||
"limit": {"type": "integer", "default": 10}
|
||||
}),
|
||||
vec!["query"],
|
||||
),
|
||||
function_calling::make_tool(
|
||||
"trace_search",
|
||||
"搜尋人物軌跡的 VLM 註記(外貌描述、衣著、標籤、地點、場景)。輸入關鍵字,回傳符合的 face trace 卡片。適合回答「穿藍色衣服的人」、「在展場出現的人」。",
|
||||
serde_json::json!({
|
||||
"file_uuid": {"type": "string", "description": "限制搜尋範圍(可選)"},
|
||||
"query": {"type": "string", "description": "搜尋關鍵字(會搜尋 name, vlm_description, vlm_clothing, vlm_tags, vlm_location, vlm_setting)"},
|
||||
"limit": {"type": "integer", "default": 10}
|
||||
}),
|
||||
vec!["query"],
|
||||
),
|
||||
@@ -273,6 +314,16 @@ fn make_tools(pool: &sqlx::PgPool) -> Vec<ToolDef> {
|
||||
}),
|
||||
vec!["file_uuid", "trace_id"],
|
||||
),
|
||||
function_calling::make_tool(
|
||||
"face_profile_search",
|
||||
"用名字或 VLM 註記搜尋已命名的人臉。輸入關鍵字(名字、衣著描述、地點、標籤),回傳符合的 face profile 卡片(含 key_frame、key_face、時間範圍、frame 範圍)。適合回答「找出穿藍色衣服的人」、「Susan 出現在哪」、「在展場的人」。",
|
||||
serde_json::json!({
|
||||
"name": {"type": "string", "description": "搜尋關鍵字(會搜尋 name, vlm_description, vlm_clothing, vlm_tags, vlm_location, vlm_setting)"},
|
||||
"file_uuid": {"type": "string", "description": "限制搜尋範圍(可選)"},
|
||||
"limit": {"type": "integer", "default": 10}
|
||||
}),
|
||||
vec!["name"],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -301,6 +352,8 @@ async fn execute_tool(pool: &sqlx::PgPool, tool_call: &ToolCall) -> (String, Str
|
||||
"tkg_edges_query" => tools::exec_tkg_edges_query(pool, &args).await,
|
||||
"tkg_node_detail" => tools::exec_tkg_node_detail(pool, &args).await,
|
||||
"smart_search" => tools::exec_smart_search(pool, &args).await,
|
||||
"semantic_search" => tools::exec_semantic_search(pool, &args).await,
|
||||
"trace_search" => tools::exec_trace_search(pool, &args).await,
|
||||
"identity_text" => tools::exec_identity_text(pool, &args).await,
|
||||
"identities_search" => tools::exec_identities_search(pool, &args).await,
|
||||
"get_identity_detail" => tools::exec_get_identity_detail(pool, &args).await,
|
||||
@@ -309,6 +362,7 @@ async fn execute_tool(pool: &sqlx::PgPool, tool_call: &ToolCall) -> (String, Str
|
||||
"analyze_frame" => tools::exec_analyze_frame(pool, &args).await,
|
||||
"search_by_appearance" => tools::exec_search_by_appearance(pool, &args).await,
|
||||
"vlm_describe" => tools::exec_vlm_describe(pool, &args).await,
|
||||
"face_profile_search" => tools::exec_face_profile_search(pool, &args).await,
|
||||
_ => Err(format!("Unknown tool: {}", name)),
|
||||
};
|
||||
let content = match result {
|
||||
|
||||
Reference in New Issue
Block a user