GenAIHub
← Back to Technical Section

ChromaDB

Open Source

The open-source embedding database built for simplicity and developer productivity.

What is Chroma?

Chroma is an AI-native open-source vector database designed to streamline the building of LLM applications with state. It makes it easy to add state and long-term memory to your AI applications by providing a simple API to store and retrieve embeddings.

πŸš€ Why Chroma? It prioritizes simplicity and developer experience (DX). It runs in-memory, as a persistent local database, or in client-server mode, making it versatile for prototyping and production.

🧩 Core Concepts

Collection

The fundamental unit of organization. Analogous to a table in SQL or a collection in MongoDB. You store your embeddings and metadata here.

Embeddings

Vector representations of text, images, or audio. Chroma handles embedding generation automatically (using providers like OpenAI or Sentence Transformers) or accepts pre-computed vectors.

Documents

The raw text chunks associated with the embeddings. Chroma stores these alongside vectors for easy retrieval.

Metadata

Key-value pairs (e.g., `{"source": "wiki", "chapter": 1}`) attached to documents to enable powerful filtering during filtered search.

πŸ’» Quick Start

Getting started with Chroma is incredibly simple. Install it with `pip install chromadb`.

import chromadb

# 1. Setup client (in-memory or persistent)
client = chromadb.PersistentClient(path="./chroma_db")

# 2. Get or create a collection
collection = client.get_or_create_collection(
    name="my_documents",
    # metadata={"hnsw:space": "cosine"} # Optional distance function
)

# 3. Add documents (Chroma handles tokenization & embedding automatically by default)
collection.add(
    documents=["This is a document about AI", "This is a document about food"],
    metadatas=[{"category": "tech"}, {"category": "lifestyle"}],
    ids=["id1", "id2"]
)

# 4. Query
results = collection.query(
    query_texts=["artificial intelligence"],
    n_results=1,
    where={, "category": "tech"} # Optional metadata filter
)

print(results)

πŸ—οΈ Common Use Cases

  • RAG (Retrieval Augmented Generation): Retrieving relevant context for LLMs to ground their responses.
  • Semantic Search: Searching documents by meaning rather than just keyword matching.
  • Memory for Agents: Determining state and recalling past interactions for autonomous agents.

Related Topics