Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

fix(qdrant): update instrumentation for qdrant-client 1.16.0+ (#972)

José Fonte563519ef8cfa
diff --git a/sdk/python/src/openlit/instrumentation/qdrant/__init__.py b/sdk/python/src/openlit/instrumentation/qdrant/__init__.py
index 2f479b23..c432883b 100644
--- a/sdk/python/src/openlit/instrumentation/qdrant/__init__.py
+++ b/sdk/python/src/openlit/instrumentation/qdrant/__init__.py
@@ -10,7 +10,7 @@ from wrapt import wrap_function_wrapper
from openlit.instrumentation.qdrant.qdrant import general_wrap
from openlit.instrumentation.qdrant.async_qdrant import async_general_wrap
-_instruments = ("qdrant-client >= 1.9.0",)
+_instruments = ("qdrant-client >= 1.16.0",)
# Operations to wrap for both sync and async clients
QDRANT_OPERATIONS = [
@@ -29,11 +29,10 @@ QDRANT_OPERATIONS = [
("delete", "qdrant.delete"),
("retrieve", "qdrant.retrieve"),
("scroll", "qdrant.scroll"),
- ("search", "qdrant.search"),
- ("search_groups", "qdrant.search_groups"),
- ("recommend", "qdrant.recommend"),
("create_payload_index", "qdrant.create_payload_index"),
("query_points", "qdrant.query_points"),
+ ("query_batch_points", "qdrant.query_batch_points"),
+ ("query_points_groups", "qdrant.query_points_groups"),
]
diff --git a/sdk/python/src/openlit/instrumentation/qdrant/utils.py b/sdk/python/src/openlit/instrumentation/qdrant/utils.py
index 4e2bcceb..688a5dd0 100644
--- a/sdk/python/src/openlit/instrumentation/qdrant/utils.py
+++ b/sdk/python/src/openlit/instrumentation/qdrant/utils.py
@@ -19,7 +19,7 @@ DB_OPERATION_MAP = {
"qdrant.update_collection": SemanticConvention.DB_OPERATION_UPDATE_COLLECTION,
"qdrant.upsert": SemanticConvention.DB_OPERATION_UPSERT,
"qdrant.upload_points": SemanticConvention.DB_OPERATION_INSERT,
- "qdrant.set_payload": SemanticConvention.DB_OPERATION_INSERT,
+ "qdrant.set_payload": SemanticConvention.DB_OPERATION_UPDATE,
"qdrant.overwrite_payload": SemanticConvention.DB_OPERATION_UPDATE,
"qdrant.update_vectors": SemanticConvention.DB_OPERATION_UPDATE,
"qdrant.delete": SemanticConvention.DB_OPERATION_DELETE,
@@ -28,10 +28,9 @@ DB_OPERATION_MAP = {
"qdrant.clear_payload": SemanticConvention.DB_OPERATION_DELETE,
"qdrant.retrieve": SemanticConvention.DB_OPERATION_GET,
"qdrant.scroll": SemanticConvention.DB_OPERATION_GET,
- "qdrant.search": SemanticConvention.DB_OPERATION_GET,
- "qdrant.search_groups": SemanticConvention.DB_OPERATION_GET,
- "qdrant.recommend": SemanticConvention.DB_OPERATION_GET,
- "qdrant.query_points": SemanticConvention.DB_OPERATION_GET,
+ "qdrant.query_points": SemanticConvention.DB_OPERATION_QUERY,
+ "qdrant.query_batch_points": SemanticConvention.DB_OPERATION_QUERY,
+ "qdrant.query_points_groups": SemanticConvention.DB_OPERATION_QUERY,
"qdrant.create_payload_index": SemanticConvention.DB_OPERATION_CREATE_INDEX,
}
@@ -142,35 +141,7 @@ def common_qdrant_logic(
]:
collection_name = scope._kwargs.get("collection_name", "unknown")
- if endpoint == "qdrant.set_payload":
- points = scope._kwargs.get("points", [])
- payload = scope._kwargs.get("payload", {})
-
- scope._span.set_attribute(
- SemanticConvention.DB_COLLECTION_NAME, collection_name
- )
- scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(points))
- scope._span.set_attribute(
- SemanticConvention.DB_VECTOR_COUNT, object_count(points)
- )
- scope._span.set_attribute(
- SemanticConvention.DB_PAYLOAD_COUNT, object_count(payload)
- )
-
- # Set operation status if response available
- if scope._response and hasattr(scope._response, "status"):
- scope._span.set_attribute(
- SemanticConvention.DB_OPERATION_STATUS, scope._response.status
- )
-
- scope._span.set_attribute(
- SemanticConvention.DB_QUERY_SUMMARY,
- f"{scope._db_operation} {collection_name} "
- f"points={object_count(points)} "
- f"payload={object_count(payload)}",
- )
-
- elif endpoint in ["qdrant.upsert", "qdrant.upload_points"]:
+ if endpoint in ["qdrant.upsert", "qdrant.upload_points"]:
points = scope._kwargs.get("points", [])
scope._span.set_attribute(
@@ -197,7 +168,7 @@ def common_qdrant_logic(
elif scope._db_operation == SemanticConvention.DB_OPERATION_UPDATE:
collection_name = scope._kwargs.get("collection_name", "unknown")
- if endpoint == "qdrant.overwrite_payload":
+ if endpoint in ["qdrant.set_payload", "qdrant.overwrite_payload"]:
points = scope._kwargs.get("points", [])
payload = scope._kwargs.get("payload", {})
@@ -300,7 +271,7 @@ def common_qdrant_logic(
f"selector={object_count(points_selector)}",
)
- # Handle query operations
+ # Handle GET operations (fetch by ID)
elif scope._db_operation == SemanticConvention.DB_OPERATION_GET:
collection_name = scope._kwargs.get("collection_name", "unknown")
@@ -336,51 +307,57 @@ def common_qdrant_logic(
f"{scope._db_operation} {collection_name} filter={scroll_filter}",
)
- elif endpoint in ["qdrant.search", "qdrant.search_groups"]:
- query_vector = scope._kwargs.get("query_vector", [])
+ # Handle QUERY operations (vector similarity search)
+ elif scope._db_operation == SemanticConvention.DB_OPERATION_QUERY:
+ collection_name = scope._kwargs.get("collection_name", "unknown")
+
+ if endpoint == "qdrant.query_points":
+ query = scope._kwargs.get("query", {})
limit = scope._kwargs.get("limit", 10)
scope._span.set_attribute(
SemanticConvention.DB_COLLECTION_NAME, collection_name
)
- scope._span.set_attribute(
- SemanticConvention.DB_QUERY_TEXT, str(query_vector)
- )
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
scope._span.set_attribute(SemanticConvention.DB_VECTOR_QUERY_TOP_K, limit)
scope._span.set_attribute(
SemanticConvention.DB_QUERY_SUMMARY,
- f"{scope._db_operation} {collection_name} limit={limit}",
+ f"{scope._db_operation} {collection_name} query={query} limit={limit}",
)
- elif endpoint == "qdrant.recommend":
- positive = scope._kwargs.get("positive", [])
- negative = scope._kwargs.get("negative", [])
+ elif endpoint == "qdrant.query_batch_points":
+ requests = scope._kwargs.get("requests", [])
scope._span.set_attribute(
SemanticConvention.DB_COLLECTION_NAME, collection_name
)
- query_content = f"positive:{positive} negative:{negative}"
- scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, query_content)
+ scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(requests))
+ scope._span.set_attribute(
+ SemanticConvention.DB_VECTOR_COUNT, object_count(requests)
+ )
scope._span.set_attribute(
SemanticConvention.DB_QUERY_SUMMARY,
- f"{scope._db_operation} {collection_name} "
- f"positive={object_count(positive)} "
- f"negative={object_count(negative)}",
+ f"{scope._db_operation} {collection_name} requests={object_count(requests)}",
)
- elif endpoint == "qdrant.query_points":
+ elif endpoint == "qdrant.query_points_groups":
query = scope._kwargs.get("query", {})
+ group_by = scope._kwargs.get("group_by", "")
+ limit = scope._kwargs.get("limit", 10)
+ group_size = scope._kwargs.get("group_size", 3)
scope._span.set_attribute(
SemanticConvention.DB_COLLECTION_NAME, collection_name
)
scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
+ scope._span.set_attribute(SemanticConvention.DB_VECTOR_QUERY_TOP_K, limit)
scope._span.set_attribute(
SemanticConvention.DB_QUERY_SUMMARY,
- f"{scope._db_operation} {collection_name} query={query}",
+ f"{scope._db_operation} {collection_name} query={query} "
+ f"group_by={group_by} limit={limit} group_size={group_size}",
)
# Handle index operations
diff --git a/sdk/python/tests/test_qdrant.py.hold b/sdk/python/tests/test_qdrant.py.hold
index 866464d7..9d394938 100644
--- a/sdk/python/tests/test_qdrant.py.hold
+++ b/sdk/python/tests/test_qdrant.py.hold
@@ -2,9 +2,10 @@
"""
This module contains tests for Qdrant functionality using the Qdrant Python library.
-Tests cover various API endpoints, including create_collection, add, query,
-upsert, update, get and delete.
-These tests validate integration with OpenLIT.
+Tests cover various API endpoints including collection operations (create, delete),
+point operations (upsert, upload, update, delete), payload operations (set, overwrite, clear, delete),
+retrieval operations (retrieve, scroll), query operations (query_points, query_points_groups,
+query_batch_points), and index management. These tests validate integration with OpenLIT.
Environment Variables:
- QDRANT_URL: Qdrant Cloud Instance URL.
@@ -36,22 +37,21 @@ def test_db_qdrant():
"""
Tests basic operations within a Qdrant collection.
- This includes creating a new collection, adding documents to the collection,
- querying the collection, and deleting documents from the collection. The test
- verifies correct behavior of these operations by asserting expected outcomes at
- each step.
+ This includes creating a new collection, adding points to the collection, modifying payloads and vectors,
+ querying the collection, and deleting points. The test verifies correct behavior
+ of these operations by asserting expected outcomes at each step.
- - A new collection is created and verified for correct naming.
- - Documents are added to the collection with specific metadata and ids,
- and the absence of an error response is verified.
- - A query operation is performed, and its results are verified to match the
- expected document ids.
- - A delete operation targets a specific document by id, and successful deletion
- is implicitly verified by the absence of an error response.
+ - (Commented out) A new collection is created and verified for correct naming.
+ - Points are upserted and uploaded to the collection with metadata.
+ - Payload operations (set, overwrite, clear, delete) are tested.
+ - Vector updates are performed and verified.
+ - Query operations are performed, and results are verified.
+ - Delete operations target specific points by id.
+
+ The test ensures the basic CRUD operations perform as expected in Qdrant.
- The test ensures the basic CRUD operations perform as expected in ChromaDB.
Raises:
- AssertionError: If the responses from ChromaDB operations do not meet the expected outcomes.
+ AssertionError: If the responses from Qdrant operations do not meet the expected outcomes.
"""
# # Create a new collection
@@ -210,35 +210,49 @@ def test_db_qdrant():
# )
# assert isinstance(search, list)
- # Search groups from the collection
- search_groups = client.search_groups(
- collection_name=COLLECTION_NAME,
- query_vector=[1.1, 1.2, 1.3, 1.4],
- group_by="city",
- limit=4,
- group_size=2,
- )
- assert isinstance(search_groups.groups, list)
-
- # Get Recommened vectors from the collection
- recommend = client.recommend(
+ # Query points from the collection
+ query_result = client.query_points(
collection_name=COLLECTION_NAME,
- positive=[1, 3],
- negative=[4, [0.2, 0.3, 0.4, 0.5]],
- strategy=models.RecommendStrategy.AVERAGE_VECTOR,
+ query=[0.2, 0.1, 0.9, 0.7],
query_filter=models.Filter(
must=[
models.FieldCondition(
key="city",
match=models.MatchValue(
- value="London",
+ value="Toronto",
),
)
]
),
limit=3,
)
- assert isinstance(recommend, list)
+ assert hasattr(query_result, "points")
+
+ # Query points groups from the collection
+ query_groups = client.query_points_groups(
+ collection_name=COLLECTION_NAME,
+ query=[1.1, 1.2, 1.3, 1.4],
+ group_by="city",
+ limit=4,
+ group_size=2,
+ )
+ assert isinstance(query_groups.groups, list)
+
+ # Query batch points from the collection
+ batch_result = client.query_batch_points(
+ collection_name=COLLECTION_NAME,
+ requests=[
+ models.QueryRequest(
+ query=[0.2, 0.1, 0.9, 0.7],
+ limit=3,
+ ),
+ models.QueryRequest(
+ query=[0.5, 0.5, 0.5, 0.5],
+ limit=2,
+ ),
+ ],
+ )
+ assert isinstance(batch_result, list)
# # Delete collection
# del_col = client.delete_collection(