Skip to content

Commit

Permalink
deepset-ai#1047 Remove count_documents from delete_documents
Browse files Browse the repository at this point in the history
Removed the expensive check to see if the collection is non-empty by performing a full count.

This is to fix issue deepset-ai#1047
  • Loading branch information
brendancicchi authored Sep 3, 2024
1 parent 129ba54 commit d656523
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,13 @@ def delete_documents(self, document_ids: Optional[List[str]] = None, delete_all:
:raises MissingDocumentError: if no document was deleted but document IDs were provided.
"""
deletion_counter = 0
if self.index.count_documents() > 0:
if document_ids is not None:
for batch in _batches(document_ids, MAX_BATCH_SIZE):
deletion_counter += self.index.delete(ids=batch)
else:
deletion_counter = self.index.delete(delete_all=delete_all)
logger.info(f"{deletion_counter} documents deleted")

if document_ids is not None and deletion_counter == 0:
msg = f"Document {document_ids} does not exist"
raise MissingDocumentError(msg)
if document_ids is not None:
for batch in _batches(document_ids, MAX_BATCH_SIZE):
deletion_counter += self.index.delete(ids=batch)
else:
logger.info("No documents in document store")
deletion_counter = self.index.delete(delete_all=delete_all)
logger.info(f"{deletion_counter} documents deleted")

if document_ids is not None and deletion_counter == 0:
msg = f"Document {document_ids} does not exist"
raise MissingDocumentError(msg)

0 comments on commit d656523

Please sign in to comment.