mirror of
https://github.com/qdrant/qdrant-client.git
synced 2026-07-23 11:11:01 -05:00
tests: speed up tests (#1130)
* fix: do not try to check compatibility in test_client_init * tests: remove sparse-code vectors (10_000 dim), remove euclid recommend methods as non-applicable for sparse * tests: add payload indexes to query group test * debug: add durations=0 to pytest * debug: test only test query group * debug: try adding payload indexes to query group test * rollback test launch
This commit is contained in:
@@ -21,7 +21,6 @@ code_vector_size = 80
|
||||
# sparse vectors sizes
|
||||
sparse_text_vector_size = 100
|
||||
sparse_image_vector_size = 1_000
|
||||
sparse_code_vector_size = 10_000
|
||||
|
||||
# number of vectors to generate
|
||||
NUM_VECTORS = 1000
|
||||
@@ -44,7 +43,6 @@ dense_vectors_config = {
|
||||
sparse_vectors_config = {
|
||||
"sparse-text": models.SparseVectorParams(),
|
||||
"sparse-image": models.SparseVectorParams(),
|
||||
"sparse-code": models.SparseVectorParams(),
|
||||
}
|
||||
|
||||
dense_vectors_sizes = {
|
||||
@@ -56,7 +54,6 @@ dense_vectors_sizes = {
|
||||
sparse_vectors_sizes = {
|
||||
"sparse-text": sparse_text_vector_size,
|
||||
"sparse-image": sparse_image_vector_size,
|
||||
"sparse-code": sparse_code_vector_size,
|
||||
}
|
||||
|
||||
multivectors_sizes = {
|
||||
|
||||
@@ -131,7 +131,7 @@ def test_simple_opt_sparse_vectors_search():
|
||||
COLLECTION_NAME,
|
||||
vectors_to_retrieve,
|
||||
with_payload=False,
|
||||
with_vectors=["sparse-image", "sparse-code"],
|
||||
with_vectors=["sparse-image", "sparse-text"],
|
||||
),
|
||||
key=lambda x: x.id,
|
||||
),
|
||||
@@ -164,7 +164,7 @@ def test_simple_opt_sparse_vectors_search():
|
||||
COLLECTION_NAME,
|
||||
vectors_to_retrieve,
|
||||
with_payload=False,
|
||||
with_vectors=["sparse-image", "sparse-code"],
|
||||
with_vectors=["sparse-image", "sparse-text"],
|
||||
),
|
||||
key=lambda x: x.id,
|
||||
),
|
||||
|
||||
@@ -20,7 +20,6 @@ from tests.congruence_tests.test_common import (
|
||||
text_vector_size,
|
||||
sparse_text_vector_size,
|
||||
sparse_image_vector_size,
|
||||
sparse_code_vector_size,
|
||||
generate_sparse_fixtures,
|
||||
sparse_vectors_config,
|
||||
generate_multivector_fixtures,
|
||||
@@ -60,9 +59,6 @@ class TestSimpleSearcher:
|
||||
self.sparse_vector_query_image = generate_random_sparse_vector(
|
||||
sparse_image_vector_size, density=0.2
|
||||
)
|
||||
self.sparse_vector_query_code = generate_random_sparse_vector(
|
||||
sparse_code_vector_size, density=0.1
|
||||
)
|
||||
|
||||
# multivector query vectors
|
||||
self.multivector_query_text = generate_random_multivector(text_vector_size, 3)
|
||||
@@ -1661,6 +1657,31 @@ def test_query_group():
|
||||
init_client(local_client, secondary_collection_points, SECONDARY_COLLECTION_NAME)
|
||||
init_client(http_client, secondary_collection_points, SECONDARY_COLLECTION_NAME)
|
||||
|
||||
http_client.create_payload_index(
|
||||
COLLECTION_NAME, field_name="id", field_schema=models.PayloadSchemaType.INTEGER
|
||||
)
|
||||
http_client.create_payload_index(
|
||||
COLLECTION_NAME, field_name="rand_digit", field_schema=models.PayloadSchemaType.INTEGER
|
||||
)
|
||||
http_client.create_payload_index(
|
||||
COLLECTION_NAME, field_name="two_words", field_schema=models.PayloadSchemaType.KEYWORD
|
||||
)
|
||||
http_client.create_payload_index(
|
||||
COLLECTION_NAME,
|
||||
field_name="city.name",
|
||||
field_schema=models.PayloadSchemaType.KEYWORD,
|
||||
)
|
||||
http_client.create_payload_index(
|
||||
COLLECTION_NAME,
|
||||
field_name="maybe",
|
||||
field_schema=models.PayloadSchemaType.KEYWORD,
|
||||
)
|
||||
http_client.create_payload_index(
|
||||
COLLECTION_NAME,
|
||||
field_name="maybe_null",
|
||||
field_schema=models.PayloadSchemaType.KEYWORD,
|
||||
)
|
||||
|
||||
searcher.group_size = 5
|
||||
searcher.limit = 3
|
||||
for key in group_by_keys():
|
||||
@@ -1687,6 +1708,7 @@ def test_query_group():
|
||||
)
|
||||
|
||||
searcher.group_by = "city.name"
|
||||
|
||||
for i in range(100):
|
||||
query_filter = one_random_filter_please()
|
||||
try:
|
||||
|
||||
@@ -104,7 +104,7 @@ def test_sparse_retrieve() -> None:
|
||||
compare_client_results(
|
||||
local_client,
|
||||
remote_client,
|
||||
lambda c: c.retrieve(COLLECTION_NAME, [id_], with_vectors=["sparse-image", "sparse-code"]),
|
||||
lambda c: c.retrieve(COLLECTION_NAME, [id_], with_vectors=["sparse-image", "sparse-text"]),
|
||||
)
|
||||
compare_client_results(
|
||||
local_client,
|
||||
@@ -112,7 +112,7 @@ def test_sparse_retrieve() -> None:
|
||||
lambda c: c.retrieve(
|
||||
COLLECTION_NAME,
|
||||
[id_],
|
||||
with_vectors=["sparse-image", "sparse-code"],
|
||||
with_vectors=["sparse-image", "sparse-text"],
|
||||
with_payload=False,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -47,7 +47,7 @@ class TestSimpleRecommendation:
|
||||
query=models.RecommendQuery(recommend=models.RecommendInput(positive=[10, 19])),
|
||||
with_payload=True,
|
||||
limit=10,
|
||||
using="sparse-image",
|
||||
using="sparse-text",
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
@@ -59,7 +59,7 @@ class TestSimpleRecommendation:
|
||||
),
|
||||
with_payload=True,
|
||||
limit=10,
|
||||
using="sparse-image",
|
||||
using="sparse-text",
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
@@ -106,7 +106,7 @@ class TestSimpleRecommendation:
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
def best_score_recommend_euclid(cls, client: QdrantBase) -> list[models.ScoredPoint]:
|
||||
def best_score_recommend_pos_neg(cls, client: QdrantBase) -> list[models.ScoredPoint]:
|
||||
return client.query_points(
|
||||
collection_name=COLLECTION_NAME,
|
||||
query=models.RecommendQuery(
|
||||
@@ -118,7 +118,7 @@ class TestSimpleRecommendation:
|
||||
),
|
||||
with_payload=True,
|
||||
limit=10,
|
||||
using="sparse-code",
|
||||
using="sparse-image",
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
@@ -135,22 +135,6 @@ class TestSimpleRecommendation:
|
||||
using="sparse-image",
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
def only_negatives_best_score_recommend_euclid(
|
||||
cls, client: QdrantBase
|
||||
) -> list[models.ScoredPoint]:
|
||||
return client.query_points(
|
||||
collection_name=COLLECTION_NAME,
|
||||
query=models.RecommendQuery(
|
||||
recommend=models.RecommendInput(
|
||||
positive=None, negative=[10, 12], strategy=models.RecommendStrategy.BEST_SCORE
|
||||
)
|
||||
),
|
||||
with_payload=True,
|
||||
limit=10,
|
||||
using="sparse-code",
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
def sum_scores_recommend(cls, client: QdrantBase) -> list[models.ScoredPoint]:
|
||||
return client.query_points(
|
||||
@@ -166,7 +150,7 @@ class TestSimpleRecommendation:
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
def sum_scores_recommend_euclid(cls, client: QdrantBase) -> list[models.ScoredPoint]:
|
||||
def sum_scores_recommend_pos_neg(cls, client: QdrantBase) -> list[models.ScoredPoint]:
|
||||
return client.query_points(
|
||||
collection_name=COLLECTION_NAME,
|
||||
query=models.RecommendQuery(
|
||||
@@ -178,7 +162,7 @@ class TestSimpleRecommendation:
|
||||
),
|
||||
with_payload=True,
|
||||
limit=10,
|
||||
using="sparse-code",
|
||||
using="sparse-image",
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
@@ -195,22 +179,6 @@ class TestSimpleRecommendation:
|
||||
using="sparse-image",
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
def only_negatives_sum_scores_recommend_euclid(
|
||||
cls, client: QdrantBase
|
||||
) -> list[models.ScoredPoint]:
|
||||
return client.query_points(
|
||||
collection_name=COLLECTION_NAME,
|
||||
query=models.RecommendQuery(
|
||||
recommend=models.RecommendInput(
|
||||
positive=None, negative=[10, 12], strategy=models.RecommendStrategy.SUM_SCORES
|
||||
)
|
||||
),
|
||||
with_payload=True,
|
||||
limit=10,
|
||||
using="sparse-code",
|
||||
).points
|
||||
|
||||
@classmethod
|
||||
def avg_vector_recommend(cls, client: QdrantBase) -> list[models.ScoredPoint]:
|
||||
return client.query_points(
|
||||
@@ -286,7 +254,6 @@ class TestSimpleRecommendation:
|
||||
|
||||
def test_simple_recommend() -> None:
|
||||
fixture_points = generate_sparse_fixtures()
|
||||
|
||||
secondary_collection_points = generate_sparse_fixtures(100)
|
||||
|
||||
searcher = TestSimpleRecommendation()
|
||||
@@ -320,35 +287,26 @@ def test_simple_recommend() -> None:
|
||||
vectors_config={},
|
||||
sparse_vectors_config=sparse_vectors_config,
|
||||
)
|
||||
|
||||
compare_client_results(local_client, remote_client, searcher.simple_recommend_image)
|
||||
compare_client_results(local_client, remote_client, searcher.many_recommend)
|
||||
compare_client_results(local_client, remote_client, searcher.simple_recommend_negative)
|
||||
compare_client_results(local_client, remote_client, searcher.recommend_from_another_collection)
|
||||
compare_client_results(local_client, remote_client, searcher.best_score_recommend)
|
||||
compare_client_results(local_client, remote_client, searcher.best_score_recommend_euclid)
|
||||
compare_client_results(local_client, remote_client, searcher.best_score_recommend_pos_neg)
|
||||
compare_client_results(
|
||||
local_client, remote_client, searcher.only_negatives_best_score_recommend
|
||||
)
|
||||
compare_client_results(
|
||||
local_client, remote_client, searcher.only_negatives_best_score_recommend_euclid
|
||||
)
|
||||
compare_client_results(local_client, remote_client, searcher.sum_scores_recommend)
|
||||
compare_client_results(local_client, remote_client, searcher.sum_scores_recommend_euclid)
|
||||
compare_client_results(local_client, remote_client, searcher.sum_scores_recommend_pos_neg)
|
||||
compare_client_results(
|
||||
local_client, remote_client, searcher.only_negatives_sum_scores_recommend
|
||||
)
|
||||
compare_client_results(
|
||||
local_client, remote_client, searcher.only_negatives_sum_scores_recommend_euclid
|
||||
)
|
||||
|
||||
compare_client_results(local_client, remote_client, searcher.avg_vector_recommend)
|
||||
compare_client_results(local_client, remote_client, searcher.recommend_from_raw_vectors)
|
||||
compare_client_results(
|
||||
local_client, remote_client, searcher.recommend_from_raw_vectors_and_ids
|
||||
)
|
||||
compare_client_results(local_client, remote_client, searcher.recommend_batch)
|
||||
|
||||
for _ in range(10):
|
||||
query_filter = one_random_filter_please()
|
||||
try:
|
||||
|
||||
@@ -11,7 +11,6 @@ from tests.congruence_tests.test_common import (
|
||||
init_client,
|
||||
init_local,
|
||||
init_remote,
|
||||
sparse_code_vector_size,
|
||||
sparse_image_vector_size,
|
||||
sparse_text_vector_size,
|
||||
sparse_vectors_config,
|
||||
@@ -26,7 +25,6 @@ class TestSimpleSparseSearcher:
|
||||
def __init__(self):
|
||||
self.query_text = generate_random_sparse_vector(sparse_text_vector_size, density=0.3)
|
||||
self.query_image = generate_random_sparse_vector(sparse_image_vector_size, density=0.2)
|
||||
self.query_code = generate_random_sparse_vector(sparse_code_vector_size, density=0.1)
|
||||
|
||||
def simple_search_text(self, client: QdrantBase) -> list[models.ScoredPoint]:
|
||||
return client.query_points(
|
||||
@@ -48,16 +46,6 @@ class TestSimpleSparseSearcher:
|
||||
limit=10,
|
||||
).points
|
||||
|
||||
def simple_search_code(self, client: QdrantBase) -> list[models.ScoredPoint]:
|
||||
return client.query_points(
|
||||
collection_name=COLLECTION_NAME,
|
||||
using="sparse-code",
|
||||
query=self.query_code,
|
||||
with_payload=True,
|
||||
with_vectors=True,
|
||||
limit=10,
|
||||
).points
|
||||
|
||||
def simple_search_text_offset(self, client: QdrantBase) -> list[models.ScoredPoint]:
|
||||
return client.query_points(
|
||||
collection_name=COLLECTION_NAME,
|
||||
@@ -122,7 +110,7 @@ class TestSimpleSparseSearcher:
|
||||
using="sparse-image",
|
||||
query=self.query_image,
|
||||
with_payload=False,
|
||||
with_vectors=["sparse-image", "sparse-code"],
|
||||
with_vectors=["sparse-image", "sparse-text"],
|
||||
limit=10,
|
||||
).points
|
||||
|
||||
@@ -186,7 +174,6 @@ def test_simple_search():
|
||||
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_text)
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_image)
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_code)
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_text_offset)
|
||||
compare_client_results(local_client, remote_client, searcher.search_score_threshold)
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_text_select_payload)
|
||||
@@ -235,7 +222,6 @@ def test_simple_opt_vectors_search():
|
||||
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_text)
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_image)
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_code)
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_text_offset)
|
||||
compare_client_results(local_client, remote_client, searcher.search_score_threshold)
|
||||
compare_client_results(local_client, remote_client, searcher.simple_search_text_select_payload)
|
||||
|
||||
@@ -103,7 +103,7 @@ def test_client_init():
|
||||
assert isinstance(client._client, QdrantLocal)
|
||||
assert client._client.location == tmpdir + "/test.db"
|
||||
|
||||
client = QdrantClient()
|
||||
client = QdrantClient(check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://localhost:6333"
|
||||
|
||||
@@ -113,22 +113,22 @@ def test_client_init():
|
||||
client = QdrantClient(check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
|
||||
client = QdrantClient(prefer_grpc=True)
|
||||
client = QdrantClient(prefer_grpc=True, check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
|
||||
client = QdrantClient(https=True)
|
||||
client = QdrantClient(https=True, check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "https://localhost:6333"
|
||||
|
||||
client = QdrantClient(https=True, port=7333)
|
||||
client = QdrantClient(https=True, port=7333, check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "https://localhost:7333"
|
||||
|
||||
client = QdrantClient(host="hidden_port_addr.com", prefix="custom")
|
||||
client = QdrantClient(host="hidden_port_addr.com", prefix="custom", check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://hidden_port_addr.com:6333/custom"
|
||||
|
||||
client = QdrantClient(host="hidden_port_addr.com", port=None)
|
||||
client = QdrantClient(host="hidden_port_addr.com", port=None, check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://hidden_port_addr.com"
|
||||
|
||||
@@ -136,73 +136,80 @@ def test_client_init():
|
||||
host="hidden_port_addr.com",
|
||||
port=None,
|
||||
prefix="custom",
|
||||
check_compatibility=False,
|
||||
)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://hidden_port_addr.com/custom"
|
||||
|
||||
client = QdrantClient("http://hidden_port_addr.com", port=None)
|
||||
client = QdrantClient("http://hidden_port_addr.com", port=None, check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://hidden_port_addr.com"
|
||||
|
||||
# url takes precedence over port, which has default value for a backward compatibility
|
||||
client = QdrantClient(url="http://localhost:6333", port=7333)
|
||||
client = QdrantClient(url="http://localhost:6333", port=7333, check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://localhost:6333"
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333", prefix="custom")
|
||||
client = QdrantClient(url="http://localhost:6333", prefix="custom", check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://localhost:6333/custom"
|
||||
|
||||
for prefix in ("api/v1", "/api/v1"):
|
||||
client = QdrantClient(url="http://localhost:6333", prefix=prefix)
|
||||
client = QdrantClient(
|
||||
url="http://localhost:6333", prefix=prefix, check_compatibility=False
|
||||
)
|
||||
assert (
|
||||
isinstance(client._client, QdrantRemote)
|
||||
and client._client.rest_uri == "http://localhost:6333/api/v1"
|
||||
)
|
||||
|
||||
client = QdrantClient(host="localhost", prefix=prefix)
|
||||
client = QdrantClient(host="localhost", prefix=prefix, check_compatibility=False)
|
||||
assert (
|
||||
isinstance(client._client, QdrantRemote)
|
||||
and client._client.rest_uri == "http://localhost:6333/api/v1"
|
||||
)
|
||||
|
||||
for prefix in ("api/v1/", "/api/v1/"):
|
||||
client = QdrantClient(url="http://localhost:6333", prefix=prefix)
|
||||
client = QdrantClient(
|
||||
url="http://localhost:6333", prefix=prefix, check_compatibility=False
|
||||
)
|
||||
assert (
|
||||
isinstance(client._client, QdrantRemote)
|
||||
and client._client.rest_uri == "http://localhost:6333/api/v1/"
|
||||
)
|
||||
|
||||
client = QdrantClient(host="localhost", prefix=prefix)
|
||||
client = QdrantClient(host="localhost", prefix=prefix, check_compatibility=False)
|
||||
assert (
|
||||
isinstance(client._client, QdrantRemote)
|
||||
and client._client.rest_uri == "http://localhost:6333/api/v1/"
|
||||
)
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333/custom")
|
||||
client = QdrantClient(url="http://localhost:6333/custom", check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://localhost:6333/custom"
|
||||
assert client._client._prefix == "/custom"
|
||||
|
||||
client = QdrantClient("my-domain.com")
|
||||
client = QdrantClient("my-domain.com", check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://my-domain.com:6333"
|
||||
|
||||
client = QdrantClient("my-domain.com:80")
|
||||
client = QdrantClient("my-domain.com:80", check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://my-domain.com:80"
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
QdrantClient(url="http://localhost:6333", host="localhost")
|
||||
QdrantClient(url="http://localhost:6333", host="localhost", check_compatibility=False)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
QdrantClient(url="http://localhost:6333/origin", prefix="custom")
|
||||
QdrantClient(
|
||||
url="http://localhost:6333/origin", prefix="custom", check_compatibility=False
|
||||
)
|
||||
|
||||
client = QdrantClient("127.0.0.1:6333")
|
||||
client = QdrantClient("127.0.0.1:6333", check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://127.0.0.1:6333"
|
||||
|
||||
client = QdrantClient("localhost:6333")
|
||||
client = QdrantClient("localhost:6333", check_compatibility=False)
|
||||
assert isinstance(client._client, QdrantRemote)
|
||||
assert client._client.rest_uri == "http://localhost:6333"
|
||||
|
||||
@@ -225,7 +232,10 @@ def test_client_init():
|
||||
QdrantClient(**params)
|
||||
|
||||
client = QdrantClient(
|
||||
url="http://localhost:6333", prefix="custom", metadata={"some-rest-meta": "some-value"}
|
||||
url="http://localhost:6333",
|
||||
prefix="custom",
|
||||
metadata={"some-rest-meta": "some-value"},
|
||||
check_compatibility=False,
|
||||
)
|
||||
assert client.init_options["url"] == "http://localhost:6333"
|
||||
assert client.init_options["prefix"] == "custom"
|
||||
|
||||
Reference in New Issue
Block a user