Weaviate

Weaviate is an open-source AI-native vector database that stores both objects and vectors. It supports semantic search, hybrid search (combining BM25 and vector), generative search, and automatic vectorization with built-in ML model integrations. Respan gives you full observability over every collection operation, search, and generative query.

Create an account at platform.respan.ai and grab an API key.

Run npx @respan/cli setup to set up with your coding agent.

Setup

1

Install packages

$pip install respan-ai opentelemetry-instrumentation-weaviate weaviate-client
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

RESPAN_API_KEY is used to export traces to Respan.

3

Initialize and run

1import weaviate
2import weaviate.classes.config as wc
3from respan import Respan
4from opentelemetry.instrumentation.weaviate import WeaviateInstrumentor
5
6respan = Respan(instrumentations=[WeaviateInstrumentor()])
7
8client = weaviate.connect_to_local()
9
10collection = client.collections.create(
11 name="Document",
12 vectorizer_config=wc.Configure.Vectorizer.text2vec_transformers(),
13 properties=[
14 wc.Property(name="title", data_type=wc.DataType.TEXT),
15 wc.Property(name="content", data_type=wc.DataType.TEXT),
16 ],
17)
18
19collection.data.insert_many([
20 {"title": "AI Observability", "content": "Respan provides tracing for AI applications."},
21 {"title": "Vector Search", "content": "Weaviate supports semantic and hybrid search."},
22 {"title": "Embeddings", "content": "Embeddings capture semantic meaning as vectors."},
23])
24
25results = collection.query.near_text(query="How does AI tracing work?", limit=2)
26for obj in results.objects:
27 print(f"{obj.properties['title']}: {obj.properties['content']}")
28
29client.close()
30respan.flush()
4

View your trace

Open the Traces page to see your Weaviate operation spans with searches, hybrid queries, and generative results.

Configuration

ParameterTypeDefaultDescription
api_keystr | NoneNoneFalls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneFalls back to RESPAN_BASE_URL env var.
instrumentationslist[]Plugin instrumentations to activate (e.g. WeaviateInstrumentor()).
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment tag (e.g. "production").

Attributes

In Respan()

1from respan import Respan
2from opentelemetry.instrumentation.weaviate import WeaviateInstrumentor
3
4respan = Respan(
5 instrumentations=[WeaviateInstrumentor()],
6 customer_identifier="user_123",
7 metadata={"service": "rag-api", "version": "1.0.0"},
8)

With propagate_attributes

1from respan import Respan, propagate_attributes
2from opentelemetry.instrumentation.weaviate import WeaviateInstrumentor
3
4respan = Respan(instrumentations=[WeaviateInstrumentor()])
5
6def search(user_id: str, query: str):
7 with propagate_attributes(
8 customer_identifier=user_id,
9 thread_identifier="conv_abc_123",
10 metadata={"plan": "pro"},
11 ):
12 return collection.query.near_text(query=query, limit=2)
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.