Files
qdrant-client/tests/test_in_memory.py
George ff7f584d33 new: update models, remove init_from and locks (#1100)
* new: update models, remove init_from and locks

* deprecate: remove init from tests

* deprecate: remove lock tests

* new: convert ascii_folding

* fix: fix type stub

* new: convert acorn

* new: convert shard key with fallback

* new: update grpcio and grpcio tools in generator (#1106)

* new: update grpcio and grpcio tools in generator

* fix: bind grpcio and tools versions to 1.62.0 in generator

* Remove deprecated methods (#1103)

* deprecate: remove old api methods

* deprecate: remove type stub for removed methods

* deprecate: remove old api methods from test_qdrant_client

* deprecate: replace search with query points in test_in_memory

* deprecate: replace search methods in fastembed mixin with query points

* deprecate: replace old api methods in test async qdrant client

* deprecate: replace search with query points in test delete points

* deprecate: replace discover and context with query points in test_discovery

* deprecate: replace recommend_groups with query_points_groups in test_group_recommend

* deprecate: replace search_groups in test_group_search

* deprecate: replace recommend with query points in test_recommendation

* deprecate: replace search with query points in test search

* deprecate: replace context and discover with query points in test sparse discovery

* deprecate: replace search with query points in test sparse idf search

* deprecate: replace recommend with query points in test sparse recommend

* deprecate: replace search with query points in test sparse search

* deprecate: replace missing search request with query request in qdrant_fastembed

* deprecate: replace search with query points in test multivector search queries

* deprecate: replace upload records with upload points in test_updates

* deprecate: remove redundant structs (#1104)

* deprecate: remove redundant structs

* fix: do not use removed conversions in local mode

* fix: remove redundant conversions, simplify types.QueryRequest

* deprecate: replace old style grpc vector conversion to a new one (#1105)

* deprecate: replace old style grpc vector conversion to a new one

* fix: ignore union attr in conversion

* review fixes

---------

Co-authored-by: generall <andrey@vasnetsov.com>

---------

Co-authored-by: generall <andrey@vasnetsov.com>

---------

Co-authored-by: generall <andrey@vasnetsov.com>

* new: deprecate add, query, query_batch in fastembed mixin (#1102)

* new: deprecate add, query, query_batch in fastembed mixin

* 1.16 -> 1.17

---------

Co-authored-by: generall <andrey@vasnetsov.com>

---------

Co-authored-by: generall <andrey@vasnetsov.com>
2025-11-11 21:17:08 +07:00

121 lines
3.8 KiB
Python

import pytest
from qdrant_client import QdrantClient, models
@pytest.fixture
def qdrant() -> QdrantClient:
return QdrantClient(":memory:")
def test_dense_in_memory_key_filter_returns_results(qdrant: QdrantClient):
qdrant.create_collection(
collection_name="test_collection",
vectors_config=models.VectorParams(size=4, distance=models.Distance.DOT),
)
operation_info = qdrant.upsert(
collection_name="test_collection",
wait=True,
points=[
models.PointStruct(id=1, vector=[0.05, 0.61, 0.76, 0.74], payload={"city": "Berlin"}),
models.PointStruct(
id=2,
vector=[0.19, 0.81, 0.75, 0.11],
payload={"city": ["Berlin", "London"]},
),
models.PointStruct(
id=3,
vector=[0.36, 0.55, 0.47, 0.94],
payload={"city": ["Berlin", "Moscow"]},
),
models.PointStruct(
id=4,
vector=[0.18, 0.01, 0.85, 0.80],
payload={"city": ["London", "Moscow"]},
),
models.PointStruct(id=5, vector=[0.24, 0.18, 0.22, 0.44], payload={"count": [0]}),
models.PointStruct(id=6, vector=[0.35, 0.08, 0.11, 0.44]),
],
)
assert operation_info.operation_id == 0
assert operation_info.status == models.UpdateStatus.COMPLETED
search_result = qdrant.query_points(
collection_name="test_collection",
query=[0.2, 0.1, 0.9, 0.7],
query_filter=models.Filter(
must=[models.FieldCondition(key="city", match=models.MatchValue(value="London"))]
),
limit=3,
).points
assert [r.id for r in search_result] == [4, 2]
def test_sparse_in_memory_key_filter_returns_results(qdrant: QdrantClient):
qdrant.create_collection(
collection_name="test_collection",
vectors_config={},
sparse_vectors_config={"text": models.SparseVectorParams()},
)
operation_info = qdrant.upsert(
collection_name="test_collection",
wait=True,
points=[
models.PointStruct(
id=1,
vector={
"text": models.SparseVector(
indices=[0, 1, 2, 3], values=[0.05, 0.61, 0.76, 0.74]
)
},
payload={"city": "Berlin"},
),
models.PointStruct(
id=2,
vector={
"text": models.SparseVector(
indices=[0, 1, 2, 3], values=[0.19, 0.81, 0.75, 0.11]
)
},
payload={"city": ["Berlin", "London"]},
),
models.PointStruct(
id=3,
vector={
"text": models.SparseVector(
indices=[0, 1, 2, 3], values=[0.36, 0.55, 0.47, 0.94]
)
},
payload={"city": ["Berlin", "Moscow"]},
),
models.PointStruct(
id=4,
vector={
"text": models.SparseVector(
indices=[0, 1, 2, 3], values=[0.18, 0.01, 0.85, 0.80]
)
},
payload={"city": ["London", "Moscow"]},
),
],
)
assert operation_info.operation_id == 0
assert operation_info.status == models.UpdateStatus.COMPLETED
search_result = qdrant.query_points(
collection_name="test_collection",
using="text",
query=models.SparseVector(indices=[0, 1, 2, 3], values=[0.2, 0.1, 0.9, 0.7]),
query_filter=models.Filter(
must=[models.FieldCondition(key="city", match=models.MatchValue(value="London"))]
),
limit=3,
).points
assert [r.id for r in search_result] == [4, 2]