Chroma (tracing)

Chroma is an open-source vector database for building semantic search and Retrieval-Augmented Generation systems.

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 respan-instrumentation-chroma chromadb
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

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()
4

View your trace

Open the Traces page and search for workflow name chroma_query_and_filters_workflow.

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. ChromaInstrumentor()).
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment 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)
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.