mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-29 15:23:51 +00:00
Renamed FaissVectorIOAdapter delete_chunk to delete_chunks
It now handles a list of chunk_id's Signed-off-by: Derek Higgins <derekh@redhat.com>
This commit is contained in:
parent
4e9bb9a47e
commit
9b6864b0ed
8 changed files with 20 additions and 18 deletions
|
@ -289,7 +289,8 @@ class FaissVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtocolPr
|
||||||
|
|
||||||
return await index.query_chunks(query, params)
|
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"""
|
"""Delete a chunk from a faiss index"""
|
||||||
faiss_index = self.cache[store_id].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)
|
||||||
|
|
|
@ -550,11 +550,12 @@ class SQLiteVecVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtoc
|
||||||
raise ValueError(f"Vector DB {vector_db_id} not found")
|
raise ValueError(f"Vector DB {vector_db_id} not found")
|
||||||
return await index.query_chunks(query, params)
|
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."""
|
"""Delete a chunk from a sqlite_vec index."""
|
||||||
index = await self._get_and_cache_vector_db_index(store_id)
|
index = await self._get_and_cache_vector_db_index(store_id)
|
||||||
if not index:
|
if not index:
|
||||||
raise ValueError(f"Vector DB {store_id} not found")
|
raise ValueError(f"Vector DB {store_id} not found")
|
||||||
|
|
||||||
# Use the index's delete_chunk method
|
for chunk_id in chunk_ids:
|
||||||
await index.index.delete_chunk(chunk_id)
|
# Use the index's delete_chunk method
|
||||||
|
await index.index.delete_chunk(chunk_id)
|
||||||
|
|
|
@ -212,5 +212,5 @@ class ChromaVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtocolP
|
||||||
self.cache[vector_db_id] = index
|
self.cache[vector_db_id] = index
|
||||||
return 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")
|
raise NotImplementedError("OpenAI Vector Stores API is not supported in Chroma")
|
||||||
|
|
|
@ -380,11 +380,12 @@ class MilvusVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtocolP
|
||||||
|
|
||||||
return await index.query_chunks(query, params)
|
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."""
|
"""Delete a chunk from a milvus vector store."""
|
||||||
index = await self._get_and_cache_vector_db_index(store_id)
|
index = await self._get_and_cache_vector_db_index(store_id)
|
||||||
if not index:
|
if not index:
|
||||||
raise ValueError(f"Vector DB {store_id} not found")
|
raise ValueError(f"Vector DB {store_id} not found")
|
||||||
|
|
||||||
# Use the index's delete_chunk method
|
for chunk_id in chunk_ids:
|
||||||
await index.index.delete_chunk(chunk_id)
|
# Use the index's delete_chunk method
|
||||||
|
await index.index.delete_chunk(chunk_id)
|
||||||
|
|
|
@ -271,11 +271,12 @@ class PGVectorVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorDBsProtoco
|
||||||
self.cache[vector_db_id] = VectorDBWithIndex(vector_db, index, self.inference_api)
|
self.cache[vector_db_id] = VectorDBWithIndex(vector_db, index, self.inference_api)
|
||||||
return self.cache[vector_db_id]
|
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."""
|
"""Delete a chunk from a PostgreSQL vector store."""
|
||||||
index = await self._get_and_cache_vector_db_index(store_id)
|
index = await self._get_and_cache_vector_db_index(store_id)
|
||||||
if not index:
|
if not index:
|
||||||
raise ValueError(f"Vector DB {store_id} not found")
|
raise ValueError(f"Vector DB {store_id} not found")
|
||||||
|
|
||||||
# Use the index's delete_chunk method
|
for chunk_id in chunk_ids:
|
||||||
await index.index.delete_chunk(chunk_id)
|
# Use the index's delete_chunk method
|
||||||
|
await index.index.delete_chunk(chunk_id)
|
||||||
|
|
|
@ -311,5 +311,5 @@ class QdrantVectorIOAdapter(VectorIO, VectorDBsProtocolPrivate):
|
||||||
) -> VectorStoreFileObject:
|
) -> VectorStoreFileObject:
|
||||||
raise NotImplementedError("OpenAI Vector Stores API is not supported in Qdrant")
|
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")
|
raise NotImplementedError("OpenAI Vector Stores API is not supported in Qdrant")
|
||||||
|
|
|
@ -268,5 +268,5 @@ class WeaviateVectorIOAdapter(
|
||||||
async def _delete_openai_vector_store_file_from_storage(self, store_id: str, file_id: str) -> None:
|
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")
|
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")
|
raise NotImplementedError("OpenAI Vector Stores API is not supported in Weaviate")
|
||||||
|
|
|
@ -153,7 +153,7 @@ class OpenAIVectorStoreMixin(ABC):
|
||||||
self.openai_vector_stores = await self._load_openai_vector_stores()
|
self.openai_vector_stores = await self._load_openai_vector_stores()
|
||||||
|
|
||||||
@abstractmethod
|
@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."""
|
"""Delete a chunk from a vector store."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -770,9 +770,7 @@ class OpenAIVectorStoreMixin(ABC):
|
||||||
|
|
||||||
dict_chunks = await self._load_openai_vector_store_file_contents(vector_store_id, file_id)
|
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]
|
chunks = [Chunk.model_validate(c) for c in dict_chunks]
|
||||||
for c in chunks:
|
await self.delete_chunks(vector_store_id, [str(c.chunk_id) for c in chunks if c.chunk_id])
|
||||||
if c.chunk_id:
|
|
||||||
await self.delete_chunk(vector_store_id, str(c.chunk_id))
|
|
||||||
|
|
||||||
store_info = self.openai_vector_stores[vector_store_id].copy()
|
store_info = self.openai_vector_stores[vector_store_id].copy()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue