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 Weaviate?

Weaviate is an open-source vector database that supports semantic search, hybrid search, and generative search with built-in module integrations. Respan auto-instruments Weaviate operations so every object insert, query, and collection operation is captured as a traced span.

Setup

1

Install packages

pip install respan-ai opentelemetry-instrumentation-weaviate weaviate-client python-dotenv
2

Set environment variables

export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export WEAVIATE_URL="YOUR_WEAVIATE_URL"
export WEAVIATE_API_KEY="YOUR_WEAVIATE_API_KEY"
For local development, WEAVIATE_URL and WEAVIATE_API_KEY are not required.
3

Initialize and run

import os
from dotenv import load_dotenv

load_dotenv()

import weaviate
import weaviate.classes.config as wc
from respan import Respan

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

# Connect to Weaviate (local instance)
client = weaviate.connect_to_local()

# Create a collection
collection = client.collections.create(
    name="RespanDemo",
    vectorizer_config=wc.Configure.Vectorizer.none(),
    properties=[
        wc.Property(name="title", data_type=wc.DataType.TEXT),
        wc.Property(name="genre", data_type=wc.DataType.TEXT),
    ],
)

# Add objects with vectors
collection.data.insert_many([
    weaviate.classes.data.DataObject(
        properties={"title": "Inception", "genre": "sci-fi"},
        vector=[0.1] * 1536,
    ),
    weaviate.classes.data.DataObject(
        properties={"title": "The Godfather", "genre": "drama"},
        vector=[0.2] * 1536,
    ),
])

# Query with near_vector
results = collection.query.near_vector(
    near_vector=[0.1] * 1536,
    limit=3,
    return_metadata=weaviate.classes.query.MetadataQuery(distance=True),
)
for obj in results.objects:
    print(f"{obj.properties['title']}: distance={obj.metadata.distance:.4f}")

client.close()
respan.flush()
4

View your trace

Open the Traces page to see your Weaviate spans including collection creation, insert, and query 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 = collection.query.near_vector(
        near_vector=[0.1] * 1536,
        limit=5,
    )
    for obj in results.objects:
        print(obj.properties)
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 collection

import weaviate
import weaviate.classes.config as wc

client = weaviate.connect_to_local()

collection = client.collections.create(
    name="Products",
    vectorizer_config=wc.Configure.Vectorizer.none(),
    properties=[
        wc.Property(name="name", data_type=wc.DataType.TEXT),
        wc.Property(name="category", data_type=wc.DataType.TEXT),
        wc.Property(name="price", data_type=wc.DataType.NUMBER),
    ],
)

Add objects

collection.data.insert_many([
    weaviate.classes.data.DataObject(
        properties={
            "name": "Wireless Headphones",
            "category": "electronics",
            "price": 299.99,
        },
        vector=[0.12, 0.34, 0.56] + [0.0] * 1533,
    ),
    weaviate.classes.data.DataObject(
        properties={
            "name": "Cotton T-Shirt",
            "category": "clothing",
            "price": 49.99,
        },
        vector=[0.78, 0.91, 0.23] + [0.0] * 1533,
    ),
])

Query

import weaviate.classes.query as wq

# Vector search
results = collection.query.near_vector(
    near_vector=[0.12, 0.34, 0.56] + [0.0] * 1533,
    limit=5,
    return_metadata=wq.MetadataQuery(distance=True),
)

for obj in results.objects:
    print(
        f"{obj.properties['name']}: "
        f"category={obj.properties['category']}, "
        f"distance={obj.metadata.distance:.4f}"
    )

# Filtered search
results = collection.query.near_vector(
    near_vector=[0.12, 0.34, 0.56] + [0.0] * 1533,
    limit=5,
    filters=wq.Filter.by_property("category").equal("electronics"),
)

Delete

# Delete by ID
collection.data.delete_by_id(uuid="your-object-uuid")

# Delete by filter
import weaviate.classes.query as wq

collection.data.delete_many(
    where=wq.Filter.by_property("category").equal("electronics")
)