feat(settings): add "Rebuild semantic index" maintenance action
Drops and recreates the sqlite-vec tables at the current model dimension, then re-queues every image for embedding. Fixes "dimension mismatch" search errors that occur when the vector table was built for a different model/dimension (e.g. after experimenting with 768-dim models against this 512-dim build). The rebuild runs under the embedding worker's DB write lock and resets the job queue inside a single transaction, so it can't interleave with an in-flight embedding batch (per code review).
This commit is contained in:
@@ -36,6 +36,18 @@ pub fn migrate(conn: &Connection) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Drop and recreate the vector tables at the current `CLIP_VECTOR_DIM`. Used by
|
||||
/// the "Rebuild semantic index" maintenance action when stored vectors no longer
|
||||
/// match the active model's dimension (e.g. after switching embedding models),
|
||||
/// so the columns are rebuilt to the right size before embeddings regenerate.
|
||||
pub fn rebuild_tables(conn: &Connection) -> Result<()> {
|
||||
conn.execute_batch(
|
||||
"DROP TABLE IF EXISTS image_vec;
|
||||
DROP TABLE IF EXISTS caption_vec;",
|
||||
)?;
|
||||
migrate(conn)
|
||||
}
|
||||
|
||||
#[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])?;
|
||||
|
||||
Reference in New Issue
Block a user