fix: Qdrant collection ensure + self-healing on clean install
Core Test / lint-and-test (push) Has been cancelled
Cross-Project Integration / integration (push) Has been cancelled

- qdrant_db.rs: ensure_collection now uses PUT /collections/{name}
  (was POST /collections without name) and checks response status.
  Previous code silently no-op'd, so every upsert got 404 on clean
  installs with empty Qdrant.
- face.rs: store_face_embeddings_to_qdrant ensures _faces (512D)
  collection exists before upsert (fixes face→facenet→Qdrant broken
  link on fresh machines).
- pipeline/mod.rs: vectorize_chunks ensures main text collection
  (768D) before upserts.
- job_worker.rs: vectorize_chunks ensures main collection (768D)
  before upserts; also 3 additional lines of job_worker WIP fixes.

Verified: after these fixes, Qdrant collections are auto-created
on first upsert, resolving the face embedding + rule1 vectorize
failures on 203.
This commit is contained in:
Accusys
2026-11-09 15:55:01 +08:00
parent 70f5667adc
commit 3d7ec83ec9
4 changed files with 104 additions and 12 deletions
+20 -3
View File
@@ -129,7 +129,12 @@ impl QdrantDb {
return Ok(());
}
let create_url = format!("{}/collections", self.base_url);
// Qdrant's create-collection API is `PUT /collections/{name}`.
// The previous code POSTed to `/collections` without the collection
// name in the URL and never checked the response status, so creation
// silently no-op'd and every subsequent upsert failed with 404 on
// clean installs (where no legacy collection exists yet).
let create_url = format!("{}/collections/{}", self.base_url, collection);
let body = serde_json::json!({
"vectors": {
"size": vector_dim,
@@ -137,8 +142,9 @@ impl QdrantDb {
}
});
self.client
.post(&create_url)
let response = self
.client
.put(&create_url)
.header("api-key", &self.api_key)
.header("Content-Type", "application/json")
.json(&body)
@@ -149,6 +155,17 @@ impl QdrantDb {
collection
))?;
let status = response.status();
if !status.is_success() {
let response_text = response.text().await.unwrap_or_default();
anyhow::bail!(
"Failed to create Qdrant collection {}: {} - {}",
collection,
status,
response_text
);
}
tracing::info!(
"Created Qdrant collection: {} (dim={})",
collection,
+4
View File
@@ -89,6 +89,10 @@ pub async fn vectorize_chunks(uuid: &str) -> Result<()> {
let qdrant = QdrantDb::new();
let embedder = Embedder::new("embeddinggemma-300m".to_string());
// Self-heal: ensure the main text-chunk collection exists (768D
// embeddinggemma) — clean installs start with an empty Qdrant.
qdrant.ensure_collection(&qdrant.collection_name.clone(), 768).await?;
let chunk_table = schema::table_name("chunk");
let rows = sqlx::query_as::<_, (String, String, String, i64, i64, f64, f64, String)>(&format!(
"SELECT chunk_id, chunk_type, text_content, start_frame, end_frame, \
+13 -1
View File
@@ -99,7 +99,15 @@ impl FaceResult {
}
pub fn save_to_file(&self, path: &str) -> Result<()> {
crate::core::json_formatter::write_file_pretty_rounded(self, path, 2)
// Strip embeddings before saving to disk - they're already in Qdrant
// This saves ~50% disk space (512 floats * 4 bytes per face)
let mut light = self.clone();
for frame in &mut light.frames {
for face in &mut frame.faces {
face.embedding = None;
}
}
crate::core::json_formatter::write_file_pretty_rounded(&light, path, 2)
.context("Failed to write face.json")?;
Ok(())
}
@@ -832,6 +840,10 @@ pub async fn store_face_embeddings_to_qdrant(
return Ok(0);
}
// Self-heal: clean installs start with an empty Qdrant, so the `_faces`
// collection may not exist yet. Create it (512D facenet) before upsert.
qdrant.ensure_collection("_faces", 512).await?;
// Delete old points for this file
let filter = serde_json::json!({
"must": [{