Skip to main content
Chroma provides native integration with LlamaIndex (formerly GPT Index), enabling you to build powerful data-driven LLM applications.

Installation

pip install chromadb llama-index llama-index-vector-stores-chroma

Basic usage

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext
from llama_index.vector_stores.chroma import ChromaVectorStore
import chromadb

# Load documents
documents = SimpleDirectoryReader("./data").load_data()

# Create Chroma client and collection
chroma_client = chromadb.EphemeralClient()
chroma_collection = chroma_client.create_collection("quickstart")

# Create vector store
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)

# Build index
index = VectorStoreIndex.from_documents(
    documents,
    storage_context=storage_context
)

# Query the index
query_engine = index.as_query_engine()
response = query_engine.query("What is this document about?")
print(response)

Using persistent storage

import chromadb
from llama_index.vector_stores.chroma import ChromaVectorStore

# Create persistent client
chroma_client = chromadb.PersistentClient(path="./chroma_db")

# Get or create collection
chroma_collection = chroma_client.get_or_create_collection("my_collection")

# Create vector store
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)

Using with a remote server

import chromadb
from chromadb.config import Settings

# Connect to remote Chroma server
chroma_client = chromadb.HttpClient(
    host="localhost",
    port=8000,
    settings=Settings(allow_reset=True, anonymized_telemetry=False)
)

chroma_collection = chroma_client.get_or_create_collection("my_collection")
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)

Advanced querying

Metadata filtering

from llama_index.core.vector_stores import MetadataFilters, ExactMatchFilter

# Query with metadata filters
filters = MetadataFilters(
    filters=[ExactMatchFilter(key="source", value="documentation")]
)

query_engine = index.as_query_engine(filters=filters)
response = query_engine.query("Your question")

Custom retrievers

from llama_index.core.retrievers import VectorIndexRetriever

# Create custom retriever
retriever = VectorIndexRetriever(
    index=index,
    similarity_top_k=5,
)

# Retrieve nodes
nodes = retriever.retrieve("query text")

Loading existing collections

import chromadb
from llama_index.core import VectorStoreIndex
from llama_index.vector_stores.chroma import ChromaVectorStore

# Connect to existing collection
chroma_client = chromadb.PersistentClient(path="./chroma_db")
chroma_collection = chroma_client.get_collection("existing_collection")

# Load from vector store
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
index = VectorStoreIndex.from_vector_store(vector_store)

Configuration options

chroma_collection
Collection
required
Chroma collection instance
host
string
Chroma server host (for HttpClient)
port
int
Chroma server port (for HttpClient)
path
string
Path for persistent storage (for PersistentClient)

Use cases

Document indexing

Index large document collections for retrieval

Knowledge graphs

Build knowledge graphs with vector embeddings

Multi-modal search

Search across text, images, and other modalities

Agents

Build LLM agents with memory backed by Chroma

Best practices

  • Use EphemeralClient for testing and prototyping
  • Use PersistentClient for local development with persistence
  • Use HttpClient for production client-server deployments
  • Batch document insertions for better performance
  • Use appropriate chunk sizes for your documents
  • Configure HNSW index parameters for your use case

Resources

LlamaIndex handles document chunking and embedding automatically, making it easy to get started with Chroma.

Build docs developers (and LLMs) love