-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commencing from Milvus 2.3.3, an enhanced functionality has been introduced to facilitate data deletion based on expressive criteria. In this context, the inclusion of the "filter" parameter serves as an entry point for accessing this feature. All rows that conform to the specified filter expression will be eliminated. Moreover, in cases where users specify both a list of primary keys to be deleted and provide a filter expression, the deletion operation will encompass the union of these two conditions, resulting in the removal of rows that satisfy either criterion. Signed-off-by: zhenshan.cao <[email protected]>
- Loading branch information
Showing
2 changed files
with
105 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import time | ||
import numpy as np | ||
from pymilvus import ( | ||
MilvusClient, | ||
) | ||
|
||
fmt = "\n=== {:30} ===\n" | ||
dim = 8 | ||
collection_name = "hello_milvus" | ||
milvus_client = MilvusClient("http://localhost:19530") | ||
milvus_client.drop_collection(collection_name) | ||
milvus_client.create_collection(collection_name, dim, consistency_level="Strong", metric_type="L2") | ||
|
||
print("collections:", milvus_client.list_collections()) | ||
print(f"{collection_name} :", milvus_client.describe_collection(collection_name)) | ||
rng = np.random.default_rng(seed=19530) | ||
|
||
rows = [ | ||
{"id": 1, "vector": rng.random((1, dim))[0], "a": 1}, | ||
{"id": 2, "vector": rng.random((1, dim))[0], "b": 2}, | ||
{"id": 3, "vector": rng.random((1, dim))[0], "c": 3}, | ||
{"id": 4, "vector": rng.random((1, dim))[0], "d": 4}, | ||
{"id": 5, "vector": rng.random((1, dim))[0], "e": 5}, | ||
{"id": 6, "vector": rng.random((1, dim))[0], "f": 6}, | ||
] | ||
|
||
print(fmt.format("Start inserting entities")) | ||
pks = milvus_client.insert(collection_name, rows, progress_bar=True) | ||
pks2 = milvus_client.insert(collection_name, {"id": 7, "vector": rng.random((1, dim))[0], "g": 1}) | ||
pks.extend(pks2) | ||
|
||
|
||
print(f"get primary key {pks[2]} from {collection_name}") | ||
pk_data = milvus_client.get(collection_name, pks[2]) | ||
|
||
if pk_data: | ||
print(f"data of primary key {pks[2]} is", pk_data[0]) | ||
else: | ||
print(f"data of primary key {pks[2]} is empty") | ||
|
||
|
||
print(f"start to delete first 2 of primary keys in collection {collection_name}") | ||
milvus_client.delete(collection_name, pks = pks[0:2]) | ||
|
||
print(f"get primary key {pks[2]} from {collection_name}") | ||
pk_data = milvus_client.get(collection_name, pks[2]) | ||
|
||
if pk_data: | ||
print(f"data of primary key {pks[2]} is", pk_data[0]) | ||
else: | ||
print(f"data of primary key {pks[2]} is empty") | ||
|
||
filter = "e == 5 or f == 6" | ||
print(f"start to delete by expr {filter} in collection {collection_name}") | ||
milvus_client.delete(collection_name, filter=filter) | ||
|
||
print(f"get deleted primary key {pks[4]} from {collection_name}") | ||
pk_data = milvus_client.get(collection_name, pks[4]) | ||
if pk_data: | ||
print(f"data of primary key {pks[4]} is", pk_data[4]) | ||
else: | ||
print(f"data of primary key {pks[4]} is empty") | ||
|
||
print(f"start to delete by expr {filter} or by primary 4 in collection {collection_name}") | ||
milvus_client.delete(collection_name, pks = 4, filter=filter) | ||
|
||
print(f"get deleted primary key {pks[3]} from {collection_name}") | ||
pk_data = milvus_client.get(collection_name, pks[3]) | ||
if pk_data: | ||
print(f"data of primary key {pks[3]} is", pk_data[3]) | ||
else: | ||
print(f"data of primary key {pks[3]} is empty") | ||
|
||
|
||
result = milvus_client.query(collection_name, "", output_fields = ["count(*)"]) | ||
print(result) | ||
print(f"final entities in {collection_name} is {result[0]['count(*)']}") | ||
|
||
milvus_client.drop_collection(collection_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters