From 530a26ac84c6d9a4f8674677eceb32417df936fa Mon Sep 17 00:00:00 2001 From: "zhenshan.cao" Date: Fri, 10 Nov 2023 11:17:50 +0800 Subject: [PATCH] Modify highlevel delete to not return any value Starting from version 2.3.2, Milvus no longer includes the primary keys in the result when processing the delete operation with expressions. This change is due to the large amount of data involved. The delete interface no longer returns any results. If no exceptions are thrown, it indicates a successful deletion. However, for backward compatibility, if the primary_keys returned from Milvus is not empty the list of primary keys is still returned. Signed-off-by: zhenshan.cao --- examples/hello_milvus_simple.py | 4 ++-- pymilvus/milvus_client/milvus_client.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/hello_milvus_simple.py b/examples/hello_milvus_simple.py index 6c5d1339e..c811c204e 100644 --- a/examples/hello_milvus_simple.py +++ b/examples/hello_milvus_simple.py @@ -36,8 +36,8 @@ print(f"data of primary key {pks[0]} is", first_pk_data) print(f"start to delete first 2 of primary keys in collection {collection_name}") -delete_pks = milvus_client.delete(collection_name, pks[0:2]) -print("deleted:", delete_pks) +milvus_client.delete(collection_name, pks[0:2]) + rng = np.random.default_rng(seed=19530) vectors_to_search = rng.random((1, dim)) diff --git a/pymilvus/milvus_client/milvus_client.py b/pymilvus/milvus_client/milvus_client.py index 8ba423132..a6aca5c97 100644 --- a/pymilvus/milvus_client/milvus_client.py +++ b/pymilvus/milvus_client/milvus_client.py @@ -379,6 +379,15 @@ def delete( Delete all the entries based on the pk. If unsure of pk you can first query the collection to grab the corresponding data. Then you can delete using the pk_field. + + Starting from version 2.3.2, Milvus no longer includes the primary keys in the result + when processing the delete operation on expressions. + This change is due to the large amount of data involved. + The delete interface no longer returns any results. + If no exceptions are thrown, it indicates a successful deletion. + However, for backward compatibility, If the primary_keys returned from Milvus is not empty + the list of primary keys is still returned. + Args: pks (list, str, int): The pk's to delete. Depending on pk_field type it can be int or str or alist of either. @@ -403,11 +412,15 @@ def delete( ret_pks = [] try: res = conn.delete(collection_name, expr, timeout=timeout, **kwargs) - ret_pks.extend(res.primary_keys) + if res.primary_keys: + ret_pks.extend(res.primary_keys) except Exception as ex: logger.error("Failed to delete primary keys in collection: %s", collection_name) raise ex from ex - return ret_pks + + if ret_pks: + return ret_pks + return None def num_entities(self, collection_name: str, timeout: Optional[float] = None) -> int: """return the number of rows in the collection.