From f37d65fc6bea7d54c7c0d76c342d974c0f08a5bb Mon Sep 17 00:00:00 2001 From: Andrey Vasnetsov Date: Thu, 1 Sep 2022 17:32:52 +0200 Subject: [PATCH] add test for match condition (#68) * add test for match condition * add field index creation * fix json converter for empty list values * undo debug --- qdrant_client/conversions/conversion.py | 5 ++++- tests/test_qdrant_client.py | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/qdrant_client/conversions/conversion.py b/qdrant_client/conversions/conversion.py index e2bc99a5..b92c4f77 100644 --- a/qdrant_client/conversions/conversion.py +++ b/qdrant_client/conversions/conversion.py @@ -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 diff --git a/tests/test_qdrant_client.py b/tests/test_qdrant_client.py index 88091666..19651123 100644 --- a/tests/test_qdrant_client.py +++ b/tests/test_qdrant_client.py @@ -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] @@ -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): @@ -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 ) @@ -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( @@ -461,6 +480,8 @@ def test_serialization(): "d": { "val1": "val2", "val2": [1, 2, 3], + "val3": [], + "val4": {}, }, "e": True, "f": None,