## Why ChromaDB?
ChromaDB is an open-source, lightweight vector database that runs locally. It's perfect for development, prototyping, and applications that need offline vector search without cloud dependencies.
### Installation
```bash pip install chromadb ```
### Creating a Client
```python import chromadb
# In-memory (ephemeral) client = chromadb.Client()
# Persistent storage client = chromadb.PersistentClient(path="./chroma_data")
# Client-server mode client = chromadb.HttpClient(host="localhost", port=8000) ```
### Working with Collections
Collections are the primary organizational unit:
```python # Create or get a collection collection = client.get_or_create_collection( name="articles", metadata={"hnsw:space": "cosine"} # Distance metric )
# Add documents (auto-embeds with default model) collection.add( documents=["The sky is blue", "Grass is green", "The sun is yellow"], ids=["doc1", "doc2", "doc3"], metadatas=[{"topic": "sky"}, {"topic": "nature"}, {"topic": "sky"}], ) ```
### Collection Management
- List: `client.list_collections()`
- Get: `client.get_collection("name")`
- Delete: `client.delete_collection("name")`
- Count: `collection.count()` — number of items