ChromaDB Cheatsheet
ChromaDB is an open-source embedded vector database designed for LLM applications. Supports semantic search, metadata filtering, document management, and persistent storage. Runs as a standalone server or embedded in Python — the top choice for RAG applications.
Quick Start
``bash
# Install
pip install chromadb
# Start server chroma run --path ./chroma_data --port 8000
# Python client (from another terminal)
python -c "
import chromadb
client = chromadb.HttpClient(host='localhost', port=8000)
print(client.heartbeat()) # should print a timestamp
"
`
Collections
Collections are like tables in a traditional database. Each collection has a name and optional embedding function. Default is sentence-transformers all-MiniLM-L6-v2. Create, list, get, and delete collections via the client.
CRUD Operations
Add documents with collection.add(documents, metadatas, ids). Query with collection.query(query_texts, n_results, where). Update with collection.update(ids, documents). Delete with collection.delete(ids). Get by ID with collection.get(ids).
Metadata Filtering
Filter search results using the where parameter. Supports comparison operators ($gt, $lt, $gte, $lte, $ne, $eq) and logical operators ($and, $or). Metadata can be any JSON-serializable dict.
API Access
ChromaDB serves a REST API at /api/v1/. You can use curl or HTTP clients directly without the Python library: curl http://localhost:8000/api/v1/collections`.
Startup & Modes(12)
| Command | Level | ||
|---|---|---|---|
chroma --helpShow Chroma CLI help | Basic | chroma --help | |
pip install chromadbInstall ChromaDB | Basic | pip install chromadb | |
python import chromadbCreate Chroma client in Python | Intermediate | python -c 'import chromadb; client = chromadb.HttpClient(host="localhost", port=8000); print(client.heartbeat())'
| |
create collectionCreate a collection | Intermediate | python -c 'import chromadb; c = chromadb.HttpClient().create_collection(name="my_docs"); print(c.count())'
| |
collection addAdd documents to a collection | Intermediate | python -c 'import chromadb; c = chromadb.HttpClient().get_collection("my_docs"); c.add(documents=["Hello world"], ids=["doc1"])'
| |
collection queryQuery a collection (semantic search) | Intermediate | python -c 'import chromadb; c = chromadb.HttpClient().get_collection("my_docs"); print(c.query(query_texts=["Hello"], n_results=5))'
| |
collection add with metadataAdd documents with metadata | Intermediate | python -c 'import chromadb; c = chromadb.HttpClient().get_collection("my_docs"); c.add(documents=["Doc1"], metadatas=[{"source":"web"}], ids=["1"])'
| |
collection deleteDelete documents from collection | Intermediate | python -c 'import chromadb; c = chromadb.HttpClient().get_collection("my_docs"); c.delete(ids=["doc1"])'
| |
collection getGet documents by IDs | Intermediate | python -c 'import chromadb; c = chromadb.HttpClient().get_collection("my_docs"); print(c.get(ids=["doc1"]))'
| |
collection updateUpdate documents in collection | Intermediate | python -c 'import chromadb; c = chromadb.HttpClient().get_collection("my_docs"); c.update(ids=["doc1"], documents=["Updated text"])'
| |
list collectionsList all collections | Basic | python -c 'import chromadb; print(chromadb.HttpClient().list_collections())' | |
delete collectionDelete a collection | Intermediate | python -c 'import chromadb; chromadb.HttpClient().delete_collection("my_docs")' |
ai-server(5)
| Command | Level | ||
|---|---|---|---|
chroma runStart Chroma server | Basic | chroma run --path ./my_chroma_data | |
chroma run --pathSpecify data persistence path | Basic | chroma run --path /data/chroma | |
chroma run --hostSpecify bind host address | Basic | chroma run --host 0.0.0.0 --port 8000 | |
chroma run --portSpecify server port (default 8000) | Basic | chroma run --path ./data --port 8080 | |
curl collections APIGet collection list via API | Basic | curl -s http://localhost:8000/api/v1/collections |