feat: VLM summary vector search integration

- Add vlm_point_id column to trace_profiles (stores Qdrant point ID)
- Add upsert_chunk_embedding_u64 to QdrantDb (numeric ID support)
- Add chunk_id to VLM payload in Qdrant for search enrichment
- Update enrich_from_pg to fallback to VLM lookup when chunk not found
- Add /api/v1/file/:uuid/vlm-summary endpoint for manual trigger
- Fix VLM point_id: use u64 hash instead of string (Qdrant requirement)
- Fix VLM timeout: was 0 (immediate timeout), now 120s

Verified: semantic search returns [vlm] results with proper enrichment
This commit is contained in:
Accusys
2026-08-22 12:10:47 +08:00
parent 476a31ecc6
commit 054545bccd
5 changed files with 184 additions and 10 deletions
+71
View File
@@ -878,6 +878,73 @@ async fn verify_file_handler(
Json(report)
}
/// Manually trigger VLM summary generation for an existing file.
/// Non-blocking: returns immediately, VLM runs in background.
async fn trigger_vlm_summary(
State(state): State<AppState>,
Path(file_uuid): Path<String>,
) -> Json<serde_json::Value> {
let db = state.db.clone();
let output_dir = crate::core::config::OUTPUT_DIR.clone();
// Check if file has face traces
let tp_table = crate::core::db::schema::table_name("trace_profiles");
let face_count: i64 = sqlx::query_scalar(&format!(
"SELECT COUNT(*) FROM {tp_table} WHERE file_uuid = $1"
))
.bind(&file_uuid)
.fetch_one(db.pool())
.await
.unwrap_or(0);
if face_count == 0 {
return Json(serde_json::json!({
"success": false,
"message": "No face traces found for this file",
"file_uuid": file_uuid,
}));
}
// Check how many traces already have vlm_description
let done_count: i64 = sqlx::query_scalar(&format!(
"SELECT COUNT(*) FROM {tp_table} WHERE file_uuid = $1 AND vlm_description IS NOT NULL AND vlm_description != ''"
))
.bind(&file_uuid)
.fetch_one(db.pool())
.await
.unwrap_or(0);
let pending = face_count - done_count;
if pending == 0 {
return Json(serde_json::json!({
"success": true,
"message": "All traces already have VLM summaries",
"file_uuid": file_uuid,
"total_traces": face_count,
"already_done": done_count,
}));
}
// Spawn VLM generation in background
let file_uuid_clone = file_uuid.clone();
tokio::spawn(async move {
let redis = crate::core::db::RedisClient::new().ok();
crate::core::processor::vlm_summary::generate_vlm_summaries(
&db, &file_uuid_clone, &output_dir, redis.map(std::sync::Arc::new),
)
.await;
});
Json(serde_json::json!({
"success": true,
"message": format!("VLM summary generation started for {} traces", pending),
"file_uuid": file_uuid,
"total_traces": face_count,
"already_done": done_count,
"pending": pending,
}))
}
pub fn processing_routes() -> Router<AppState> {
Router::new()
.route("/api/v1/file/:file_uuid/process", post(trigger_processing))
@@ -903,4 +970,8 @@ pub fn processing_routes() -> Router<AppState> {
get(get_processor_counts),
)
.route("/api/v1/file/:file_uuid/verify", get(verify_file_handler))
.route(
"/api/v1/file/:file_uuid/vlm-summary",
post(trigger_vlm_summary),
)
}