feat(vector-io): implement chunk deletion for SQLite vector provider

Add delete_chunk() method with transaction-safe deletion
Delete from metadata, vector, and FTS tables
Implement _delete_openai_chunk_from_vector_store() for OpenAI compatibility

Signed-off-by: Derek Higgins <derekh@redhat.com>
This commit is contained in:
Derek Higgins 2025-07-18 16:39:23 +01:00
parent 3d4b32db0a
commit e44a29012e

View file

@ -425,6 +425,35 @@ class SQLiteVecIndex(EmbeddingIndex):
return QueryChunksResponse(chunks=chunks, scores=scores) return QueryChunksResponse(chunks=chunks, scores=scores)
async def delete_chunk(self, chunk_id: str) -> None:
"""Remove a chunk from the SQLite vector store."""
def _delete_chunk():
connection = _create_sqlite_connection(self.db_path)
cur = connection.cursor()
try:
cur.execute("BEGIN TRANSACTION")
# Delete from metadata table
cur.execute(f"DELETE FROM {self.metadata_table} WHERE id = ?", (chunk_id,))
# Delete from vector table
cur.execute(f"DELETE FROM {self.vector_table} WHERE id = ?", (chunk_id,))
# Delete from FTS table
cur.execute(f"DELETE FROM {self.fts_table} WHERE id = ?", (chunk_id,))
connection.commit()
except Exception as e:
connection.rollback()
logger.error(f"Error deleting chunk {chunk_id}: {e}")
raise
finally:
cur.close()
connection.close()
await asyncio.to_thread(_delete_chunk)
class SQLiteVecVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtocolPrivate): class SQLiteVecVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtocolPrivate):
""" """
@ -523,4 +552,9 @@ class SQLiteVecVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtoc
async def _delete_openai_chunk_from_vector_store(self, store_id: str, chunk_id: str) -> None: async def _delete_openai_chunk_from_vector_store(self, store_id: str, chunk_id: str) -> None:
"""Delete a chunk from a sqlite_vec index.""" """Delete a chunk from a sqlite_vec index."""
pass # TODO index = await self._get_and_cache_vector_db_index(store_id)
if not index:
raise ValueError(f"Vector DB {store_id} not found")
# Use the index's delete_chunk method
await index.index.delete_chunk(chunk_id)