> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getnetra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Qdrant

> Trace Qdrant vector operations with Netra auto-instrumentation. Monitor collection searches, point upserts, and payload filters automatically.

<img src="https://mintcdn.com/netra/IXT7TOAHn4HQhvyF/images/integration-logos/vector-databases/qdrant.png?fit=max&auto=format&n=IXT7TOAHn4HQhvyF&q=85&s=104856aee5a2eeba41af0ee9fc4522a0" alt="Qdrant" width="298" height="80" data-path="images/integration-logos/vector-databases/qdrant.png" />

## Installation

Install both the Netra SDK and Qdrant:

<CodeGroup>
  ```bash Python theme={null}
  pip install netra-sdk qdrant-client
  ```

  ```bash Typescript theme={null}
  npm install netra-sdk @qdrant/js-client-rest
  ```
</CodeGroup>

## Usage

Initialize the Netra SDK to automatically trace all Qdrant operations:

<CodeGroup>
  ```python Python theme={null}
  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"}
  )
  ```

  ```typescript Typescript theme={null}
  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" }
  });
  ```
</CodeGroup>

### Collection Operations

Trace collection creation and management:

<CodeGroup>
  ```python Python theme={null}
  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()
  ```

  ```typescript Typescript theme={null}
  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();
  }
  ```
</CodeGroup>

### Point Insertion

Trace point insertions:

<CodeGroup>
  ```python Python theme={null}
  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()
  ```

  ```typescript Typescript theme={null}
  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();
  }
  ```
</CodeGroup>

### Vector Search

Trace similarity searches:

<CodeGroup>
  ```python Python theme={null}
  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
  ```

  ```typescript Typescript theme={null}
  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;
  }
  ```
</CodeGroup>

### Filtering

Trace filtered searches:

<CodeGroup>
  ```python Python theme={null}
  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
  ```

  ```typescript Typescript theme={null}
  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;
  }
  ```
</CodeGroup>

## Next Steps

* [Quick Start Guide](https://docs.getnetra.ai/quick-start/python) - Complete setup and configuration
* [Decorators](https://docs.getnetra.ai/tracing/decorators) - Add custom tracing with `@workflow`, `@agent`, and `@task` decorators
* [Qdrant Documentation](https://qdrant.tech/documentation/) - Official Qdrant documentation
