Qdrant

Qdrant is an open-source vector similarity search engine with a focus on performance and developer experience. It provides advanced filtering, payload indexing, and support for multiple distance metrics with both on-disk and in-memory storage. Respan gives you full observability over every collection operation, upsert, and query.

Create an account at platform.respan.ai and grab an API key.

Run npx @respan/cli setup to set up with your coding agent.

Setup

1

Install packages

$pip install respan-ai opentelemetry-instrumentation-qdrant qdrant-client
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

RESPAN_API_KEY is used to export traces to Respan.

3

Initialize and run

1from qdrant_client import QdrantClient, models
2from respan import Respan
3from opentelemetry.instrumentation.qdrant import QdrantInstrumentor
4
5respan = Respan(instrumentations=[QdrantInstrumentor()])
6
7client = QdrantClient(url="http://localhost:6333")
8
9client.create_collection(
10 collection_name="documents",
11 vectors_config=models.VectorParams(size=4, distance=models.Distance.COSINE),
12)
13
14client.upsert(
15 collection_name="documents",
16 points=[
17 models.PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4], payload={"topic": "observability"}),
18 models.PointStruct(id=2, vector=[0.5, 0.6, 0.7, 0.8], payload={"topic": "search"}),
19 models.PointStruct(id=3, vector=[0.2, 0.3, 0.4, 0.5], payload={"topic": "embeddings"}),
20 ],
21)
22
23results = client.query_points(
24 collection_name="documents",
25 query=[0.1, 0.2, 0.3, 0.4],
26 limit=2,
27 with_payload=True,
28)
29for point in results.points:
30 print(f"ID: {point.id} (score: {point.score:.4f}) — {point.payload['topic']}")
31
32respan.flush()
4

View your trace

Open the Traces page to see your Qdrant operation spans.

Configuration

ParameterTypeDefaultDescription
api_keystr | NoneNoneFalls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneFalls back to RESPAN_BASE_URL env var.
instrumentationslist[]Plugin instrumentations to activate (e.g. QdrantInstrumentor()).
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment tag (e.g. "production").

Attributes

In Respan()

1from respan import Respan
2from opentelemetry.instrumentation.qdrant import QdrantInstrumentor
3
4respan = Respan(
5 instrumentations=[QdrantInstrumentor()],
6 customer_identifier="user_123",
7 metadata={"service": "rag-api", "version": "1.0.0"},
8)

With propagate_attributes

1from respan import Respan, propagate_attributes
2from opentelemetry.instrumentation.qdrant import QdrantInstrumentor
3
4respan = Respan(instrumentations=[QdrantInstrumentor()])
5
6def search(user_id: str, query_vector):
7 with propagate_attributes(
8 customer_identifier=user_id,
9 thread_identifier="conv_abc_123",
10 metadata={"plan": "pro"},
11 ):
12 return client.query_points(collection_name="documents", query=query_vector, limit=2)
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.