$npx -y skills add AlexAI-MCP/hermes-CCC --skill chromaOpen-source embedding database for RAG — store embeddings, vector search, metadata filtering. Simple API, scales from notebook to production.
| 1 | # Chroma |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Use this skill to store embeddings and perform semantic retrieval for RAG systems. |
| 6 | - Prefer Chroma when you want a simple local developer experience with an easy Python API. |
| 7 | - Chroma works well for notebooks, prototypes, local apps, and moderate production deployments. |
| 8 | - It supports metadata filtering, server mode, and pluggable embedding functions. |
| 9 | |
| 10 | ## Install |
| 11 | |
| 12 | ```bash |
| 13 | pip install chromadb sentence-transformers |
| 14 | ``` |
| 15 | |
| 16 | - Add any extra embedding provider packages you need, such as the OpenAI SDK. |
| 17 | |
| 18 | ## Basic Setup |
| 19 | |
| 20 | ```python |
| 21 | import chromadb |
| 22 | |
| 23 | client = chromadb.PersistentClient(path="./chroma_db") |
| 24 | ``` |
| 25 | |
| 26 | - `PersistentClient` stores data on disk. |
| 27 | - It is a good default for local development and single-node setups. |
| 28 | |
| 29 | ## Create a Collection |
| 30 | |
| 31 | ```python |
| 32 | collection = client.create_collection(name="docs") |
| 33 | ``` |
| 34 | |
| 35 | - Use descriptive collection names like `docs`, `papers`, `tickets`, or `kb_chunks`. |
| 36 | - A collection is the logical container for your embeddings and payload metadata. |
| 37 | |
| 38 | ## Add Documents |
| 39 | |
| 40 | - Minimal add call: |
| 41 | |
| 42 | ```python |
| 43 | collection.add( |
| 44 | documents=["Chroma is useful for local RAG.", "Vector search retrieves semantically similar text."], |
| 45 | metadatas=[{"source": "note1"}, {"source": "note2"}], |
| 46 | ids=["doc-1", "doc-2"], |
| 47 | ) |
| 48 | ``` |
| 49 | |
| 50 | - Required arrays must align by index. |
| 51 | - Keep `ids` stable if you plan to update or delete records later. |
| 52 | |
| 53 | ## Query |
| 54 | |
| 55 | ```python |
| 56 | results = collection.query( |
| 57 | query_texts=["How do I store embeddings for RAG?"], |
| 58 | n_results=5, |
| 59 | ) |
| 60 | |
| 61 | print(results["documents"]) |
| 62 | print(results["metadatas"]) |
| 63 | ``` |
| 64 | |
| 65 | - `query_texts=['...']` is the most common path when Chroma is managing embeddings for you. |
| 66 | - Start with `n_results=5` or `10` for most retrieval experiments. |
| 67 | |
| 68 | ## Basic Collection Lifecycle |
| 69 | |
| 70 | - Create collection |
| 71 | - Add documents |
| 72 | - Query for nearest neighbors |
| 73 | - Update documents when content changes |
| 74 | - Delete stale records |
| 75 | |
| 76 | ## Get or Create |
| 77 | |
| 78 | - For idempotent startup flows, prefer `get_or_create_collection`: |
| 79 | |
| 80 | ```python |
| 81 | collection = client.get_or_create_collection(name="docs") |
| 82 | ``` |
| 83 | |
| 84 | - This is helpful in services that initialize storage on boot. |
| 85 | |
| 86 | ## Embedding Functions |
| 87 | |
| 88 | - Chroma supports multiple embedding strategies. |
| 89 | - Common choices include: |
| 90 | - `DefaultEmbeddingFunction` |
| 91 | - `SentenceTransformerEmbeddingFunction` |
| 92 | - `OpenAIEmbeddingFunction` |
| 93 | |
| 94 | ## Default Embedding Function |
| 95 | |
| 96 | ```python |
| 97 | from chromadb.utils.embedding_functions import DefaultEmbeddingFunction |
| 98 | |
| 99 | embedding_fn = DefaultEmbeddingFunction() |
| 100 | collection = client.get_or_create_collection( |
| 101 | name="default-embeddings", |
| 102 | embedding_function=embedding_fn, |
| 103 | ) |
| 104 | ``` |
| 105 | |
| 106 | - The default function is convenient for quick experiments. |
| 107 | - For production, you usually want to control the embedding model explicitly. |
| 108 | |
| 109 | ## SentenceTransformers Embedding Function |
| 110 | |
| 111 | ```python |
| 112 | from chromadb.utils.embedding_functions import SentenceTransformerEmbeddingFunction |
| 113 | |
| 114 | embedding_fn = SentenceTransformerEmbeddingFunction( |
| 115 | model_name="sentence-transformers/all-MiniLM-L6-v2", |
| 116 | ) |
| 117 | |
| 118 | collection = client.get_or_create_collection( |
| 119 | name="st-docs", |
| 120 | embedding_function=embedding_fn, |
| 121 | ) |
| 122 | ``` |
| 123 | |
| 124 | - This is a good choice for local semantic search with no external API dependency. |
| 125 | |
| 126 | ## OpenAI Embedding Function |
| 127 | |
| 128 | ```python |
| 129 | from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction |
| 130 | |
| 131 | embedding_fn = OpenAIEmbeddingFunction( |
| 132 | api_key="YOUR_API_KEY", |
| 133 | model_name="text-embedding-3-small", |
| 134 | ) |
| 135 | |
| 136 | collection = client.get_or_create_collection( |
| 137 | name="openai-docs", |
| 138 | embedding_function=embedding_fn, |
| 139 | ) |
| 140 | ``` |
| 141 | |
| 142 | - Use this when you want consistent hosted embeddings across environments. |
| 143 | - Track model versions because embedding changes can invalidate similarity behavior. |
| 144 | |
| 145 | ## Add Structured Documents |
| 146 | |
| 147 | ```python |
| 148 | collection.add( |
| 149 | documents=[ |
| 150 | "Retrieval augmented generation combines retrieval with generation.", |
| 151 | "Chroma collections can store metadata for filtering.", |
| 152 | ], |
| 153 | metadatas=[ |
| 154 | {"source": "paper1", "section": "intro", "year": 2024}, |
| 155 | {"source": "paper1", "section": "methods", "year": 2024}, |
| 156 | ], |
| 157 | ids=["paper1-intro", "paper1-methods"], |
| 158 | ) |
| 159 | ``` |
| 160 | |
| 161 | - Include source, section, title, author, or timestamp metadata if you need filtered retrieval. |
| 162 | |
| 163 | ## Metadata Filtering |
| 164 | |
| 165 | - Filter by metadata with `where`: |
| 166 | |
| 167 | ```python |
| 168 | results = collection.query( |
| 169 | query_texts=["What does the paper say about filtering?"], |
| 170 | n_results=5, |
| 171 | where={"source": "paper1"}, |
| 172 | ) |
| 173 | ``` |
| 174 | |
| 175 | - Example requested pattern: |
| 176 | - `where={'source': 'paper1'}` |
| 177 | |
| 178 | - Metadata filters are critical for multi-tenant or source-restricted RAG. |
| 179 | |
| 180 | ## Full Text Search |
| 181 | |
| 182 | - Chroma also supports document-side text filtering with ` |