Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pinecone import Pinecone, PineconeAsyncio, PodSpec, ServerlessSpec
from pinecone.db_data import _Index, _IndexAsyncio
from pinecone.exceptions import NotFoundException

from .filters import _normalize_filters, _validate_filters

Expand Down Expand Up @@ -352,6 +353,30 @@ 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"
try:
self._index.delete(delete_all=True, namespace=self.namespace)
except NotFoundException:
# Namespace doesn't exist (empty collection), which is fine - nothing to delete
logger.debug("Namespace '{namespace}' not found. Nothing to delete.", namespace=self.namespace or "default")

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"
try:
await self._async_index.delete(delete_all=True, namespace=self.namespace)
except NotFoundException:
# Namespace doesn't exist (empty collection), which is fine - nothing to delete
logger.debug("Namespace '{namespace}' not found. Nothing to delete.", namespace=self.namespace or "default")

def _embedding_retrieval(
self,
query_embedding: List[float],
Expand Down
13 changes: 13 additions & 0 deletions integrations/pinecone/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions integrations/pinecone/tests/test_document_store_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down