feat: VLM summary vector storage in Qdrant for semantic search

- Add upsert_vlm_embedding to QdrantDb with trace_id in payload
- chunk_id format: {file_uuid}_t{trace_id_hex} for search enrichment
- Update enrich_vlm_from_pg to extract trace_id from chunk_id
- VLM summary now searchable via semantic search with source_type=vlm
This commit is contained in:
Accusys
2026-08-25 02:57:18 +08:00
parent 2bbbf1950d
commit 29f14e83c4
3 changed files with 72 additions and 19 deletions
+19 -10
View File
@@ -143,25 +143,34 @@ async fn enrich_from_pg(
}
}
/// Enrich a VLM summary search result from trace_profiles, looked up by vlm_point_id.
/// Enrich a VLM summary search result from trace_profiles.
/// The chunk_id from Qdrant is in format "{file_uuid}_t{trace_id_hex}".
async fn enrich_vlm_from_pg(
db: &crate::core::db::PostgresDb,
file_uuid: &str,
point_id: &str,
chunk_id: &str,
qdrant_score: f32,
) -> Option<SearchResult> {
// Extract trace_id from chunk_id format: "{file_uuid}_t{trace_id_hex}"
let trace_id: i32 = if chunk_id.len() > 34 && chunk_id.starts_with(file_uuid) {
let hex_part = &chunk_id[33..]; // after "{file_uuid}_t"
i32::from_str_radix(hex_part, 16).ok()?
} else {
return None;
};
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"
let rows: Vec<(i64, i64, Option<String>)> = sqlx::query_as(&format!(
"SELECT start_frame, end_frame, vlm_description FROM {tp_table} \
WHERE file_uuid = $1 AND trace_id = $2"
))
.bind(file_uuid)
.bind(point_id)
.bind(trace_id)
.fetch_all(db.pool())
.await
.ok()?;
let (tid, start_frame, end_frame, vlm_desc) = rows.into_iter().next()?;
let (start_frame, end_frame, vlm_desc) = rows.into_iter().next()?;
let text = vlm_desc.unwrap_or_default();
Some(SearchResult {
@@ -175,16 +184,16 @@ async fn enrich_vlm_from_pg(
start_time: 0.0,
end_time: 0.0,
raw_text: None,
summary: Some(format!("VLM trace_{}", tid)),
summary: Some(format!("VLM trace_{}", trace_id)),
text_content: Some(text),
metadata: Some(serde_json::json!({
"type": "vlm_summary",
"trace_id": tid,
"trace_id": trace_id,
})),
similarity: Some(qdrant_score as f64),
file_name: None,
serve_url: None,
thumbnail_url: Some(format!("/api/v1/file/{}/trace/{}/thumbnail", file_uuid, tid)),
thumbnail_url: Some(format!("/api/v1/file/{}/trace/{}/thumbnail", file_uuid, trace_id)),
source_type: Some("vlm".to_string()),
})
}