From 4ca97dd5bec90f52a073bb7f20ba8a23065872dd Mon Sep 17 00:00:00 2001 From: cambiumproject <84091814+cambiumproject@users.noreply.github.com> Date: Mon, 30 Aug 2021 08:22:53 -0500 Subject: [PATCH] Fix behavior of delete_documents() with filters for Milvus (#1354) * Fix behavior of delete_documents() Delete filtered set of vectors rather than the whole collection * Update milvus.py * Update milvus.py --- haystack/document_store/milvus.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/haystack/document_store/milvus.py b/haystack/document_store/milvus.py index 752c96b31..616c9e9da 100644 --- a/haystack/document_store/milvus.py +++ b/haystack/document_store/milvus.py @@ -403,9 +403,13 @@ class MilvusDocumentStore(SQLDocumentStore): if status.code != Status.SUCCESS: raise RuntimeError(f'Milvus has collection check failed: {status}') if ok: - status = self.milvus_server.drop_collection(collection_name=index) - if status.code != Status.SUCCESS: - raise RuntimeError(f'Milvus drop collection failed: {status}') + if filters: + existing_docs = super().get_all_documents(filters=filters, index=index) + self._delete_vector_ids_from_milvus(documents=existing_docs, index=index) + else: + status = self.milvus_server.drop_collection(collection_name=index) + if status.code != Status.SUCCESS: + raise RuntimeError(f'Milvus drop collection failed: {status}') self.milvus_server.flush([index]) self.milvus_server.compact(collection_name=index)