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

1import os
2
3import chromadb
4from respan import Respan, workflow
5from respan_instrumentation_chroma import ChromaInstrumentor
6
7respan = Respan(
8 api_key=os.environ["RESPAN_API_KEY"],
9 instrumentations=[ChromaInstrumentor()],
10)
11
12
13@workflow(name="chroma_query_and_filters_workflow")
14def run_chroma_query() -> dict:
15 client = chromadb.Client()
16 collection = client.get_or_create_collection("respan_docs")
17
18 collection.upsert(
19 ids=["doc-1"],
20 embeddings=[[0.1, 0.2, 0.3]],
21 documents=["Respan traces Chroma operations."],
22 metadatas=[{"topic": "observability"}],
23 )
24
25 return collection.query(
26 query_embeddings=[[0.1, 0.2, 0.3]],
27 n_results=1,
28 include=["documents", "metadatas", "distances"],
29 )
30
31
32print(run_chroma_query())
33respan.flush()
34respan.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()

1from respan import Respan
2from respan_instrumentation_chroma import ChromaInstrumentor
3
4respan = Respan(
5 instrumentations=[ChromaInstrumentor()],
6 customer_identifier="user_123",
7 metadata={"service": "chroma-vector-db", "version": "1.0.0"},
8)

With propagate_attributes

1import chromadb
2
3from respan import Respan, propagate_attributes
4from respan_instrumentation_chroma import ChromaInstrumentor
5
6respan = Respan(instrumentations=[ChromaInstrumentor()])
7
8
9def run_query_with_attributes(user_id: str):
10 with propagate_attributes(
11 customer_identifier=user_id,
12 thread_identifier="chroma_thread",
13 metadata={"index": "respan_docs"},
14 ):
15 collection = chromadb.Client().get_or_create_collection("respan_docs")
16 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.