From e44a29012eb5676453b78f16164ca97c6b2971c7 Mon Sep 17 00:00:00 2001 From: Derek Higgins Date: Fri, 18 Jul 2025 16:39:23 +0100 Subject: [PATCH] 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 --- .../inline/vector_io/sqlite_vec/sqlite_vec.py | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/llama_stack/providers/inline/vector_io/sqlite_vec/sqlite_vec.py b/llama_stack/providers/inline/vector_io/sqlite_vec/sqlite_vec.py index a8331e65a..3f31fa4ab 100644 --- a/llama_stack/providers/inline/vector_io/sqlite_vec/sqlite_vec.py +++ b/llama_stack/providers/inline/vector_io/sqlite_vec/sqlite_vec.py @@ -425,6 +425,35 @@ class SQLiteVecIndex(EmbeddingIndex): 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): """ @@ -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: """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)