|
1 | 1 | import random |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
| 5 | +from qdrant_client import QdrantClient |
3 | 6 | from qdrant_client.client_base import QdrantBase |
4 | 7 | from qdrant_client.http.models import models |
5 | 8 | from tests.congruence_tests.test_common import ( |
@@ -100,3 +103,70 @@ def test_sparse_mixed_ids() -> None: |
100 | 103 | init_client(remote_client, fixture_points, sparse_vectors_config=sparse_vectors_config) |
101 | 104 |
|
102 | 105 | compare_client_results(local_client, remote_client, scroller.scroll_all) |
| 106 | + |
| 107 | + |
| 108 | +def _init_value_type_collection(client: QdrantBase) -> None: |
| 109 | + if client.collection_exists(COLLECTION_NAME): |
| 110 | + client.delete_collection(COLLECTION_NAME) |
| 111 | + client.create_collection( |
| 112 | + collection_name=COLLECTION_NAME, |
| 113 | + vectors_config=models.VectorParams(size=2, distance=models.Distance.COSINE), |
| 114 | + ) |
| 115 | + client.upsert( |
| 116 | + collection_name=COLLECTION_NAME, |
| 117 | + points=[ |
| 118 | + models.PointStruct(id=1, vector=[0.1, 0.2], payload={"n": 1}), |
| 119 | + models.PointStruct(id=2, vector=[0.1, 0.2], payload={"n": True}), |
| 120 | + models.PointStruct(id=3, vector=[0.1, 0.2], payload={"n": 0}), |
| 121 | + models.PointStruct(id=4, vector=[0.1, 0.2], payload={"n": False}), |
| 122 | + models.PointStruct(id=5, vector=[0.1, 0.2], payload={"n": 1.0}), |
| 123 | + models.PointStruct(id=6, vector=[0.1, 0.2], payload={"n": 0.0}), |
| 124 | + ], |
| 125 | + wait=True, |
| 126 | + ) |
| 127 | + |
| 128 | + |
| 129 | +def _scroll_value_type(client: QdrantBase, scroll_filter: models.Filter) -> list[models.Record]: |
| 130 | + records, _next_page = client.scroll( |
| 131 | + collection_name=COLLECTION_NAME, |
| 132 | + scroll_filter=scroll_filter, |
| 133 | + limit=10, |
| 134 | + with_payload=True, |
| 135 | + ) |
| 136 | + return records |
| 137 | + |
| 138 | + |
| 139 | +@pytest.mark.parametrize("prefer_grpc", [True, False]) |
| 140 | +def test_bool_int_float_filters_do_not_cross_match(prefer_grpc) -> None: |
| 141 | + """Python cross-matches bool / int / float (bool is a subclass of int, and |
| 142 | + 1 == 1.0), but Qdrant keeps them as distinct payload value types for exact |
| 143 | + match. Local mode must not cross-match them, matching the remote server |
| 144 | + behaviour. Match condition operands can only be bool / int / str (never float), |
| 145 | + so a float payload value is never matched by an exact-match condition. |
| 146 | + """ |
| 147 | + local_client: QdrantClient = init_local() |
| 148 | + _init_value_type_collection(local_client) |
| 149 | + |
| 150 | + remote_client: QdrantClient = init_remote(prefer_grpc=prefer_grpc) |
| 151 | + _init_value_type_collection(remote_client) |
| 152 | + |
| 153 | + filters = [ |
| 154 | + models.Filter(must=[models.FieldCondition(key="n", match=models.MatchValue(value=1))]), |
| 155 | + models.Filter(must=[models.FieldCondition(key="n", match=models.MatchValue(value=True))]), |
| 156 | + models.Filter(must=[models.FieldCondition(key="n", match=models.MatchValue(value=0))]), |
| 157 | + models.Filter(must=[models.FieldCondition(key="n", match=models.MatchValue(value=False))]), |
| 158 | + models.Filter(must=[models.FieldCondition(key="n", match=models.MatchAny(any=[1, 0]))]), |
| 159 | + models.Filter( |
| 160 | + must=[models.FieldCondition(key="n", match=models.MatchExcept(**{"except": [1, 0]}))] |
| 161 | + ), |
| 162 | + models.Filter(must=[models.FieldCondition(key="n", range=models.Range(gte=1, lte=1))]), |
| 163 | + models.Filter(must=[models.FieldCondition(key="n", range=models.Range(gte=0, lte=1))]), |
| 164 | + ] |
| 165 | + |
| 166 | + for scroll_filter in filters: |
| 167 | + compare_client_results( |
| 168 | + local_client, |
| 169 | + remote_client, |
| 170 | + _scroll_value_type, |
| 171 | + scroll_filter=scroll_filter, |
| 172 | + ) |
0 commit comments