
Installation
Install both the Netra SDK and Qdrant:pip install netra-sdk qdrant-client
npm install netra-sdk @qdrant/js-client-rest
Usage
Initialize the Netra SDK to automatically trace all Qdrant operations:from netra import Netra
from qdrant_client import QdrantClient
import os
# Initialize Netra
Netra.init(
headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
trace_content=True
)
# Create Qdrant client - automatically traced
client = QdrantClient(
url=os.environ.get('QDRANT_URL'),
api_key=os.environ.get('QDRANT_API_KEY')
)
# Create collection
client.create_collection(
collection_name="my_collection",
vectors_config={"size": 384, "distance": "Cosine"}
)
import { Netra } from "netra-sdk";
import { QdrantClient } from "@qdrant/js-client-rest";
// Initialize Netra
await Netra.init({
headers: `x-api-key=${process.env.NETRA_API_KEY}`,
traceContent: true
});
// Create Qdrant client - automatically traced
const client = new QdrantClient({
url: process.env.QDRANT_URL,
apiKey: process.env.QDRANT_API_KEY
});
// Create collection
await client.createCollection("my_collection", {
vectors: { size: 384, distance: "Cosine" }
});
Collection Operations
Trace collection creation and management:from netra.decorators import task
from netra import SpanWrapper
@task()
def create_collection(client: QdrantClient, name: str, size: int):
span = SpanWrapper("qdrant-create-collection", {
"collection.name": name,
"vector.size": size
}).start()
client.create_collection(
collection_name=name,
vectors_config={"size": size, "distance": "Cosine"}
)
span.end()
import { task, SpanWrapper } from "netra-sdk";
@task()
async function createCollection(client: QdrantClient, name: string, size: number) {
const span = new SpanWrapper("qdrant-create-collection", {
"collection.name": name,
"vector.size": size
}).start();
await client.createCollection(name, {
vectors: { size, distance: "Cosine" }
});
span.end();
}
Point Insertion
Trace point insertions:from netra.decorators import task
from netra import SpanWrapper, ActionModel
@task()
def upsert_points(client: QdrantClient, collection: str, points: list):
span = SpanWrapper("qdrant-upsert", {
"collection": collection,
"points.count": len(points)
}).start()
client.upsert(
collection_name=collection,
points=points
)
span.set_action([ActionModel(
action="upsert",
action_type="database.upsert",
success=True,
affected_records=[{"id": str(p.id)} for p in points],
metadata={"collection": collection}
)])
span.set_attribute("status", "success")
span.end()
import { task, SpanWrapper, ActionModel } from "netra-sdk";
@task()
async function upsertPoints(client: QdrantClient, collection: string, points: any[]) {
const span = new SpanWrapper("qdrant-upsert", {
"collection": collection,
"points.count": points.length
}).start();
await client.upsert(collection, {
points: points
});
span.setAction([{
action: "upsert",
action_type: "database.upsert",
success: true,
affected_records: points.map(p => ({ id: String(p.id) })),
metadata: { collection }
}]);
span.setAttribute("status", "success");
span.end();
}
Vector Search
Trace similarity searches:from netra.decorators import workflow
from netra import SpanWrapper
@workflow()
def search_points(client: QdrantClient, collection: str, query: list[float], limit: int = 5):
span = SpanWrapper("qdrant-search", {
"collection": collection,
"query.size": len(query),
"limit": limit
}).start()
results = client.search(
collection_name=collection,
query_vector=query,
limit=limit
)
span.set_attribute("results.count", len(results))
span.end()
return results
import { workflow, SpanWrapper } from "netra-sdk";
@workflow()
async function searchPoints(client: QdrantClient, collection: string, query: number[], limit: number = 5) {
const span = new SpanWrapper("qdrant-search", {
"collection": collection,
"query.size": query.length,
"limit": limit
}).start();
const results = await client.search(collection, {
vector: query,
limit
});
span.setAttribute("results.count", results.length);
span.end();
return results;
}
Filtering
Trace filtered searches:from netra.decorators import task
from netra import SpanWrapper
import json
@task()
def filter_search(client: QdrantClient, collection: str, query: list[float], filter: dict):
span = SpanWrapper("qdrant-filter-search", {
"collection": collection,
"filter": json.dumps(filter)
}).start()
results = client.search(
collection_name=collection,
query_vector=query,
query_filter=filter,
limit=10
)
span.set_attribute("results.count", len(results))
span.end()
return results
import { task, SpanWrapper } from "netra-sdk";
@task()
async function filterSearch(client: QdrantClient, collection: string, query: number[], filter: any) {
const span = new SpanWrapper("qdrant-filter-search", {
"collection": collection,
"filter": JSON.stringify(filter)
}).start();
const results = await client.search(collection, {
vector: query,
filter,
limit: 10
});
span.setAttribute("results.count", results.length);
span.end();
return results;
}
Next Steps
- Quick Start Guide - Complete setup and configuration
- Decorators - Add custom tracing with
@workflow,@agent, and@taskdecorators - Qdrant Documentation - Official Qdrant documentation
