Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify highlevel delete to not return any value #1777

Merged
merged 1 commit into from
Nov 10, 2023
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
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.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type should be changed to Optional[List[Union[str, int]]]

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
Loading