fix(search): close three P2 correctness gaps from code review
- vector: increment embedding_revision whenever delete_embedding is called so the HNSW cache is invalidated after image/folder deletions, not just after inserts - hnsw_index: fix race in build_index — read the revision before fetching embeddings and again after the parallel_insert; retry the whole build if the revision advanced during construction, ensuring the cached index always reflects a consistent snapshot - commands: replace the fixed 4× over-fetch in semantic_search_images with a progressive doubling loop; start at exactly `limit` candidates and double the batch (capped at 8192) until the page is filled or the vector table is exhausted, preventing both under- and over-fetching
This commit is contained in:
@@ -33,6 +33,12 @@ pub fn migrate(conn: &Connection) -> Result<()> {
|
||||
#[allow(dead_code)]
|
||||
pub fn delete_embedding(conn: &Connection, image_id: i64) -> Result<()> {
|
||||
conn.execute("DELETE FROM image_vec WHERE image_id = ?1", [image_id])?;
|
||||
// Advance the revision so any cached HNSW index is invalidated after deletions.
|
||||
conn.execute(
|
||||
"INSERT INTO app_kv (key, value) VALUES ('embedding_revision', 1)
|
||||
ON CONFLICT(key) DO UPDATE SET value = value + 1",
|
||||
[],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user