Skip to content

Commit 5bff056

Browse files
CopilotMte90
andcommitted
Fix vector search initialization and clear_project_data issues
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent e22f611 commit 5bff056

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

db/operations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ def clear_project_data(database_path: str) -> None:
231231
cur.execute("DELETE FROM chunks")
232232
# Delete files
233233
cur.execute("DELETE FROM files")
234+
# Clear vector metadata to allow re-indexing with different embedding dimensions
235+
cur.execute("DELETE FROM vector_meta WHERE key = 'dimension'")
234236
conn.commit()
235237

236238
# Invalidate caches

db/vector_operations.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,24 @@ def search_vectors(database_path: str, q_vector: List[float], top_k: int = 5) ->
210210
load_sqlite_vector_extension(conn)
211211
ensure_chunks_and_meta(conn)
212212

213-
q_json = json.dumps(q_vector)
213+
# Ensure vector index is initialized before searching
214214
cur = conn.cursor()
215+
cur.execute("SELECT value FROM vector_meta WHERE key = 'dimension'")
216+
row = cur.fetchone()
217+
if not row:
218+
# No dimension stored means no vectors have been indexed yet
219+
logger.info("No vector dimension found in metadata - no chunks indexed yet")
220+
return []
221+
222+
dim = int(row[0])
223+
try:
224+
conn.execute(f"SELECT vector_init('chunks', 'embedding', 'dimension={dim},type=FLOAT32,distance=COSINE')")
225+
logger.debug(f"Vector index initialized for search with dimension {dim}")
226+
except Exception as e:
227+
logger.error(f"vector_init failed during search: {e}")
228+
raise RuntimeError(f"vector_init failed during search: {e}") from e
229+
230+
q_json = json.dumps(q_vector)
215231
try:
216232
cur.execute(
217233
"""

0 commit comments

Comments
 (0)