Skip to content

Commit 5046d36

Browse files
author
Filip Haltmayer
committed
SimpleAPI
Signed-off-by: Filip Haltmayer <filip.haltmayer@zilliz.com>
1 parent 1bb9bd5 commit 5046d36

File tree

7 files changed

+1101
-5
lines changed

7 files changed

+1101
-5
lines changed

Diff for: pymilvus/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from .orm.role import Role
7575

7676
from .milvus_client.milvus_client import MilvusClient
77+
from .simple_api.simple_api import SimpleAPI
7778

7879
__all__ = [
7980
'Collection', 'Index', 'Partition',
@@ -95,5 +96,6 @@
9596
'MilvusException',
9697
'__version__',
9798

98-
'MilvusClient'
99+
'MilvusClient',
100+
'SimpleAPI',
99101
]

Diff for: pymilvus/client/grpc_handler.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,10 @@ def batch_insert(self, collection_name, entities, partition_name=None, timeout=N
481481
raise err
482482

483483
@retry_on_rpc_failure()
484-
def delete(self, collection_name, expression, partition_name=None, timeout=None, **kwargs):
484+
def delete(self, collection_name, expr, partition_name=None, timeout=None, **kwargs):
485485
check_pass_param(collection_name=collection_name)
486486
try:
487-
req = Prepare.delete_request(collection_name, partition_name, expression)
487+
req = Prepare.delete_request(collection_name, partition_name, expr)
488488
future = self._stub.Delete.future(req, timeout=timeout)
489489

490490
if kwargs.get("_async", False):
@@ -580,7 +580,7 @@ def _execute_search_requests(self, requests, timeout=None, **kwargs):
580580

581581
@retry_on_rpc_failure(retry_on_deadline=False)
582582
def search(self, collection_name, data, anns_field, param, limit,
583-
expression=None, partition_names=None, output_fields=None,
583+
expr=None, partition_names=None, output_fields=None,
584584
round_decimal=-1, timeout=None, **kwargs):
585585
check_pass_param(
586586
limit=limit,
@@ -594,7 +594,7 @@ def search(self, collection_name, data, anns_field, param, limit,
594594
)
595595

596596
requests = Prepare.search_requests_with_expr(collection_name, data, anns_field, param, limit,
597-
expression, partition_names, output_fields, round_decimal,
597+
expr, partition_names, output_fields, round_decimal,
598598
**kwargs)
599599
return self._execute_search_requests(requests, timeout, round_decimal=round_decimal, **kwargs)
600600

Diff for: pymilvus/simple_api/__init__.py

Whitespace-only changes.

Diff for: pymilvus/simple_api/example.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from pprint import pprint
2+
from pymilvus import (
3+
SimpleAPI,
4+
)
5+
6+
fmt = "\n=== {:30} ===\n"
7+
dim = 3
8+
collection_name = "hello_milvus"
9+
vector_field_name = "vector"
10+
primary_key_name = "id"
11+
api = SimpleAPI()
12+
api.drop_collection(collection_name)
13+
14+
api.create_collection(
15+
collection_name=collection_name,
16+
dimension=dim,
17+
vector_field=vector_field_name,
18+
primary_key_name=primary_key_name,
19+
metric_type="L2",
20+
partition_field={"name": "a", "type": "int"},
21+
overwrite=True,
22+
)
23+
24+
print("collections:", api.list_collections())
25+
26+
# print(f"{collection_name} :", api.describe_collection(collection_name))
27+
28+
test_data = [
29+
{"vector": [1, 2, 3], "a": 1, "b": 3},
30+
{"vector": [2, 3, 4], "a": 2, "b": 2.1},
31+
{"vector": [3, 4, 5], "a": 3, "c": -1},
32+
{"vector": [4, 5, 6], "a": 4, "d": {"m": 3}},
33+
{"vector": [7, 8, 9], "a": 5, "f": [3, 2, 1]},
34+
{"vector": [8, 9, 10], "a": 6, "g": "laq"},
35+
{"vector": [7, 10, 11], "a": 7, "z": -1},
36+
]
37+
38+
print(fmt.format("Start inserting entities"))
39+
pks = api.insert(collection_name, test_data, progress_bar=True)
40+
print(fmt.format("Start searching based on vector similarity"))
41+
42+
print("len of pks:", len(pks), "first pk is :", pks[0])
43+
44+
print(f"get rows with `a` values that are 3 or 4 from {collection_name}")
45+
46+
values = api.fetch(collection_name, field_name="a", values=[3, 4], include_vectors=True)
47+
48+
print("values are:")
49+
pprint(values)
50+
print()
51+
52+
print(
53+
f"get rows where `b` < 3 from partiton `a` in [1,2,3] from {collection_name} but only the vector."
54+
)
55+
56+
values = api.query(
57+
collection_name,
58+
filter_expression="b < 3",
59+
partition_keys=[1, 2, 3],
60+
output_fields=["vector"],
61+
)
62+
63+
print("values are:")
64+
pprint(values)
65+
print()
66+
67+
print(f"search for [3,3,3] in {collection_name} and include the vector result.")
68+
69+
values = api.search(
70+
collection_name=collection_name, data=[3, 3, 3], include_vectors=True, top_k=1
71+
)
72+
73+
print("values are:")
74+
pprint(values)
75+
print()
76+
77+
print(f"Delete vectors where b = 3 in partitions a in [1, 2, 3] from {collection_name}")
78+
79+
api.delete(
80+
collection_name=collection_name,
81+
field_name="a",
82+
values=[3],
83+
partition_keys=[1, 2, 3],
84+
)

0 commit comments

Comments
 (0)