diff --git a/llama_stack/providers/inline/vector_io/faiss/faiss.py b/llama_stack/providers/inline/vector_io/faiss/faiss.py index d119b6d2a..edee4649d 100644 --- a/llama_stack/providers/inline/vector_io/faiss/faiss.py +++ b/llama_stack/providers/inline/vector_io/faiss/faiss.py @@ -289,7 +289,8 @@ class FaissVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtocolPr return await index.query_chunks(query, params) - async def delete_chunk(self, store_id: str, chunk_id: str) -> None: + async def delete_chunks(self, store_id: str, chunk_ids: list[str]) -> None: """Delete a chunk from a faiss index""" faiss_index = self.cache[store_id].index - await faiss_index.delete_chunk(chunk_id) + for chunk_id in chunk_ids: + await faiss_index.delete_chunk(chunk_id) 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 1c4165e46..cfa4e2263 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 @@ -550,11 +550,12 @@ class SQLiteVecVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtoc raise ValueError(f"Vector DB {vector_db_id} not found") return await index.query_chunks(query, params) - async def delete_chunk(self, store_id: str, chunk_id: str) -> None: + async def delete_chunks(self, store_id: str, chunk_ids: list[str]) -> None: """Delete a chunk from a sqlite_vec index.""" 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) + for chunk_id in chunk_ids: + # Use the index's delete_chunk method + await index.index.delete_chunk(chunk_id) diff --git a/llama_stack/providers/remote/vector_io/chroma/chroma.py b/llama_stack/providers/remote/vector_io/chroma/chroma.py index 5b3063823..1aec8e9f9 100644 --- a/llama_stack/providers/remote/vector_io/chroma/chroma.py +++ b/llama_stack/providers/remote/vector_io/chroma/chroma.py @@ -212,5 +212,5 @@ class ChromaVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtocolP self.cache[vector_db_id] = index return index - async def delete_chunk(self, store_id: str, chunk_id: str) -> None: + async def delete_chunks(self, store_id: str, chunk_ids: list[str]) -> None: raise NotImplementedError("OpenAI Vector Stores API is not supported in Chroma") diff --git a/llama_stack/providers/remote/vector_io/milvus/milvus.py b/llama_stack/providers/remote/vector_io/milvus/milvus.py index 67839a67c..f1652a80e 100644 --- a/llama_stack/providers/remote/vector_io/milvus/milvus.py +++ b/llama_stack/providers/remote/vector_io/milvus/milvus.py @@ -380,11 +380,12 @@ class MilvusVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtocolP return await index.query_chunks(query, params) - async def delete_chunk(self, store_id: str, chunk_id: str) -> None: + async def delete_chunks(self, store_id: str, chunk_ids: list[str]) -> None: """Delete a chunk from a milvus vector store.""" 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) + for chunk_id in chunk_ids: + # Use the index's delete_chunk method + await index.index.delete_chunk(chunk_id) diff --git a/llama_stack/providers/remote/vector_io/pgvector/pgvector.py b/llama_stack/providers/remote/vector_io/pgvector/pgvector.py index b83e1d916..643c27328 100644 --- a/llama_stack/providers/remote/vector_io/pgvector/pgvector.py +++ b/llama_stack/providers/remote/vector_io/pgvector/pgvector.py @@ -271,11 +271,12 @@ class PGVectorVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtoco self.cache[vector_db_id] = VectorDBWithIndex(vector_db, index, self.inference_api) return self.cache[vector_db_id] - async def delete_chunk(self, store_id: str, chunk_id: str) -> None: + async def delete_chunks(self, store_id: str, chunk_ids: list[str]) -> None: """Delete a chunk from a PostgreSQL vector store.""" 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) + for chunk_id in chunk_ids: + # Use the index's delete_chunk method + await index.index.delete_chunk(chunk_id) diff --git a/llama_stack/providers/remote/vector_io/qdrant/qdrant.py b/llama_stack/providers/remote/vector_io/qdrant/qdrant.py index 9dad37da1..3df3da27f 100644 --- a/llama_stack/providers/remote/vector_io/qdrant/qdrant.py +++ b/llama_stack/providers/remote/vector_io/qdrant/qdrant.py @@ -311,5 +311,5 @@ class QdrantVectorIOAdapter(VectorIO, VectorDBsProtocolPrivate): ) -> VectorStoreFileObject: raise NotImplementedError("OpenAI Vector Stores API is not supported in Qdrant") - async def delete_chunk(self, store_id: str, chunk_id: str) -> None: + async def delete_chunks(self, store_id: str, chunk_ids: list[str]) -> None: raise NotImplementedError("OpenAI Vector Stores API is not supported in Qdrant") diff --git a/llama_stack/providers/remote/vector_io/weaviate/weaviate.py b/llama_stack/providers/remote/vector_io/weaviate/weaviate.py index 2027604c7..543835e20 100644 --- a/llama_stack/providers/remote/vector_io/weaviate/weaviate.py +++ b/llama_stack/providers/remote/vector_io/weaviate/weaviate.py @@ -268,5 +268,5 @@ class WeaviateVectorIOAdapter( async def _delete_openai_vector_store_file_from_storage(self, store_id: str, file_id: str) -> None: raise NotImplementedError("OpenAI Vector Stores API is not supported in Weaviate") - async def delete_chunk(self, store_id: str, chunk_id: str) -> None: + async def delete_chunks(self, store_id: str, chunk_ids: list[str]) -> None: raise NotImplementedError("OpenAI Vector Stores API is not supported in Weaviate") diff --git a/llama_stack/providers/utils/memory/openai_vector_store_mixin.py b/llama_stack/providers/utils/memory/openai_vector_store_mixin.py index 3767821c3..ee69d7c52 100644 --- a/llama_stack/providers/utils/memory/openai_vector_store_mixin.py +++ b/llama_stack/providers/utils/memory/openai_vector_store_mixin.py @@ -153,7 +153,7 @@ class OpenAIVectorStoreMixin(ABC): self.openai_vector_stores = await self._load_openai_vector_stores() @abstractmethod - async def delete_chunk(self, store_id: str, chunk_id: str) -> None: + async def delete_chunks(self, store_id: str, chunk_ids: list[str]) -> None: """Delete a chunk from a vector store.""" pass @@ -770,9 +770,7 @@ class OpenAIVectorStoreMixin(ABC): 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_chunk(vector_store_id, str(c.chunk_id)) + await self.delete_chunks(vector_store_id, [str(c.chunk_id) for c in chunks if c.chunk_id]) store_info = self.openai_vector_stores[vector_store_id].copy()