Skip to content

Commit 7c6ba89

Browse files
committed
fix(store): clear FTS on reindex and use stored dim for vec table init
reset_for_reindex now also deletes from chunks_fts so stale keyword entries don't survive a dimension migration. Store::init() reads the stored embedding_dim from meta to create the vec table with the correct dimension, preventing a stale 384-dim table from persisting when the model outputs 256-dim vectors.
1 parent bd87d71 commit 7c6ba89

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/store.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ impl Store {
141141
.context("failed to initialize schema")?;
142142
self.migrate()?;
143143
self.ensure_fts_table()?;
144-
crate::vecstore::init_vec_table(&self.conn, 256)?;
144+
// Use stored embedding dimension if available, defaulting to 256 for new databases.
145+
let dim = self
146+
.get_meta("embedding_dim")?
147+
.and_then(|s| s.parse::<usize>().ok())
148+
.unwrap_or(256);
149+
crate::vecstore::init_vec_table(&self.conn, dim)?;
145150
self.migrate_vectors_to_vec0()?;
146151
Ok(())
147152
}
@@ -1165,11 +1170,12 @@ impl Store {
11651170
}
11661171
}
11671172

1168-
/// Drop the vec table and all chunk records. Used during dimension migration.
1173+
/// Drop the vec table and all chunk/FTS records. Used during dimension migration.
11691174
pub fn reset_for_reindex(&self, new_dim: usize) -> Result<()> {
11701175
self.conn.execute("DROP TABLE IF EXISTS chunks_vec", [])?;
11711176
crate::vecstore::init_vec_table(&self.conn, new_dim)?;
11721177
self.conn.execute("DELETE FROM chunks", [])?;
1178+
self.conn.execute("DELETE FROM chunks_fts", [])?;
11731179
Ok(())
11741180
}
11751181

0 commit comments

Comments
 (0)