Skip to content

Commit

Permalink
fix: compare scroll results
Browse files Browse the repository at this point in the history
  • Loading branch information
joein committed Jul 22, 2023
1 parent 45e2323 commit 66f8510
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion qdrant_client/qdrant_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import warnings
from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Tuple, Union

from qdrant_client import grpc as grpc
Expand Down
18 changes: 14 additions & 4 deletions tests/congruence_tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from qdrant_client import QdrantClient
from qdrant_client.client_base import QdrantBase
from qdrant_client.conversions import common_types as types
from qdrant_client.http import models
from qdrant_client.http.models import VectorStruct
from qdrant_client.local.qdrant_local import QdrantLocal
Expand Down Expand Up @@ -84,7 +85,7 @@ def compare_collections(
compare_client_results(
client_1,
client_2,
lambda client: client.scroll(COLLECTION_NAME, with_vectors=True, limit=num_vectors * 2)[0],
lambda client: client.scroll(COLLECTION_NAME, with_vectors=True, limit=num_vectors * 2),
)


Expand All @@ -96,11 +97,13 @@ def compare_vectors(vec1: Optional[VectorStruct], vec2: Optional[VectorStruct],

if isinstance(vec1, dict):
for key, value in vec1.items():
assert np.allclose(vec1[key], vec2[key], atol=1.e-3), (
assert np.allclose(vec1[key], vec2[key], atol=1.0e-3), (
f"res1[{i}].vectors[{key}] = {value}, " f"res2[{i}].vectors[{key}] = {vec2[key]}"
)
else:
assert np.allclose(vec1, vec2, atol=1.e-3), f"res1[{i}].vectors = {vec1}, res2[{i}].vectors = {vec2}"
assert np.allclose(
vec1, vec2, atol=1.0e-3
), f"res1[{i}].vectors = {vec1}, res2[{i}].vectors = {vec2}"


def compare_scored_record(
Expand Down Expand Up @@ -149,7 +152,14 @@ def compare_client_results(
res1 = foo(client1, **kwargs)
res2 = foo(client2, **kwargs)

if isinstance(res1, (list, tuple)):
# compare scroll results
if isinstance(res1, tuple) and len(res1) == 2:
if isinstance(res1[0], list) and (res1[1] is None or isinstance(res1[1], types.PointId)):
res1, offset1 = res1
res2, offset2 = res2
assert offset1 == offset2, f"offset1 = {offset1}, offset2 = {offset2}"

if isinstance(res1, list):
compare_records(res1, res2)
elif isinstance(res1, models.GroupsResult):
groups_1 = sorted(res1.groups, key=lambda x: (x.hits[0].score, x.id))
Expand Down

0 comments on commit 66f8510

Please sign in to comment.