Skip to content

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

[Feat]: Add OpenTelemetry instrumentation for Monitoring LLM Applications using Qdrant (#232)

patcher9635987c59797
diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml
index 551e66d1..7a83d205 100644
--- a/.github/workflows/python-tests.yml
+++ b/.github/workflows/python-tests.yml
@@ -20,6 +20,8 @@ env:
MISTRAL_API_TOKEN: ${{ secrets.MISTRAL_API_TOKEN }}
PINECONE_API_TOKEN: ${{ secrets.PINECONE_API_TOKEN }}
GROQ_API_TOKEN: ${{ secrets.GROQ_API_TOKEN }}
+ QDRANT_URL: ${{ secrets.QDRANT_URL }}
+ QDRANT_API_TOKEN: ${{ secrets.QDRANT_API_TOKEN }}
jobs:
build:
diff --git a/docs/images/docs-qdrant-banner.gif b/docs/images/docs-qdrant-banner.gif
new file mode 100644
index 00000000..e73c6a50
Binary files /dev/null and b/docs/images/docs-qdrant-banner.gif differ
diff --git a/docs/latest/integrations/chromadb.mdx b/docs/latest/integrations/chromadb.mdx
index 492e6ee9..b84ab296 100644
--- a/docs/latest/integrations/chromadb.mdx
+++ b/docs/latest/integrations/chromadb.mdx
@@ -10,7 +10,7 @@ sidebarTitle: 'ChromaDB'
OpenLIT SDKs provide OpenTelemetry Auto-Instrumentation for monitoring LLM Application using ChromaDB which includes performance, Operation stats and more.
The integration is compatible with
-- PineCone Python SDK client `>= 0.4.0`
+- ChromaDB Python SDK client `>= 0.4.0`
## Get Started
diff --git a/docs/latest/integrations/introduction.mdx b/docs/latest/integrations/introduction.mdx
index 7e467624..35f1734a 100644
--- a/docs/latest/integrations/introduction.mdx
+++ b/docs/latest/integrations/introduction.mdx
@@ -185,7 +185,7 @@ Start integrating and monitoring your applications with OpenLIT effortlessly. Ch
title="ChromaDB"
href="/latest/integrations/chromadb"
icon={
- <svg viewBox="0 0 256 296" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
+ <svg viewBox="0 0 256 256" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
<title>Chroma</title>
<g>
<ellipse fill="#FFDE2D" cx="170.666795" cy="81.9198362" rx="85.3332053" ry="81.9198362"></ellipse>
@@ -211,6 +211,34 @@ Start integrating and monitoring your applications with OpenLIT effortlessly. Ch
iconType="duotone"
>
</Card>
+ <Card
+ title="Qdrant"
+ href="/latest/integrations/qdrant"
+ icon={
+ <svg viewBox="0 0 286 286" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
+ <title>qdrant</title>
+ <defs>
+ <linearGradient x1="81.5619048%" y1="44.8421053%" x2="-18.0857143%" y2="44.8421053%" id="linearGradient-1">
+ <stop stop-color="#FF3364" offset="0%"></stop>
+ <stop stop-color="#C91540" stop-opacity="0" offset="100%"></stop>
+ </linearGradient>
+ </defs>
+ <g>
+ <polygon fill="#24386C" points="201.31705 271.722427 195.422715 109.21267 184.747781 66.3682368 256 73.9112545 256 270.492509 212.474757 295.612626"></polygon>
+ <polygon fill="#7589BE" points="255.995151 73.8998107 212.469908 99.037384 122.649634 79.3346471 17.5160008 122.140288 1.1370484e-14 73.8998107 63.9883137 36.9499053 127.996024 0 191.986277 36.9499053"></polygon>
+ <polyline fill="#B2BFE8" points="0.00310340412 73.8998107 43.5283462 99.037384 68.7590217 174.073816 153.949405 242.236209 128.001067 295.599243 63.9933568 258.647398 0.00310340412 221.697492 0.00310340412 73.897871"></polyline>
+ <polyline fill="#24386C" points="156.856906 202.807459 128.001067 245.347371 128.001067 295.603122 168.946605 271.978458 190.043934 240.475027"></polyline>
+ <polygon fill="#7589BE" points="128.018523 195.107138 87.0555287 124.184656 95.8787005 100.678309 129.42068 84.4156955 168.946411 124.185819"></polygon>
+ <polyline fill="#B2BFE8" points="87.0555287 124.178837 128.001067 147.803501 128.001067 195.091621 90.131778 196.720927 67.2247763 167.471344 87.0555287 124.178856"></polyline>
+ <polygon fill="#24386C" points="128.001067 147.799621 168.946605 124.176897 196.813234 170.576668 163.090869 198.439418 128.001067 195.089293"></polygon>
+ <path d="M168.946605,271.974579 L212.471848,295.601182 L212.471848,99.0393237 L170.226759,74.658205 L128.001067,50.2770864 L85.7559782,74.658205 L43.5302858,99.0393237 L43.5302858,196.581255 L85.7559782,220.962373 L128.001067,245.345432 L168.946605,221.699432 L168.946605,271.974579 Z M168.946605,171.443681 L128.001067,195.087742 L87.0555287,171.443681 L87.0555287,124.174957 L128.001067,100.530897 L168.946605,124.174957 L168.946605,171.443681" fill="#DC244C"></path>
+ <polygon fill="url(#linearGradient-1)" points="128.018523 245.362888 128.018523 195.099379 87.2863443 171.657041 87.2863443 221.837146"></polygon>
+ </g>
+ </svg>
+ }
+ iconType="duotone"
+ >
+ </Card>
</CardGroup>
### Frameworks
diff --git a/docs/latest/integrations/qdrant.mdx b/docs/latest/integrations/qdrant.mdx
new file mode 100644
index 00000000..8ab334af
--- /dev/null
+++ b/docs/latest/integrations/qdrant.mdx
@@ -0,0 +1,52 @@
+---
+title: 'Monitor Qdrant using OpenTelemetry'
+sidebarTitle: 'Qdrant'
+---
+
+<Frame>
+ <img src="/images/docs-qdrant-banner.gif" />
+</Frame>
+
+OpenLIT SDKs provide OpenTelemetry Auto-Instrumentation for monitoring LLM Application using Qdrant which includes performance, Operation stats and more.
+
+The integration is compatible with
+- Qdrant Python SDK client `>= 1.9.0`
+
+## Get Started
+
+<Steps>
+ <Step title="Install the OpenLIT Python SDK using pip">
+ ```shell
+ pip install openlit
+ ```
+ </Step>
+ <Step title="Add the following two lines to your application code:">
+ Integrating the OpenLIT into LLM applications is straightforward. Start monitoring for your LLM Application with just **one line of code**:
+
+ ```python
+ import openlit
+
+ openlit.init(otlp_endpoint="otlp_backend_endpoint", otlp_headers="otlp_backend_token")
+ ```
+
+ Alternatively, you can configure the OTLP endpoint by setting the `OTEL_EXPORTER_OTLP_ENDPOINT` and the OTLP headers by setting the Appli`OTEL_EXPORTER_OTLP_HEADERS` environmentcation variable as recommended in the OpenTelemetry documentation.
+
+ If your aim is primarily to test or develop without sending telemetry data to an external backend, you can initialize OpenLIT without any parameters. This approach directs all telemetry output to your console, enabling quick diagnostics and local debugging:
+
+ ```python
+ import openlit
+
+ openlit.init()
+ ```
+
+ Refer to the OpenLIT [Python SDK repository](https://github.com/openlit/openlit/tree/main/sdk/python) for more advanced configurations and use cases.
+ </Step>
+</Steps>
+
+---
+
+<CardGroup cols={2}>
+<Card title="Connections" href="/latest/connections/intro" icon='link'>
+Connect to your existing Observablity Stack
+</Card>
+</CardGroup>
\ No newline at end of file
diff --git a/docs/mint.json b/docs/mint.json
index a7b782f9..4da53942 100644
--- a/docs/mint.json
+++ b/docs/mint.json
@@ -75,7 +75,8 @@
"version": "latest",
"pages": [
"latest/integrations/chromadb",
- "latest/integrations/pinecone"
+ "latest/integrations/pinecone",
+ "latest/integrations/qdrant"
]
},
{
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index 4ef9a297..cc61adce 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.4.0"
+version = "1.5.0"
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects"
authors = ["OpenLIT"]
repository = "https://github.com/openlit/openlit/tree/main/openlit/python"
diff --git a/sdk/python/src/openlit/__init__.py b/sdk/python/src/openlit/__init__.py
index 8643c10f..c4d381fb 100644
--- a/sdk/python/src/openlit/__init__.py
+++ b/sdk/python/src/openlit/__init__.py
@@ -25,6 +25,7 @@ from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
from openlit.instrumentation.haystack import HaystackInstrumentor
from openlit.instrumentation.chroma import ChromaInstrumentor
from openlit.instrumentation.pinecone import PineconeInstrumentor
+from openlit.instrumentation.qdrant import QdrantInstrumentor
from openlit.instrumentation.transformers import TransformersInstrumentor
# Set up logging for error and information messages.
@@ -158,6 +159,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
"haystack": "haystack",
"chroma": "chromadb",
"pinecone": "pinecone",
+ "qdrant": "qdrant_client",
"transformers": "transformers"
}
@@ -209,6 +211,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
"haystack": HaystackInstrumentor(),
"chroma": ChromaInstrumentor(),
"pinecone": PineconeInstrumentor(),
+ "qdrant": QdrantInstrumentor(),
"transformers": TransformersInstrumentor()
}
diff --git a/sdk/python/src/openlit/instrumentation/chroma/chroma.py b/sdk/python/src/openlit/instrumentation/chroma/chroma.py
index 3c89e5ce..df64d965 100644
--- a/sdk/python/src/openlit/instrumentation/chroma/chroma.py
+++ b/sdk/python/src/openlit/instrumentation/chroma/chroma.py
@@ -85,7 +85,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
if gen_ai_endpoint == "chroma.add":
db_operation = SemanticConvetion.DB_OPERATION_ADD
span.set_attribute(SemanticConvetion.DB_OPERATION,
- SemanticConvetion.DB_OPERATION_GET)
+ SemanticConvetion.DB_OPERATION_ADD)
span.set_attribute(SemanticConvetion.DB_ID_COUNT,
object_count(kwargs.get("ids")))
span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
diff --git a/sdk/python/src/openlit/instrumentation/qdrant/__init__.py b/sdk/python/src/openlit/instrumentation/qdrant/__init__.py
new file mode 100644
index 00000000..7bce53f2
--- /dev/null
+++ b/sdk/python/src/openlit/instrumentation/qdrant/__init__.py
@@ -0,0 +1,155 @@
+# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
+"""Initializer of Auto Instrumentation of Qdrant Functions"""
+from typing import Collection
+import importlib.metadata
+from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
+from wrapt import wrap_function_wrapper
+
+from openlit.instrumentation.qdrant.qdrant import general_wrap
+
+_instruments = ("qdrant-client >= 1.9.0",)
+
+WRAPPED_METHODS = [
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.create_collection",
+ "endpoint": "qdrant.create_collection",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.delete_collection",
+ "endpoint": "qdrant.delete_collection",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.update_collection",
+ "endpoint": "qdrant.update_collection",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.upload_collection",
+ "endpoint": "qdrant.upload_collection",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.upsert",
+ "endpoint": "qdrant.upsert",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.set_payload",
+ "endpoint": "qdrant.set_payload",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.overwrite_payload",
+ "endpoint": "qdrant.overwrite_payload",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.clear_payload",
+ "endpoint": "qdrant.clear_payload",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.delete_payload",
+ "endpoint": "qdrant.delete_payload",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.upload_points",
+ "endpoint": "qdrant.upload_points",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.update_vectors",
+ "endpoint": "qdrant.update_vectors",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.delete_vectors",
+ "endpoint": "qdrant.delete_vectors",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.delete",
+ "endpoint": "qdrant.delete",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.retrieve",
+ "endpoint": "qdrant.retrieve",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.scroll",
+ "endpoint": "qdrant.scroll",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.search",
+ "endpoint": "qdrant.search",
+ "wrapper": general_wrap,
+ },
+ {
+ "package": "qdrant_client",
+ "object": "QdrantClient.search_groups",
+ "endpoint": "qdrant.search_groups",
+ "wrapper": general_wrap,
+ },
+ {
+
+ "package": "qdrant_client",
+ "object": "QdrantClient.recommend",
+ "endpoint": "qdrant.recommend",
+ "wrapper": general_wrap,
+ }
+]
+
+class QdrantInstrumentor(BaseInstrumentor):
+ """An instrumentor for Qdrant's client library."""
+
+ def instrumentation_dependencies(self) -> Collection[str]:
+ return _instruments
+
+ def _instrument(self, **kwargs):
+ application_name = kwargs.get("application_name")
+ environment = kwargs.get("environment")
+ tracer = kwargs.get("tracer")
+ metrics = kwargs.get("metrics_dict")
+ pricing_info = kwargs.get("pricing_info")
+ trace_content = kwargs.get("trace_content")
+ disable_metrics = kwargs.get("disable_metrics")
+ version = importlib.metadata.version("qdrant-client")
+
+ for wrapped_method in WRAPPED_METHODS:
+ wrap_package = wrapped_method.get("package")
+ wrap_object = wrapped_method.get("object")
+ gen_ai_endpoint = wrapped_method.get("endpoint")
+ wrapper = wrapped_method.get("wrapper")
+ wrap_function_wrapper(
+ wrap_package,
+ wrap_object,
+ wrapper(gen_ai_endpoint, version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
+ )
+
+
+ @staticmethod
+ def _uninstrument(self, **kwargs):
+ pass
diff --git a/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py b/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py
new file mode 100644
index 00000000..25fe56ba
--- /dev/null
+++ b/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py
@@ -0,0 +1,258 @@
+# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment, too-many-branches
+"""
+Module for monitoring Qdrant.
+"""
+
+import logging
+from opentelemetry.trace import SpanKind, Status, StatusCode
+from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from openlit.__helpers import handle_exception
+from openlit.semcov import SemanticConvetion
+
+# Initialize logger for logging potential issues and operations
+logger = logging.getLogger(__name__)
+
+def object_count(obj):
+ """
+ Counts Length of object if it exists, Else returns None
+ """
+ try:
+ cnt = len(obj)
+ # pylint: disable=bare-except
+ except:
+ cnt = 0
+
+ return cnt
+
+def general_wrap(gen_ai_endpoint, version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
+ """
+ Creates a wrapper around a function call to trace and log its execution metrics.
+
+ This function wraps any given function to measure its execution time,
+ log its operation, and trace its execution using OpenTelemetry.
+
+ Parameters:
+ - gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
+ - version (str): The version of the Langchain application.
+ - environment (str): The deployment environment (e.g., 'production', 'development').
+ - application_name (str): Name of the Langchain application.
+ - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
+ - pricing_info (dict): Information about the pricing for internal metrics (currently not used).
+ - trace_content (bool): Flag indicating whether to trace the content of the response.
+
+ Returns:
+ - function: A higher-order function that takes a function 'wrapped' and returns
+ a new function that wraps 'wrapped' with additional tracing and logging.
+ """
+
+ def wrapper(wrapped, instance, args, kwargs):
+ """
+ An inner wrapper function that executes the wrapped function, measures execution
+ time, and records trace data using OpenTelemetry.
+
+ Parameters:
+ - wrapped (Callable): The original function that this wrapper will execute.
+ - instance (object): The instance to which the wrapped function belongs. This
+ is used for instance methods. For static and classmethods,
+ this may be None.
+ - args (tuple): Positional arguments passed to the wrapped function.
+ - kwargs (dict): Keyword arguments passed to the wrapped function.
+
+ Returns:
+ - The result of the wrapped function call.
+
+ The wrapper initiates a span with the provided tracer, sets various attributes
+ on the span based on the function's execution and response, and ensures
+ errors are handled and logged appropriately.
+ """
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ response = wrapped(*args, **kwargs)
+
+ try:
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
+ gen_ai_endpoint)
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ environment)
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
+ SemanticConvetion.GEN_AI_TYPE_VECTORDB)
+ span.set_attribute(SemanticConvetion.DB_SYSTEM,
+ SemanticConvetion.DB_SYSTEM_QDRANT)
+
+ if gen_ai_endpoint == "qdrant.create_collection":
+ db_operation = SemanticConvetion.DB_OPERATION_CREATE_COLLECTION
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_CREATE_COLLECTION)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+
+ elif gen_ai_endpoint == "qdrant.upload_collection":
+ db_operation = SemanticConvetion.DB_OPERATION_CREATE_COLLECTION
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_CREATE_COLLECTION)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+
+ elif gen_ai_endpoint == "qdrant.delete_collection":
+ db_operation = SemanticConvetion.DB_OPERATION_DELETE_COLLECTION
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_DELETE_COLLECTION)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+
+ elif gen_ai_endpoint == "qdrant.update_collection":
+ db_operation = SemanticConvetion.DB_OPERATION_UPDATE_COLLECTION
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_UPDATE_COLLECTION)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+
+ elif gen_ai_endpoint == "qdrant.set_payload":
+ db_operation = SemanticConvetion.DB_OPERATION_ADD
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_ADD)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
+ response.status)
+ span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
+ object_count(kwargs.get("points")))
+ span.set_attribute(SemanticConvetion.DB_PAYLOAD_COUNT,
+ object_count(kwargs.get("payload")))
+
+ elif gen_ai_endpoint == "qdrant.retrieve":
+ db_operation = SemanticConvetion.DB_OPERATION_QUERY
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_QUERY)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_STATEMENT,
+ str(kwargs.get("ids")))
+
+ elif gen_ai_endpoint == "qdrant.scroll":
+ db_operation = SemanticConvetion.DB_OPERATION_QUERY
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_QUERY)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_STATEMENT,
+ str(kwargs.get("scroll_filter")))
+
+ elif gen_ai_endpoint in ["qdrant.search", "qdrant.search_groups"]:
+ db_operation = SemanticConvetion.DB_OPERATION_QUERY
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_QUERY)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_STATEMENT,
+ str(kwargs.get("query_vector")))
+
+ elif gen_ai_endpoint == "qdrant.recommend":
+ db_operation = SemanticConvetion.DB_OPERATION_QUERY
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_QUERY)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_STATEMENT,
+ "positive:" + str(kwargs.get("positive", "")) +
+ " negative:" + str(kwargs.get("negative", "")))
+
+ elif gen_ai_endpoint == "qdrant.upload_points":
+ db_operation = SemanticConvetion.DB_OPERATION_ADD
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_ADD)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
+ object_count(kwargs.get("points")))
+
+ elif gen_ai_endpoint == "qdrant.update_vectors":
+ db_operation = SemanticConvetion.DB_OPERATION_UPDATE
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_UPDATE)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
+ response.status)
+ span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
+ object_count(kwargs.get("points")))
+
+ elif gen_ai_endpoint == "qdrant.overwrite_payload":
+ db_operation = SemanticConvetion.DB_OPERATION_UPDATE
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_UPDATE)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
+ response.status)
+ span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
+ object_count(kwargs.get("points")))
+ span.set_attribute(SemanticConvetion.DB_PAYLOAD_COUNT,
+ object_count(kwargs.get("payload")))
+
+ elif gen_ai_endpoint == "qdrant.upsert":
+ db_operation = SemanticConvetion.DB_OPERATION_UPSERT
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_UPSERT)
+ span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
+ response.status)
+ span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
+ object_count(kwargs.get("points")))
+
+ elif gen_ai_endpoint in ["qdrant.delete_payload", "qdrant.delete_vectors"]:
+ db_operation = SemanticConvetion.DB_OPERATION_DELETE
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_DELETE)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
+ response.status)
+ span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
+ object_count(kwargs.get("points")))
+
+ elif gen_ai_endpoint in ["qdrant.clear_payload", "qdrant.delete"]:
+ db_operation = SemanticConvetion.DB_OPERATION_DELETE
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
+ SemanticConvetion.DB_OPERATION_DELETE)
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
+ kwargs.get("collection_name", ""))
+ span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
+ response.status)
+ span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
+ object_count(kwargs.get("points_selector")))
+
+ span.set_status(Status(StatusCode.OK))
+
+ if disable_metrics is False:
+ attributes = {
+ TELEMETRY_SDK_NAME:
+ "openlit",
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ application_name,
+ SemanticConvetion.DB_SYSTEM:
+ SemanticConvetion.DB_SYSTEM_QDRANT,
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
+ environment,
+ SemanticConvetion.GEN_AI_TYPE:
+ SemanticConvetion.GEN_AI_TYPE_VECTORDB,
+ SemanticConvetion.DB_OPERATION:
+ db_operation
+ }
+
+ metrics["db_requests"].add(1, attributes)
+
+ return response
+
+ except Exception as e:
+ handle_exception(span, e)
+ logger.error("Error in trace creation: %s", e)
+
+ # Return original response
+ return response
+
+ return wrapper
diff --git a/sdk/python/src/openlit/semcov/__init__.py b/sdk/python/src/openlit/semcov/__init__.py
index a9425f58..bd93472d 100644
--- a/sdk/python/src/openlit/semcov/__init__.py
+++ b/sdk/python/src/openlit/semcov/__init__.py
@@ -95,11 +95,13 @@ class SemanticConvetion:
# Vector DB
DB_REQUESTS = "db.total.requests"
DB_SYSTEM = "db.system"
- DB_SYSTEM_CHROMA = "chroma"
- DB_SYSTEM_PINECONE = "pinecone"
DB_COLLECTION_NAME = "db.collection.name"
DB_OPERATION = "db.operation"
+ DB_OPERATION_STATUS = "db.operation.status"
DB_OPERATION_CREATE_INDEX = "create_index"
+ DB_OPERATION_CREATE_COLLECTION = "create_collection"
+ DB_OPERATION_UPDATE_COLLECTION = "update_collection"
+ DB_OPERATION_DELETE_COLLECTION = "delete_collection"
DB_OPERATION_QUERY = "query"
DB_OPERATION_DELETE = "delete"
DB_OPERATION_UPDATE = "update"
@@ -111,6 +113,7 @@ class SemanticConvetion:
DB_VECTOR_COUNT = "db.vector_count"
DB_METADATA_COUNT = "db.metadatas_count"
DB_DOCUMENTS_COUNT = "db.documents_count"
+ DB_PAYLOAD_COUNT = "db.payload_count"
DB_QUERY_LIMIT = "db.limit"
DB_OFFSET = "db.offset"
DB_WHERE_DOCUMENT = "db.where_document"
@@ -118,7 +121,7 @@ class SemanticConvetion:
DB_STATEMENT = "db.statement"
DB_N_RESULTS = "db.n_results"
DB_DELETE_ALL = "db.delete_all"
- DB_INDEX_NAME = "db.create_index.name"
+ DB_INDEX_NAME = "db.index.name"
DB_INDEX_DIMENSION = "db.create_index.dimensions"
DB_INDEX_METRIC = "db.create_index.metric"
DB_INDEX_SPEC = "db.create_index.spec"
@@ -126,3 +129,7 @@ class SemanticConvetion:
DB_UPDATE_METADATA = "db.update.metadata"
DB_UPDATE_VALUES = "db.update.values"
DB_UPDATE_ID = "db.update.id"
+
+ DB_SYSTEM_CHROMA = "chroma"
+ DB_SYSTEM_PINECONE = "pinecone"
+ DB_SYSTEM_QDRANT = "qdrant"
diff --git a/sdk/python/tests/requirements.txt b/sdk/python/tests/requirements.txt
index 370a350c..6eb414eb 100644
--- a/sdk/python/tests/requirements.txt
+++ b/sdk/python/tests/requirements.txt
@@ -18,6 +18,7 @@ groq >= 0.5.0
# Vector DBs
chromadb>=0.4.0
pinecone-client>=2.2.0
+qdrant-client>=1.9.0
# Frameworks
langchain>=0.1.16
diff --git a/sdk/python/tests/test_pinecone.py b/sdk/python/tests/test_pinecone.py
index cab460c3..a1c57bb6 100644
--- a/sdk/python/tests/test_pinecone.py
+++ b/sdk/python/tests/test_pinecone.py
@@ -1,12 +1,12 @@
# pylint: disable=duplicate-code, no-name-in-module
"""
-This module contains tests for ChromaDB functionality using the ChromaDB Python library.
+This module contains tests for Pinecone functionality using the Pinecone Python library.
Tests cover various API endpoints, including upsert, query and delete.
These tests validate integration with OpenLIT.
Environment Variables:
- - PINECONE_API_TOKEN: Cohere API api_key for authentication.
+ - PINECONE_API_TOKEN: Pinecone API api_key for authentication.
Note: Ensure the environment is properly configured for Pinecone access and OpenLIT monitoring
prior to running these tests.
diff --git a/sdk/python/tests/test_qdrant.py b/sdk/python/tests/test_qdrant.py
new file mode 100644
index 00000000..3c0cf05f
--- /dev/null
+++ b/sdk/python/tests/test_qdrant.py
@@ -0,0 +1,224 @@
+# pylint: disable=duplicate-code, no-name-in-module
+"""
+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.
+
+Environment Variables:
+ - QDRANT_URL: Qdrant Cloud Instance URL.
+ - QDRANT_API_TOKEN: Qdrant API api_key for authentication.
+
+Note: Ensure the environment is properly configured for Qdrant access and OpenLIT monitoring
+prior to running these tests.
+"""
+
+import os
+from qdrant_client import QdrantClient, models
+from qdrant_client.models import Distance, VectorParams, PointStruct
+import openlit
+
+# Initialize Qdrant client
+client = QdrantClient(
+ url=os.getenv("QDRANT_URL"),
+ api_key=os.getenv("QDRANT_API_TOKEN"),
+)
+
+# Initialize environment and application name for OpenLIT monitoring
+openlit.init(environment="openlit-testing", application_name="openlit-python-test")
+collecton_name = "openlit-" + os.getenv("GITHUB_JOB")
+
+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.
+
+ - 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.
+
+ 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.
+ """
+
+ # Create a new collection
+ collection = client.create_collection(
+ collection_name=collecton_name,
+ vectors_config=VectorParams(size=4, distance=Distance.DOT),
+ )
+
+ assert collection is True
+
+ # Upsert to the collection
+ upsert = client.upsert(
+ collection_name=collecton_name,
+ wait=True,
+ points=[
+ PointStruct(id=1, vector=[0.05, 0.61, 0.76, 0.74], payload={"city": "Berlin"}),
+ PointStruct(id=2, vector=[0.19, 0.81, 0.75, 0.11], payload={"city": "London"}),
+ PointStruct(id=3, vector=[0.36, 0.55, 0.47, 0.94], payload={"city": "Moscow"}),
+ PointStruct(id=4, vector=[0.18, 0.01, 0.85, 0.80], payload={"city": "New York"}),
+ PointStruct(id=5, vector=[0.24, 0.18, 0.22, 0.44], payload={"city": "Beijing"}),
+ PointStruct(id=6, vector=[0.35, 0.08, 0.11, 0.44], payload={"city": "Mumbai"}),
+ ],
+ )
+
+ assert upsert.status == 'completed'
+
+ # Set Payload to the collection
+ set_payload = client.set_payload(
+ collection_name=collecton_name,
+ payload={
+ "city": "Vienna",
+ },
+ points=[1],
+ )
+ assert set_payload.status == 'completed'
+
+ # Overwrite Payload to the collection
+ overwrite_payload = client.overwrite_payload(
+ collection_name=collecton_name,
+ payload={
+ "city": "Toronto",
+ },
+ points=[1],
+ )
+ assert overwrite_payload.status == 'completed'
+
+ # Clear Payload to the collection
+ clear_payload = client.clear_payload(
+ collection_name=collecton_name,
+ points_selector=[1],
+ )
+ assert clear_payload.status == 'completed'
+
+ # Delete Payload to the collection
+ delete_payload = client.delete_payload(
+ collection_name=collecton_name,
+ keys=["city"],
+ points=[2],
+ )
+ assert delete_payload.status == 'completed'
+
+ # Upload Points to the collection
+ upload_points = client.upload_points(
+ collection_name=collecton_name,
+ points=[
+ models.PointStruct(
+ id=1,
+ payload={
+ "city": "Toronto",
+ },
+ vector=[0.9, 0.1, 0.1, 0.2],
+ )
+ ],
+ max_retries=3,
+ )
+ assert upload_points is None
+
+ # Update Vectors in the collection
+ update_vectors = client.update_vectors(
+ collection_name=collecton_name,
+ points=[
+ models.PointVectors(
+ id=1,
+ vector=[0.9, 0.1, 0.1, 0.2],
+ )
+ ],
+ )
+ assert update_vectors.status == 'completed'
+
+ # Delete Points in the collection
+ delt = client.delete(
+ collection_name=collecton_name,
+ points_selector=models.PointIdsList(
+ points=[2],
+ ),
+ )
+ assert delt.status == 'completed'
+
+ # Retrieve vectors from the collection
+ retrieve = client.retrieve(
+ collection_name=collecton_name,
+ ids=[4],
+ )
+ assert isinstance(retrieve, list)
+
+ # Scroll vectors from the collection
+ scroll = client.scroll(
+ collection_name=collecton_name,
+ scroll_filter=models.Filter(
+ must=[
+ models.FieldCondition(key="city", match=models.MatchValue(value="Toronto")),
+ ]
+ ),
+ limit=1,
+ with_payload=True,
+ with_vectors=False,
+ )
+ assert isinstance(scroll, tuple)
+
+ # Search vectors from the collection
+ search = client.search(
+ collection_name=collecton_name,
+ query_filter=models.Filter(
+ must=[
+ models.FieldCondition(
+ key="city",
+ match=models.MatchValue(
+ value="London",
+ ),
+ )
+ ]
+ ),
+ search_params=models.SearchParams(hnsw_ef=128, exact=False),
+ query_vector=[0.2, 0.1, 0.9, 0.7],
+ limit=3,
+ )
+ assert isinstance(search, list)
+
+ # Search groups from the collection
+ search_groups = client.search_groups(
+ collection_name=collecton_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(
+ collection_name=collecton_name,
+ positive=[1, 3],
+ negative=[4, [0.2, 0.3, 0.4, 0.5]],
+ strategy=models.RecommendStrategy.AVERAGE_VECTOR,
+ query_filter=models.Filter(
+ must=[
+ models.FieldCondition(
+ key="city",
+ match=models.MatchValue(
+ value="London",
+ ),
+ )
+ ]
+ ),
+ limit=3,
+ )
+ assert isinstance(recommend, list)
+
+ # Delete collection
+ del_col = client.delete_collection(
+ collection_name=collecton_name,
+ )
+ assert del_col is True