From dfa36839cbd6706bf5612d0e743740551110e4db Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Jan 2026 22:33:33 +0400 Subject: [PATCH] fix: re-index files in local mode watcher --- src/watcher.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/src/watcher.rs b/src/watcher.rs index 816219f..1d7b812 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -340,12 +340,13 @@ impl FileWatcher { ); } Mode::Local => { + let engine = crate::core::EmbeddingEngine::new(&self.config)?; + self.index_file_local(&db, &engine, path, &content)?; println!( - " {} {} {} {}", - style("[~]").yellow(), - style("modified").yellow(), - style(filename).cyan(), - style("(pending)").dim() + " {} {} {}", + style("[+]").green(), + style("indexed").green(), + style(filename).cyan() ); } } @@ -354,6 +355,45 @@ impl FileWatcher { Ok(()) } + fn index_file_local( + &self, + db: &Database, + engine: &crate::core::EmbeddingEngine, + path: &Path, + content: &str, + ) -> Result<()> { + use sha2::{Digest, Sha256}; + + let mut hasher = Sha256::new(); + hasher.update(content.as_bytes()); + let hash = hex::encode(hasher.finalize()); + + // Chunk the content + let chunks = self.chunk_content(content); + if chunks.is_empty() { + return Ok(()); + } + + let file_id = db.insert_file(path, &hash)?; + + // Get embeddings locally + let chunk_texts: Vec<&str> = chunks.iter().map(|c| c.content.as_str()).collect(); + let embeddings = engine.embed_batch(&chunk_texts)?; + + for (idx, (chunk, embedding)) in chunks.iter().zip(embeddings.iter()).enumerate() { + db.insert_chunk( + file_id, + idx as i32, + &chunk.content, + chunk.start_line, + chunk.end_line, + embedding, + )?; + } + + Ok(()) + } + fn index_file_server( &self, db: &Database,