Skip to content

Commit

Permalink
add test for match condition (#68)
Browse files Browse the repository at this point in the history
* add test for match condition

* add field index creation

* fix json converter for empty list values

* undo debug
  • Loading branch information
generall authored Sep 1, 2022
1 parent 29d18e9 commit f37d65f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 4 additions & 1 deletion qdrant_client/conversions/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def value_to_json(value: Value) -> Any:
return {}
return dict((key, value_to_json(val)) for key, val in value_["structValue"]['fields'].items())
if "listValue" in value_:
return list(value_to_json(val) for val in value_["listValue"]['values'])
if 'values' in value_["listValue"]:
return list(value_to_json(val) for val in value_["listValue"]['values'])
else:
return []
if "nullValue" in value_:
return None
raise ValueError(f"Not supported value: {value_}") # pragma: no cover
Expand Down
25 changes: 23 additions & 2 deletions tests/test_qdrant_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
def one_random_payload_please(idx):
return {
"id": idx + 100,
"id_str": [str(random.randint(1, 30)).zfill(2) for _ in range(random.randint(0, 5))],
"text_data": uuid.uuid4().hex,
"rand_number": random.random(),
"text_array": [uuid.uuid4().hex, uuid.uuid4().hex]
Expand Down Expand Up @@ -95,7 +96,6 @@ def test_record_upload(prefer_grpc):
assert result_count.count > 100



@pytest.mark.parametrize("prefer_grpc", [False, True])
@pytest.mark.parametrize("numpy_upload", [False, True])
def test_qdrant_client_integration(prefer_grpc, numpy_upload):
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_qdrant_client_integration(prefer_grpc, numpy_upload):
collection_name=COLLECTION_NAME,
query_vector=query_vector,
query_filter=None, # Don't use any filters for now, search across all indexed points
append_payload=True, # Also return a stored payload for found points
with_payload=True, # Also return a stored payload for found points
limit=5 # Return 5 closest points
)

Expand All @@ -203,6 +203,25 @@ def test_qdrant_client_integration(prefer_grpc, numpy_upload):
for hit in hits:
print(hit)

client.create_payload_index(COLLECTION_NAME, "id_str", PayloadSchemaType.KEYWORD)
# and use it as a query
hits = client.search(
collection_name=COLLECTION_NAME,
query_vector=query_vector,
query_filter=Filter(
must=[
FieldCondition(
key="id_str",
match=MatchValue(value="11")
)
]
),
with_payload=True,
limit=5
)

assert ('11' in hits[0].payload['id_str'])

client.update_collection(
collection_name=COLLECTION_NAME,
optimizer_config=OptimizersConfigDiff(
Expand Down Expand Up @@ -461,6 +480,8 @@ def test_serialization():
"d": {
"val1": "val2",
"val2": [1, 2, 3],
"val3": [],
"val4": {},
},
"e": True,
"f": None,
Expand Down

0 comments on commit f37d65f

Please sign in to comment.