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

[WIP] Simple API #1523

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 3 additions & 1 deletion pymilvus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from .orm.role import Role

from .milvus_client.milvus_client import MilvusClient
from .simple_api.simple_api import SimpleAPI

__all__ = [
'Collection', 'Index', 'Partition',
Expand All @@ -95,5 +96,6 @@
'MilvusException',
'__version__',

'MilvusClient'
'MilvusClient',
'SimpleAPI',
]
8 changes: 4 additions & 4 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,10 @@ def batch_insert(self, collection_name, entities, partition_name=None, timeout=N
raise err

@retry_on_rpc_failure()
def delete(self, collection_name, expression, partition_name=None, timeout=None, **kwargs):
def delete(self, collection_name, expr, partition_name=None, timeout=None, **kwargs):
check_pass_param(collection_name=collection_name)
try:
req = Prepare.delete_request(collection_name, partition_name, expression)
req = Prepare.delete_request(collection_name, partition_name, expr)
future = self._stub.Delete.future(req, timeout=timeout)

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

@retry_on_rpc_failure(retry_on_deadline=False)
def search(self, collection_name, data, anns_field, param, limit,
expression=None, partition_names=None, output_fields=None,
expr=None, partition_names=None, output_fields=None,
round_decimal=-1, timeout=None, **kwargs):
check_pass_param(
limit=limit,
Expand All @@ -594,7 +594,7 @@ def search(self, collection_name, data, anns_field, param, limit,
)

requests = Prepare.search_requests_with_expr(collection_name, data, anns_field, param, limit,
expression, partition_names, output_fields, round_decimal,
expr, partition_names, output_fields, round_decimal,
**kwargs)
return self._execute_search_requests(requests, timeout, round_decimal=round_decimal, **kwargs)

Expand Down
Empty file added pymilvus/simple_api/__init__.py
Empty file.
84 changes: 84 additions & 0 deletions pymilvus/simple_api/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from pprint import pprint
from pymilvus import (
SimpleAPI,
)

fmt = "\n=== {:30} ===\n"
dim = 3
collection_name = "hello_milvus"
vector_field_name = "vector"
primary_key_name = "id"
api = SimpleAPI()
api.drop_collection(collection_name)

api.create_collection(
collection_name=collection_name,
dimension=dim,
vector_field=vector_field_name,
primary_key_name=primary_key_name,
metric_type="L2",
partition_field={"name": "a", "type": "int"},
overwrite=True,
)

print("collections:", api.list_collections())

# print(f"{collection_name} :", api.describe_collection(collection_name))

test_data = [
{"vector": [1, 2, 3], "a": 1, "b": 3},
{"vector": [2, 3, 4], "a": 2, "b": 2.1},
{"vector": [3, 4, 5], "a": 3, "c": -1},
{"vector": [4, 5, 6], "a": 4, "d": {"m": 3}},
{"vector": [7, 8, 9], "a": 5, "f": [3, 2, 1]},
{"vector": [8, 9, 10], "a": 6, "g": "laq"},
{"vector": [7, 10, 11], "a": 7, "z": -1},
]

print(fmt.format("Start inserting entities"))
pks = api.insert(collection_name, test_data, progress_bar=True)
print(fmt.format("Start searching based on vector similarity"))

print("len of pks:", len(pks), "first pk is :", pks[0])

print(f"get rows with `a` values that are 3 or 4 from {collection_name}")

values = api.fetch(collection_name, field_name="a", values=[3, 4], include_vectors=True)

print("values are:")
pprint(values)
print()

print(
f"get rows where `b` < 3 from partiton `a` in [1,2,3] from {collection_name} but only the vector."
)

values = api.query(
collection_name,
filter_expression="b < 3",
partition_keys=[1, 2, 3],
output_fields=["vector"],
)

print("values are:")
pprint(values)
print()

print(f"search for [3,3,3] in {collection_name} and include the vector result.")

values = api.search(
collection_name=collection_name, data=[3, 3, 3], include_vectors=True, top_k=1
)

print("values are:")
pprint(values)
print()

print(f"Delete vectors where b = 3 in partitions a in [1, 2, 3] from {collection_name}")

api.delete(
collection_name=collection_name,
field_name="a",
values=[3],
partition_keys=[1, 2, 3],
)
Loading