Skip to main content
Version: User Guides (BYOC)

Delete Entities

You can delete the entities that are no longer needed by filtering conditions or their primary keys.

Delete Entities by Filtering Conditions

When deleting multiple entities that share some attributes in a batch, you can use filter expressions. The example code below uses the in operator to bulk delete all Entities with thier color field set to the values of red and green. You can also use other operators to construct filter expressions that meet your requirements. For more information about filter expressions, please refer to Filtering.

from pymilvus import MilvusClient

client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)

res = client.delete(
collection_name="quick_setup",
filter="color in ['red_3314', 'purple_7392']"
)

print(res)

# Output
# {'delete_count': 2}

Delete Entities by Primary Keys

In most cases, a primary key uniquely identifies an Entity. You can delete Entities by setting their primary keys in the delete request. The example code below demonstrates how to delete two entities with primary keys 18 and 19.

res = client.delete(
collection_name="quick_setup",
ids=[18, 19]
)

print(res)

# Output
# {'delete_count': 2}

Delete Entities from Partitions

You can also delete entities stored in specific partitions. The following code snippets assume that you have a partition named PartitionA in your collection.

res = client.delete(
collection_name="quick_setup",
ids=[18, 19],
partition_name="partitionA"
)

print(res)

# Output
# {'delete_count': 2}