Milvus

Milvus is an open-source vector database built for scalable similarity search. It supports billion-scale vector data, multiple index types (IVF, HNSW, DiskANN), and hybrid search combining vector similarity with scalar filtering. Respan gives you full observability over every collection operation, search, and insert.

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-milvus pymilvus
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 pymilvus import MilvusClient
2from respan import Respan
3from opentelemetry.instrumentation.milvus import MilvusInstrumentor
4
5respan = Respan(instrumentations=[MilvusInstrumentor()])
6
7client = MilvusClient(uri="http://localhost:19530")
8
9client.create_collection(collection_name="documents", dimension=4)
10
11data = [
12 {"id": 1, "vector": [0.1, 0.2, 0.3, 0.4], "text": "AI observability with Respan"},
13 {"id": 2, "vector": [0.5, 0.6, 0.7, 0.8], "text": "Vector similarity search"},
14 {"id": 3, "vector": [0.2, 0.3, 0.4, 0.5], "text": "Scalable vector indexing"},
15]
16client.insert(collection_name="documents", data=data)
17
18results = client.search(
19 collection_name="documents",
20 data=[[0.1, 0.2, 0.3, 0.4]],
21 limit=2,
22 output_fields=["text"],
23)
24for hits in results:
25 for hit in hits:
26 print(f"{hit['entity']['text']} (distance: {hit['distance']:.4f})")
27
28respan.flush()
4

View your trace

Open the Traces page to see your Milvus 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. MilvusInstrumentor()).
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.milvus import MilvusInstrumentor
3
4respan = Respan(
5 instrumentations=[MilvusInstrumentor()],
6 customer_identifier="user_123",
7 metadata={"service": "vector-api", "version": "1.0.0"},
8)

With propagate_attributes

1from respan import Respan, propagate_attributes
2from opentelemetry.instrumentation.milvus import MilvusInstrumentor
3
4respan = Respan(instrumentations=[MilvusInstrumentor()])
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.search(collection_name="documents", data=[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.