feat: implement chunk deletion for vector stores

Add support for deleting individual chunks from vector stores

- Add abstract delete_chunk() method to EmbeddingIndex base class
- Implement chunk deletion for Faiss provider with index tracking
- Add chunk_ids list to maintain chunk order in Faiss index
- Integrate chunk deletion into OpenAI vector store file deletion flow
- Add placeholder implementations for SQLite and Milvus providers

Closes: #2477

Signed-off-by: Derek Higgins <derekh@redhat.com>
This commit is contained in:
Derek Higgins 2025-07-09 12:19:50 +01:00
parent cd8715d327
commit 3d4b32db0a
5 changed files with 57 additions and 1 deletions

View file

@ -152,6 +152,11 @@ class OpenAIVectorStoreMixin(ABC):
"""Load existing OpenAI vector stores into the in-memory cache."""
self.openai_vector_stores = await self._load_openai_vector_stores()
@abstractmethod
async def _delete_openai_chunk_from_vector_store(self, store_id: str, chunk_id: str) -> None:
"""Delete a chunk from a vector store."""
pass
@abstractmethod
async def register_vector_db(self, vector_db: VectorDB) -> None:
"""Register a vector database (provider-specific implementation)."""
@ -763,6 +768,12 @@ class OpenAIVectorStoreMixin(ABC):
if vector_store_id not in self.openai_vector_stores:
raise ValueError(f"Vector store {vector_store_id} not found")
dict_chunks = await self._load_openai_vector_store_file_contents(vector_store_id, file_id)
chunks = [Chunk.model_validate(c) for c in dict_chunks]
for c in chunks:
if c.chunk_id:
await self._delete_openai_chunk_from_vector_store(vector_store_id, str(c.chunk_id))
store_info = self.openai_vector_stores[vector_store_id].copy()
file = await self.openai_retrieve_vector_store_file(vector_store_id, file_id)

View file

@ -231,6 +231,10 @@ class EmbeddingIndex(ABC):
async def add_chunks(self, chunks: list[Chunk], embeddings: NDArray):
raise NotImplementedError()
@abstractmethod
async def delete_chunk(self, chunk_id: str):
raise NotImplementedError()
@abstractmethod
async def query_vector(self, embedding: NDArray, k: int, score_threshold: float) -> QueryChunksResponse:
raise NotImplementedError()