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:
Accusys
2026-07-27 02:15:51 +08:00
parent fcdeab82e6
commit 39a2cbc65b
118 changed files with 19386 additions and 2964 deletions
+146 -20
View File
@@ -40,6 +40,7 @@ pub struct SearchResult {
pub file_name: Option<String>,
pub serve_url: Option<String>,
pub thumbnail_url: Option<String>,
pub source_type: Option<String>,
}
#[derive(Debug, Serialize)]
@@ -63,6 +64,14 @@ struct MergedResult {
source: String,
}
fn map_chunk_type_to_source(chunk_type: &str) -> String {
match chunk_type.to_lowercase().as_str() {
"ocr" => "ocr".to_string(),
"sentence" => "asrx".to_string(),
other => other.to_string(),
}
}
/// Enrich a Qdrant search result with full data from PostgreSQL
async fn enrich_from_pg(
db: &crate::core::db::PostgresDb,
@@ -89,6 +98,7 @@ async fn enrich_from_pg(
file_name: None,
serve_url: None,
thumbnail_url: None,
source_type: Some(map_chunk_type_to_source(&p.chunk_type)),
}),
Ok(None) => None,
Err(e) => {
@@ -117,6 +127,7 @@ fn pg_result_to_search(p: &SemanticSearchResult) -> SearchResult {
file_name: None,
serve_url: None,
thumbnail_url: None,
source_type: Some(map_chunk_type_to_source(&p.chunk_type)),
}
}
@@ -417,7 +428,7 @@ pub async fn smart_search(
let is_keyword_only = mr.keyword_score.is_some() && mr.semantic_score.is_none();
let is_semantic_only = mr.semantic_score.is_some() && mr.keyword_score.is_none();
let skip_text_match = is_keyword_only || is_semantic_only;
if !skip_text_match {
// 關鍵字過濾: CJK 用子字串匹配,英文用單詞邊界匹配
// 使用 text_content 或 summary 進行匹配
@@ -464,23 +475,11 @@ pub async fn smart_search(
pg.summary.clone()
};
// Determine source prefix based on content field
let source_prefix = if let Some(ref content) = pg.content {
let text = content.get("text").and_then(|t| t.as_str()).unwrap_or("");
let ocr_text = content.get("ocr_text").and_then(|t| t.as_str()).unwrap_or("");
let has_asrx = !text.trim().is_empty();
let has_ocr = !ocr_text.trim().is_empty();
if has_asrx && has_ocr {
"[ASRX+OCR] "
} else if has_asrx {
"[ASRX] "
} else if has_ocr {
"[OCR] "
} else {
""
}
let source_type_value = map_chunk_type_to_source(&pg.chunk_type);
let source_prefix = if pg.chunk_type == "ocr" {
"[OCR] "
} else if pg.chunk_type == "sentence" {
"[ASRX] "
} else {
""
};
@@ -497,7 +496,11 @@ pub async fn smart_search(
end_time: pg.end_time,
raw_text: None,
summary: Some(format!("{}{}", source_prefix, display_text)),
text_content: Some(format!("{}{}", source_prefix, pg.text_content.clone().unwrap_or_default())),
text_content: Some(format!(
"{}{}",
source_prefix,
pg.text_content.clone().unwrap_or_default()
)),
metadata: pg.metadata.clone(),
similarity: Some(mr.score),
file_name: None,
@@ -508,6 +511,7 @@ pub async fn smart_search(
fu, mr.chunk_id
)
}),
source_type: Some(source_type_value),
});
}
}
@@ -569,8 +573,130 @@ pub async fn smart_search(
}))
}
/// Keyword-only search (BM25, no vector)
pub async fn keyword_search(
State(state): State<crate::api::types::AppState>,
Json(req): Json<SmartSearchRequest>,
) -> Result<Json<SmartSearchResponse>, (StatusCode, Json<serde_json::Value>)> {
let db = &state.db;
let page = req.page.unwrap_or(1).max(1);
let page_size = req.page_size.unwrap_or(5).max(1);
let limit = page_size;
// Keyword search via PG BM25
let keyword_results = db
.search_bm25(&req.query, req.file_uuid.as_deref(), limit as i64)
.await
.map_err(|e| {
tracing::error!("Keyword search failed: {}", e);
(
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({ "error": e.to_string() })),
)
})?;
tracing::info!(
"Keyword search: {} hits for '{}'",
keyword_results.len(),
req.query
);
let mut results = Vec::new();
for row in keyword_results.iter() {
if let Ok(Some(p)) = db
.get_chunk_by_id_no_embedding(&row.file_uuid, &row.chunk_id)
.await
{
results.push(SearchResult {
id: 0,
file_uuid: p.file_uuid.clone(),
parent_id: p.scene_order,
scene_order: Some(p.scene_order),
start_frame: p.start_frame,
end_frame: p.end_frame,
fps: p.fps,
start_time: p.start_time,
end_time: p.end_time,
raw_text: None,
summary: Some(p.summary.clone()),
text_content: p.text_content.clone(),
metadata: p.metadata.clone(),
similarity: Some(row.bm25_score as f64),
file_name: None,
serve_url: None,
thumbnail_url: None,
source_type: Some(map_chunk_type_to_source(&p.chunk_type)),
});
}
}
Ok(Json(SmartSearchResponse {
query: req.query,
results,
page,
page_size,
strategy: "keyword".to_string(),
}))
}
/// Semantic-only search (vector, no keyword)
pub async fn semantic_search(
State(state): State<crate::api::types::AppState>,
Json(req): Json<SmartSearchRequest>,
) -> Result<Json<SmartSearchResponse>, (StatusCode, Json<serde_json::Value>)> {
let db = &state.db;
let qdrant = &state.qdrant;
let page = req.page.unwrap_or(1).max(1);
let page_size = req.page_size.unwrap_or(5).max(1);
let limit = page_size;
// Generate embedding
let embedder = Embedder::new("embeddinggemma-300m".to_string());
let embedding = embedder.embed_query(&req.query).await.map_err(|e| {
tracing::error!("Embedding failed: {}", e);
(
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({ "error": e.to_string() })),
)
})?;
// Semantic search via Qdrant
let semantic_results = if let Some(file_uuid) = &req.file_uuid {
qdrant
.search_in_uuid(&embedding, file_uuid, limit)
.await
.unwrap_or_default()
} else {
qdrant.search(&embedding, limit).await.unwrap_or_default()
};
tracing::info!(
"Semantic search: {} hits for '{}'",
semantic_results.len(),
req.query
);
let mut results = Vec::new();
for hit in semantic_results.iter() {
if let Some(p) = enrich_from_pg(db, &hit.uuid, &hit.chunk_id, hit.score).await {
results.push(p);
}
}
Ok(Json(SmartSearchResponse {
query: req.query,
results,
page,
page_size,
strategy: "semantic".to_string(),
}))
}
// --- Router Setup ---
pub fn search_routes() -> Router<crate::api::types::AppState> {
Router::new().route("/api/v1/search/smart", post(smart_search))
Router::new()
.route("/api/v1/search/smart", post(smart_search))
.route("/api/v1/search/keyword", post(keyword_search))
.route("/api/v1/search/semantic", post(semantic_search))
}