Chroma (tracing)
Chroma is an open-source vector database for building semantic search and Retrieval-Augmented Generation systems.
Set up Respan
Create an account at platform.respan.ai and grab an API key .
Paste this into your coding agent:
Help me set up Respan tracing with the Chroma integration.
Follow https://www.respan.ai/docs/integrations/chroma.mdSetup
Install packages
pip install respan-ai respan-instrumentation-chroma chromadbSet environment variables
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"RESPAN_API_KEY is used to export traces to Respan.
Initialize and run
import os
import chromadb
from respan import Respan, workflow
from respan_instrumentation_chroma import ChromaInstrumentor
respan = Respan(
api_key=os.environ["RESPAN_API_KEY"],
instrumentations=[ChromaInstrumentor()],
)
@workflow(name="chroma_query_and_filters_workflow")
def run_chroma_query() -> dict:
client = chromadb.Client()
collection = client.get_or_create_collection("respan_docs")
collection.upsert(
ids=["doc-1"],
embeddings=[[0.1, 0.2, 0.3]],
documents=["Respan traces Chroma operations."],
metadatas=[{"topic": "observability"}],
)
return collection.query(
query_embeddings=[[0.1, 0.2, 0.3]],
n_results=1,
include=["documents", "metadatas", "distances"],
)
print(run_chroma_query())
respan.shutdown()View your trace
Open the Traces page and search for workflow name chroma_query_and_filters_workflow.
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | None | None | Falls back to RESPAN_API_KEY env var. |
base_url | str | None | None | Falls back to RESPAN_BASE_URL env var. |
instrumentations | list | [] | Plugin instrumentations to activate (e.g. ChromaInstrumentor()). |
customer_identifier | str | None | None | Default customer identifier for all spans. |
metadata | dict | None | None | Default metadata attached to all spans. |
environment | str | None | None | Environment tag (e.g. "production"). |
Attributes
In Respan()
from respan import Respan
from respan_instrumentation_chroma import ChromaInstrumentor
respan = Respan(
instrumentations=[ChromaInstrumentor()],
customer_identifier="user_123",
metadata={"service": "chroma-vector-db", "version": "1.0.0"},
)With propagate_attributes
import chromadb
from respan import Respan, propagate_attributes
from respan_instrumentation_chroma import ChromaInstrumentor
respan = Respan(instrumentations=[ChromaInstrumentor()])
def run_query_with_attributes(user_id: str):
with propagate_attributes(
customer_identifier=user_id,
thread_identifier="chroma_thread",
metadata={"index": "respan_docs"},
):
collection = chromadb.Client().get_or_create_collection("respan_docs")
return collection.query(query_embeddings=[[0.1, 0.2, 0.3]], n_results=3)| Attribute | Type | Description |
|---|---|---|
customer_identifier | str | Identifies the end user in Respan analytics. |
thread_identifier | str | Groups related messages into a conversation. |
metadata | dict | Custom key-value pairs. Merged with default metadata. |