diff --git a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py index 2f7bfab649..b24d6ef6de 100644 --- a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py +++ b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py @@ -352,6 +352,22 @@ async def delete_documents_async(self, document_ids: List[str]) -> None: assert self._async_index is not None, "Index is not initialized" await self._async_index.delete(ids=document_ids, namespace=self.namespace) + def delete_all_documents(self) -> None: + """ + Deletes all documents in the document store. + """ + self._initialize_index() + assert self._index is not None, "Index is not initialized" + self._index.delete(delete_all=True, namespace=self.namespace) + + async def delete_all_documents_async(self) -> None: + """ + Asynchronously deletes all documents in the document store. + """ + await self._initialize_async_index() + assert self._async_index is not None, "Index is not initialized" + await self._async_index.delete(delete_all=True, namespace=self.namespace) + def _embedding_retrieval( self, query_embedding: List[float], diff --git a/integrations/pinecone/tests/test_document_store.py b/integrations/pinecone/tests/test_document_store.py index 21ebc8136c..152ac436d4 100644 --- a/integrations/pinecone/tests/test_document_store.py +++ b/integrations/pinecone/tests/test_document_store.py @@ -272,6 +272,19 @@ def test_write_documents_duplicate_skip(self, document_store: PineconeDocumentSt @pytest.mark.skip(reason="Pinecone creates a namespace only when the first document is written") def test_delete_documents_empty_document_store(self, document_store: PineconeDocumentStore): ... + def test_delete_all_documents(self, document_store: PineconeDocumentStore): + docs = [Document(content="first doc"), Document(content="second doc")] + document_store.write_documents(docs) + assert document_store.count_documents() == 2 + + document_store.delete_all_documents() + assert document_store.count_documents() == 0 + + def test_delete_all_documents_empty_collection(self, document_store: PineconeDocumentStore): + assert document_store.count_documents() == 0 + document_store.delete_all_documents() + assert document_store.count_documents() == 0 + def test_embedding_retrieval(self, document_store: PineconeDocumentStore): query_embedding = [0.1] * 768 most_similar_embedding = [0.8] * 768 diff --git a/integrations/pinecone/tests/test_document_store_async.py b/integrations/pinecone/tests/test_document_store_async.py index 83c1959f19..60f1abed54 100644 --- a/integrations/pinecone/tests/test_document_store_async.py +++ b/integrations/pinecone/tests/test_document_store_async.py @@ -66,6 +66,19 @@ async def test_delete_documents(self, document_store_async: PineconeDocumentStor await document_store_async.delete_documents_async([doc.id]) assert await document_store_async.count_documents_async() == 0 + async def test_delete_all_documents_async(self, document_store_async: PineconeDocumentStore): + docs = [Document(content="first doc"), Document(content="second doc")] + await document_store_async.write_documents_async(docs) + assert await document_store_async.count_documents_async() == 2 + + await document_store_async.delete_all_documents_async() + assert await document_store_async.count_documents_async() == 0 + + async def test_delete_all_documents_async_empty_collection(self, document_store_async: PineconeDocumentStore): + assert await document_store_async.count_documents_async() == 0 + await document_store_async.delete_all_documents_async() + assert await document_store_async.count_documents_async() == 0 + async def test_embedding_retrieval(self, document_store_async: PineconeDocumentStore): query_embedding = [0.1] * 768 most_similar_embedding = [0.8] * 768