> ## 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.

# LanceDB

> Trace LanceDB vector operations with Netra auto-instrumentation. Monitor table queries, vector searches, and indexing operations automatically.

<img src="https://mintcdn.com/netra/IXT7TOAHn4HQhvyF/images/integration-logos/vector-databases/lancedb.png?fit=max&auto=format&n=IXT7TOAHn4HQhvyF&q=85&s=2e8be60ae11a9b31699f1caec3f4467b" alt="LanceDB" width="346" height="80" data-path="images/integration-logos/vector-databases/lancedb.png" />

## Installation

Install both the Netra SDK and LanceDB:

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

  ```bash Typescript theme={null}
  npm install netra-sdk vectordb
  ```
</CodeGroup>

## Usage

Initialize the Netra SDK to automatically trace all LanceDB operations:

<CodeGroup>
  ```python Python theme={null}
  from netra import Netra
  import lancedb
  import os

  # Initialize Netra
  Netra.init(
      headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
      trace_content=True
  )

  # Connect to LanceDB - automatically traced
  db = lancedb.connect("./lancedb")
  table = db.create_table("my_table", [
      {"id": 1, "vector": [0.1, 0.2], "text": "Sample"}
  ])
  ```

  ```typescript Typescript theme={null}
  import { Netra } from "netra-sdk";
  import * as vectordb from "vectordb";

  // Initialize Netra
  await Netra.init({
    headers: `x-api-key=${process.env.NETRA_API_KEY}`,
    traceContent: true
  });

  // Connect to LanceDB - automatically traced
  const db = await vectordb.connect("./lancedb");
  const table = await db.createTable("my_table", [
    { id: 1, vector: [0.1, 0.2], text: "Sample" }
  ]);
  ```
</CodeGroup>

### Table Operations

Trace table creation and management:

<CodeGroup>
  ```python Python theme={null}
  from netra.decorators import task
  from netra import SpanWrapper

  @task()
  def create_table(db, name: str, data: list):
      span = SpanWrapper("lancedb-create-table", {
          "table.name": name,
          "data.count": len(data)
      }).start()
      
      table = db.create_table(name, data)
      span.end()
      
      return table
  ```

  ```typescript Typescript theme={null}
  import { task, SpanWrapper } from "netra-sdk";

  @task()
  async function createTable(db: any, name: string, data: any[]) {
    const span = new SpanWrapper("lancedb-create-table", {
      "table.name": name,
      "data.count": data.length
    }).start();
    
    const table = await db.createTable(name, data);
    span.end();
    
    return table;
  }
  ```
</CodeGroup>

### Vector Insertion

Trace data insertions:

<CodeGroup>
  ```python Python theme={null}
  from netra.decorators import task
  from netra import SpanWrapper, ActionModel

  @task()
  def add_vectors(table, data: list):
      span = SpanWrapper("lancedb-add", {
          "vectors.count": len(data)
      }).start()
      
      table.add(data)
      
      span.set_action([ActionModel(
          action="insert",
          action_type="database.insert",
          success=True,
          affected_records=[{"id": str(d["id"])} for d in data],
          metadata={"table": table.name}
      )])
      span.set_attribute("status", "success")
      span.end()
  ```

  ```typescript Typescript theme={null}
  import { task, SpanWrapper, ActionModel } from "netra-sdk";

  @task()
  async function addVectors(table: any, data: any[]) {
    const span = new SpanWrapper("lancedb-add", {
      "vectors.count": data.length
    }).start();
    
    await table.add(data);
    
    span.setAction([{
      action: "insert",
      action_type: "database.insert",
      success: true,
      affected_records: data.map(d => ({ id: String(d.id) })),
      metadata: { table: table.name }
    }]);
    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_vectors(table, query: list[float], limit: int = 5):
      span = SpanWrapper("lancedb-search", {
          "query.size": len(query),
          "limit": limit
      }).start()
      
      results = table.search(query).limit(limit).to_list()
      
      span.set_attribute("results.count", len(results))
      span.end()
      
      return results
  ```

  ```typescript Typescript theme={null}
  import { workflow, SpanWrapper } from "netra-sdk";

  @workflow()
  async function searchVectors(table: any, query: number[], limit: number = 5) {
    const span = new SpanWrapper("lancedb-search", {
      "query.size": query.length,
      "limit": limit
    }).start();
    
    const results = await table
      .search(query)
      .limit(limit)
      .execute();
    
    span.setAttribute("results.count", results.length);
    span.end();
    
    return results;
  }
  ```
</CodeGroup>

### Filtering

Trace filtered queries:

<CodeGroup>
  ```python Python theme={null}
  from netra.decorators import task
  from netra import SpanWrapper

  @task()
  def filter_search(table, query: list[float], filter: str):
      span = SpanWrapper("lancedb-filter-search", {
          "filter": filter
      }).start()
      
      results = table.search(query).where(filter).limit(10).to_list()
      
      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(table: any, query: number[], filter: string) {
    const span = new SpanWrapper("lancedb-filter-search", {
      "filter": filter
    }).start();
    
    const results = await table
      .search(query)
      .where(filter)
      .limit(10)
      .execute();
    
    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
* [LanceDB Documentation](https://lancedb.github.io/lancedb/) - Official LanceDB documentation
