fix: sanitize SQL and narrow exception handling in indexer
This commit is contained in:
@@ -6,7 +6,7 @@ from typing import Dict, Iterator, List
|
||||
from companion.config import Config
|
||||
from companion.rag.chunker import Chunk, ChunkingRule, chunk_file
|
||||
from companion.rag.embedder import OllamaEmbedder
|
||||
from companion.rag.vector_store import VectorStore
|
||||
from companion.rag.vector_store import VectorStore, TABLE_NAME
|
||||
|
||||
|
||||
class Indexer:
|
||||
@@ -106,8 +106,8 @@ class Indexer:
|
||||
|
||||
def full_index(self) -> None:
|
||||
try:
|
||||
self.vector_store.table.drop()
|
||||
except Exception:
|
||||
self.vector_store.db.drop_table(TABLE_NAME)
|
||||
except (FileNotFoundError, ValueError):
|
||||
pass
|
||||
self.vector_store.table = self.vector_store._get_or_create_table()
|
||||
|
||||
@@ -120,10 +120,11 @@ class Indexer:
|
||||
relative_path = file_path.relative_to(self.vault_path).as_posix()
|
||||
modified_at = file_path.stat().st_mtime
|
||||
|
||||
escaped_path = relative_path.replace("'", "''")
|
||||
results = (
|
||||
self.vector_store.table.search()
|
||||
.limit(1)
|
||||
.where(f"source_file = '{relative_path}'")
|
||||
.where(f"source_file = '{escaped_path}'")
|
||||
.to_list()
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user