Skip to content

Commit

Permalink
Modify highlevel delete to not return any value (#1777)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
czs007 authored Nov 10, 2023
1 parent b658468 commit 3e494ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/hello_milvus_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
17 changes: 15 additions & 2 deletions pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 3e494ce

Please sign in to comment.