Simplify deleting all chunks

This commit is contained in:
Yiorgis Gozadinos 2025-09-02 15:13:31 +03:00
parent b73949c784
commit 75e878308e
No known key found for this signature in database

View file

@ -51,7 +51,6 @@ class ChunkRepository:
embedding = entity.embedding embedding = entity.embedding
else: else:
embedding = await self.embedder.embed(entity.content) embedding = await self.embedder.embed(entity.content)
chunk_record = self.store.ChunkRecord( chunk_record = self.store.ChunkRecord(
id=chunk_id, id=chunk_id,
document_id=entity.document_id, document_id=entity.document_id,
@ -179,21 +178,13 @@ class ChunkRepository:
async def delete_all(self) -> None: async def delete_all(self) -> None:
"""Delete all chunks from the database.""" """Delete all chunks from the database."""
count = len( # Drop and recreate table to clear all data
list( self.store.db.drop_table("chunks")
self.store.chunks_table.search() self.store.chunks_table = self.store.db.create_table(
.limit(1) "chunks", schema=self.store.ChunkRecord
.to_pydantic(self.store.ChunkRecord)
)
) )
if count > 0: # Create FTS index on the new table
# Drop and recreate table to clear all data self.store.chunks_table.create_fts_index("content", replace=True)
self.store.db.drop_table("chunks")
self.store.chunks_table = self.store.db.create_table(
"chunks", schema=self.store.ChunkRecord
)
# Create FTS index on the new table
self.store.chunks_table.create_fts_index("content", replace=True)
async def delete_by_document_id(self, document_id: str) -> bool: async def delete_by_document_id(self, document_id: str) -> bool:
"""Delete all chunks for a document.""" """Delete all chunks for a document."""