Skip to main content
  1. Sign up — Create an account at platform.respan.ai
  2. Create an API key — Generate one on the API keys page
  3. Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page
Add the Docs MCP to your AI coding tool to get help building with Respan. No API key needed.
{
  "mcpServers": {
    "respan-docs": {
      "url": "https://docs.respan.ai/mcp"
    }
  }
}

What is LanceDB?

LanceDB is an open-source, serverless vector database built on the Lance columnar format. It runs embedded (no server needed) and supports disk-based indexing for cost-efficient similarity search. Respan auto-instruments LanceDB operations so every add, search, and table operation is captured as a traced span.

Setup

1

Install packages

pip install respan-ai opentelemetry-instrumentation-lancedb lancedb python-dotenv
2

Set environment variables

export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
LanceDB runs locally by default, so no additional credentials are needed.
3

Initialize and run

import os
from dotenv import load_dotenv

load_dotenv()

import lancedb
from respan import Respan

# Initialize Respan with auto-instrumentation
respan = Respan(is_auto_instrument=True)

# Connect to a local LanceDB database
db = lancedb.connect("./lancedb")

# Create a table with vector data
data = [
    {"id": "doc_1", "text": "Introduction to machine learning", "vector": [0.1] * 1536},
    {"id": "doc_2", "text": "Vector databases explained", "vector": [0.2] * 1536},
    {"id": "doc_3", "text": "Building search engines", "vector": [0.3] * 1536},
]
table = db.create_table("respan_demo", data=data, mode="overwrite")

# Search
results = table.search([0.1] * 1536).limit(3).to_pandas()
print(results)

respan.flush()
4

View your trace

Open the Traces page to see your LanceDB spans including table creation, add, and search operations.

Configuration

ParameterTypeDefaultDescription
api_keystr | NoneNoneFalls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneFalls back to RESPAN_BASE_URL env var.
is_auto_instrumentbool | NoneFalseAuto-discover installed instrumentors. Required for Traceloop instrumentors.
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment tag (e.g. "production").

Attributes

Attach customer identifiers, thread IDs, and metadata to spans.

In Respan()

Set defaults at initialization — these apply to all spans.
from respan import Respan

respan = Respan(
    is_auto_instrument=True,
    customer_identifier="user_123",
    metadata={"service": "search-api", "version": "1.0.0"},
)

With propagate_attributes

Override per-request using a context manager.
from respan import Respan, propagate_attributes

respan = Respan(is_auto_instrument=True)

with propagate_attributes(
    customer_identifier="user_456",
    thread_identifier="session_abc",
    metadata={"plan": "enterprise"},
):
    results = table.search([0.1] * 1536).limit(5).to_pandas()
    print(results)
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.

Examples

Create table

import lancedb

db = lancedb.connect("./lancedb")

data = [
    {
        "id": "product_001",
        "name": "Wireless Headphones",
        "category": "electronics",
        "price": 299.99,
        "vector": [0.12, 0.34, 0.56] + [0.0] * 1533,
    },
    {
        "id": "product_002",
        "name": "Cotton T-Shirt",
        "category": "clothing",
        "price": 49.99,
        "vector": [0.78, 0.91, 0.23] + [0.0] * 1533,
    },
]

table = db.create_table("products", data=data, mode="overwrite")

Add data

table.add([
    {
        "id": "product_003",
        "name": "Running Shoes",
        "category": "footwear",
        "price": 129.99,
        "vector": [0.45, 0.67, 0.89] + [0.0] * 1533,
    },
])
import pandas as pd

# Basic vector search
results = table.search([0.12, 0.34, 0.56] + [0.0] * 1533).limit(5).to_pandas()

for _, row in results.iterrows():
    print(f"{row['name']}: category={row['category']}, distance={row['_distance']:.4f}")

# Filtered search
results = (
    table.search([0.12, 0.34, 0.56] + [0.0] * 1533)
    .where("category = 'electronics'")
    .limit(5)
    .to_pandas()
)

Delete

# Delete by filter
table.delete("category = 'electronics'")

# Delete by ID
table.delete("id = 'product_001'")