-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: junjie.jiang <[email protected]>
- Loading branch information
1 parent
b771a87
commit cd4dc53
Showing
4 changed files
with
73 additions
and
0 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
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
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 |
---|---|---|
|
@@ -38,3 +38,4 @@ black | |
requests | ||
minio | ||
azure-storage-blob | ||
milvus>=2.4.0,<2.5.0 |
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,56 @@ | ||
import os | ||
from tempfile import TemporaryDirectory | ||
import numpy as np | ||
|
||
from pymilvus.milvus_client import MilvusClient | ||
|
||
|
||
class TestMilvusLite: | ||
|
||
def test_milvus_lite(self): | ||
with TemporaryDirectory(dir='./') as root: | ||
db_file = os.path.join(root, 'test.db') | ||
client = MilvusClient(db_file) | ||
client.create_collection( | ||
collection_name="demo_collection", | ||
dimension=3 | ||
) | ||
|
||
# Text strings to search from. | ||
docs = [ | ||
"Artificial intelligence was founded as an academic discipline in 1956.", | ||
"Alan Turing was the first person to conduct substantial research in AI.", | ||
"Born in Maida Vale, London, Turing was raised in southern England.", | ||
] | ||
|
||
vectors = [[np.random.uniform(-1, 1) for _ in range(3) ] for _ in range(len(docs))] | ||
data = [{"id": i, "vector": vectors[i], "text": docs[i], "subject": "history"} for i in range(len(vectors))] | ||
res = client.insert( | ||
collection_name="demo_collection", | ||
data=data | ||
) | ||
assert res["insert_count"] == 3 | ||
|
||
res = client.search( | ||
collection_name="demo_collection", | ||
data=[vectors[0]], | ||
filter="subject == 'history'", | ||
limit=2, | ||
output_fields=["text", "subject"], | ||
) | ||
assert len(res[0]) == 2 | ||
|
||
# a query that retrieves all entities matching filter expressions. | ||
res = client.query( | ||
collection_name="demo_collection", | ||
filter="subject == 'history'", | ||
output_fields=["text", "subject"], | ||
) | ||
assert len(res) == 3 | ||
|
||
# delete | ||
res = client.delete( | ||
collection_name="demo_collection", | ||
filter="subject == 'history'", | ||
) | ||
assert len(res) == 3 |