Files
qdrant-client/tests/congruence_tests/test_collections.py
George 27acfd0d75 new: remove vectors_count, update http and grpc models (#1069)
* new: remove vectors_count, update http and grpc models

* fix: update inspection cache

* new: add conversions and update interface

* fix: fix some conversions

* fix: fix typo

* fix: fix isinstance

* fix: regen async

* fix: fix update_filter usage, fix isinstance

* tests: collection metadata test

* fix: address backward compatibility in test

* new: update models, add max payload index count and copy vectors

* fix; update _inspection_cache

* new: add read consistency to count points

* Allow uuids in interface (#1085)

* new: direct uuid support

* tests: add uuid tests

* fix: update inspection cache

* new: add collection metadata and tests to local mode (#1089)

* new: add collection metadata and tests to local mode

* fix: regen async client

* new: implement parametrized rrf in local mode (#1087)

* new: implement parametrized rrf in local mode

* refactoring: use a variable for a magic value

* fix: adjust conversion according to AI

* Update filter (#1090)

* new: add missing update_filter, implement it in local mode

* fix: fix type hint, fix update operation, fix rest uploader, add tests

* fix: fix update filter is None case

* fix: mypy was not a good boy

* Text any filter (#1091)

* new: add match text any local mode

* tests: add match text any tests

* 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>

* new: yet another update

* new: add initial_state to create shard key (#1109)

* chore: remove obsolete imports

* fix: add metadata parameter to recreate collection in local

* fix: fix metadata handling in local more

---------

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

162 lines
5.4 KiB
Python

from time import sleep
from typing import Callable
from qdrant_client.http import models
from qdrant_client.http.exceptions import UnexpectedResponse
from tests.congruence_tests.test_common import (
generate_fixtures,
init_client,
init_local,
init_remote,
)
COLLECTION_NAME = "test_collection"
def test_get_collection():
fixture_points = generate_fixtures()
remote_client = init_remote()
remote_collections = remote_client.get_collections()
for collection in remote_collections.collections:
remote_client.delete_collection(collection.name)
local_client = init_local()
init_client(local_client, fixture_points)
init_client(remote_client, fixture_points)
local_collections = local_client.get_collections()
remote_collections = remote_client.get_collections()
assert len(local_collections.collections) == len(remote_collections.collections)
local_collection = local_collections.collections[0].name
remote_collection = remote_collections.collections[0].name
assert local_collection == remote_collection
local_collection_info = local_client.get_collection(local_collection)
remote_collection_info = remote_client.get_collection(remote_collection)
assert local_collection_info.points_count == remote_collection_info.points_count
assert (
local_collection_info.config.params.vectors == remote_collection_info.config.params.vectors
)
def test_recreate_collection():
# this method has been marked as deprecated and should be removed in qdrant-client v1.12
local_client = init_local()
http_client = init_remote()
grpc_client = init_remote(prefer_grpc=True)
vector_params = models.VectorParams(size=20, distance=models.Distance.COSINE)
local_client.recreate_collection(COLLECTION_NAME, vectors_config=vector_params)
http_client.recreate_collection(COLLECTION_NAME, vectors_config=vector_params)
assert local_client.collection_exists(COLLECTION_NAME)
assert http_client.collection_exists(COLLECTION_NAME)
http_client.delete_collection(COLLECTION_NAME)
grpc_client.recreate_collection(COLLECTION_NAME, vectors_config=vector_params)
assert grpc_client.collection_exists(COLLECTION_NAME)
def test_collection_exists():
remote_client = init_remote()
local_client = init_local()
assert not remote_client.collection_exists(COLLECTION_NAME + "_not_exists")
assert not local_client.collection_exists(COLLECTION_NAME + "_not_exists")
vector_params = models.VectorParams(size=2, distance=models.Distance.COSINE)
try:
remote_client.delete_collection(COLLECTION_NAME)
except UnexpectedResponse:
pass # collection does not exist
remote_client.create_collection(COLLECTION_NAME, vectors_config=vector_params)
try:
local_client.delete_collection(COLLECTION_NAME)
except ValueError:
pass # collection does not exist
local_client.create_collection(COLLECTION_NAME, vectors_config=vector_params)
assert remote_client.collection_exists(COLLECTION_NAME)
assert local_client.collection_exists(COLLECTION_NAME)
def test_config_variations():
def check_variation(vectors_config, sparse_vectors_config):
if remote_client.collection_exists(COLLECTION_NAME):
remote_client.delete_collection(COLLECTION_NAME)
if local_client.collection_exists(COLLECTION_NAME):
local_client.delete_collection(COLLECTION_NAME)
remote_client.create_collection(
COLLECTION_NAME,
vectors_config=vectors_config,
sparse_vectors_config=sparse_vectors_config,
)
local_client.create_collection(
COLLECTION_NAME,
vectors_config=vectors_config,
sparse_vectors_config=sparse_vectors_config,
)
remote_client_config_params = remote_client.get_collection(COLLECTION_NAME).config.params
local_client_config_params = local_client.get_collection(COLLECTION_NAME).config.params
assert remote_client_config_params.vectors == local_client_config_params.vectors
assert (
remote_client_config_params.sparse_vectors == local_client_config_params.sparse_vectors
)
remote_grpc_client.delete_collection(COLLECTION_NAME)
remote_grpc_client.create_collection(
COLLECTION_NAME,
vectors_config=vectors_config,
sparse_vectors_config=sparse_vectors_config,
)
assert remote_client_config_params.vectors == local_client_config_params.vectors
assert (
remote_client_config_params.sparse_vectors == local_client_config_params.sparse_vectors
)
remote_client = init_remote()
remote_grpc_client = init_remote(prefer_grpc=True)
local_client = init_local()
vectors_config = models.VectorParams(size=2, distance=models.Distance.COSINE)
sparse_vectors_config = {"sparse": models.SparseVectorParams()}
check_variation(vectors_config, sparse_vectors_config)
check_variation(vectors_config, None)
check_variation(None, sparse_vectors_config)
check_variation({"text": vectors_config}, sparse_vectors_config)
check_variation({"text": vectors_config}, None)
check_variation(None, None)
def wait_for(condition: Callable, *args, **kwargs):
for i in range(0, 10):
try:
condition(*args, **kwargs)
except AssertionError:
sleep(0.5)
continue
break