-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f173ee
commit eb3b753
Showing
4 changed files
with
96 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
from pymilvus import Milvus, connections | ||
from vectordb_orm import MilvusSession | ||
from vectordb_orm.tests.models import MyObject | ||
|
||
@pytest.fixture() | ||
def milvus_client(): | ||
return Milvus() | ||
|
||
@pytest.fixture() | ||
def session(milvus_client): | ||
session = MilvusSession(milvus_client) | ||
connections.connect("default", host="localhost", port="19530") | ||
return session | ||
|
||
@pytest.fixture() | ||
def collection(session: MilvusSession, milvus_client: Milvus): | ||
# Wipe the collection | ||
milvus_client.drop_collection(MyObject.collection_name()) | ||
|
||
# Create a new default one | ||
return MyObject._create_collection(milvus_client) |
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,49 @@ | ||
import pytest | ||
from pymilvus import Milvus | ||
from vectordb_orm import MilvusSession | ||
from vectordb_orm.tests.models import MyObject | ||
import numpy as np | ||
from time import sleep | ||
|
||
def test_create_object(collection): | ||
my_object = MyObject(text='example', embedding=np.array([1.0] * 128)) | ||
assert my_object.text == 'example' | ||
assert np.array_equal(my_object.embedding, np.array([1.0] * 128)) | ||
assert my_object.id is None | ||
|
||
|
||
def test_insert_object(collection, milvus_client: Milvus, session: MilvusSession): | ||
my_object = MyObject(text='example', embedding=np.array([1.0] * 128)) | ||
my_object.insert(milvus_client) | ||
assert my_object.id is not None | ||
|
||
collection.flush() | ||
collection.load() | ||
|
||
# Retrieve the object and ensure the values are equivalent | ||
results = session.query(MyObject).filter(MyObject.id == my_object.id).all() | ||
assert len(results) == 1 | ||
|
||
result : MyObject = results[0].result | ||
assert result.text == my_object.text | ||
|
||
|
||
def test_delete_object(collection, milvus_client: Milvus, session: MilvusSession): | ||
my_object = MyObject(text='example', embedding=np.array([1.0] * 128)) | ||
my_object.insert(milvus_client) | ||
|
||
collection.flush() | ||
collection.load() | ||
|
||
results = session.query(MyObject).filter(MyObject.text == "example").all() | ||
assert len(results) == 1 | ||
|
||
my_object.delete(milvus_client) | ||
|
||
# Allow enough time to become consistent | ||
collection.flush() | ||
collection.load() | ||
sleep(1) | ||
|
||
results = session.query(MyObject).filter(MyObject.text == "example").all() | ||
assert len(results) == 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