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:
+52
-2
@@ -103,7 +103,8 @@ fn map_chunk_type_to_source(chunk_type: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Enrich a Qdrant search result with full data from PostgreSQL
|
||||
/// Enrich a Qdrant search result with full data from PostgreSQL.
|
||||
/// Falls back to trace_profiles lookup for VLM summary results (matched by vlm_point_id).
|
||||
async fn enrich_from_pg(
|
||||
db: &crate::core::db::PostgresDb,
|
||||
file_uuid: &str,
|
||||
@@ -131,7 +132,10 @@ async fn enrich_from_pg(
|
||||
thumbnail_url: None,
|
||||
source_type: Some(map_chunk_type_to_source(&p.chunk_type)),
|
||||
}),
|
||||
Ok(None) => None,
|
||||
Ok(None) => {
|
||||
// Chunk not found — try VLM summary lookup by vlm_point_id
|
||||
enrich_vlm_from_pg(db, file_uuid, chunk_id, qdrant_score).await
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!("PG enrichment failed for {} {}: {}", file_uuid, chunk_id, e);
|
||||
None
|
||||
@@ -139,6 +143,52 @@ async fn enrich_from_pg(
|
||||
}
|
||||
}
|
||||
|
||||
/// Enrich a VLM summary search result from trace_profiles, looked up by vlm_point_id.
|
||||
async fn enrich_vlm_from_pg(
|
||||
db: &crate::core::db::PostgresDb,
|
||||
file_uuid: &str,
|
||||
point_id: &str,
|
||||
qdrant_score: f32,
|
||||
) -> Option<SearchResult> {
|
||||
let tp_table = crate::core::db::schema::table_name("trace_profiles");
|
||||
let rows: Vec<(i32, i64, i64, Option<String>)> = sqlx::query_as(&format!(
|
||||
"SELECT trace_id, start_frame, end_frame, vlm_description FROM {tp_table} \
|
||||
WHERE file_uuid = $1 AND vlm_point_id = $2"
|
||||
))
|
||||
.bind(file_uuid)
|
||||
.bind(point_id)
|
||||
.fetch_all(db.pool())
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
let (tid, start_frame, end_frame, vlm_desc) = rows.into_iter().next()?;
|
||||
let text = vlm_desc.unwrap_or_default();
|
||||
|
||||
Some(SearchResult {
|
||||
id: 0,
|
||||
file_uuid: Some(file_uuid.to_string()),
|
||||
parent_id: 0,
|
||||
scene_order: None,
|
||||
start_frame,
|
||||
end_frame,
|
||||
fps: 0.0,
|
||||
start_time: 0.0,
|
||||
end_time: 0.0,
|
||||
raw_text: None,
|
||||
summary: Some(format!("VLM trace_{}", tid)),
|
||||
text_content: Some(text),
|
||||
metadata: Some(serde_json::json!({
|
||||
"type": "vlm_summary",
|
||||
"trace_id": tid,
|
||||
})),
|
||||
similarity: Some(qdrant_score as f64),
|
||||
file_name: None,
|
||||
serve_url: None,
|
||||
thumbnail_url: Some(format!("/api/v1/file/{}/trace/{}/thumbnail", file_uuid, tid)),
|
||||
source_type: Some("vlm".to_string()),
|
||||
})
|
||||
}
|
||||
|
||||
fn pg_result_to_search(p: &SemanticSearchResult) -> SearchResult {
|
||||
SearchResult {
|
||||
id: 0,
|
||||
|
||||
Reference in New Issue
Block a user