/major-ai-skills:chromadbfrom major-ai-skills
Build and operate Chroma collections for RAG: PersistentClient vs HttpClient, embedding-function contracts, metadata/where filters, and dimension-safe upsert/query paths agents routinely break.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Chroma is an embedding-first vector store: documents (or precomputed vectors) land in collections, each locked to a fixed embedding dimension and distance space after first write. Clients run embedded (PersistentClient / ephemeral Client) or client–server (HttpClient / AsyncHttpClient). Agents treat the embedding function + distance metric as a retrieval contract, persist paths intentionally, and never mix models across upsert and query without a new collection rebuild.
┌─────────────────────────────────────────────────────────────┐
│ Chroma retrieval stack │
│ │
│ Clients │
│ ├── Ephemeral Client() — in-memory notebooks/tests │
│ ├── PersistentClient(path) — local embedded + on-disk │
│ └── HttpClient / AsyncHttpClient — remote Chroma server │
│ │
│ Collection contract │
│ ├── EmbeddingFunction (default: all-MiniLM-L6-v2 / 384-d) │
│ ├── Space: hnsw.space = l2 | cosine | ip (immutable) │
│ └── Dimension locked on first embedding write │
│ │
│ Read path │
│ ├── query(query_texts|query_embeddings) + where │
│ ├── where_document ($contains / $regex) │
│ └── get(ids|filters) — no similarity ranking │
└─────────────────────────────────────────────────────────────┘
Use when
@langchain / @llamaindex.Do not use when
PersistentClient path (Chroma is thread-safe, not process-safe for writers) → one writer process or HttpClient + server.documents that get logged → refuse; redact or store secrets outside the index.PersistentClient(path=...) for single-process apps; HttpClient when multiple processes/hosts must share one store.embedding_function + configuration={"hnsw": {"space": "cosine"}} when cosine distance is intended). Store embedding_model / dim in collection metadata.source#chunk_i) so re-ingest is idempotent.where / where_document, not post-hoc Python discard of the full candidate set.l2/ip spaces; prefer cosine when magnitude drift is expected.from __future__ import annotations
import hashlib
import os
from pathlib import Path
import chromadb
from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction
PERSIST = Path(os.environ.get("CHROMA_PATH", "var/chroma"))
MODEL = "text-embedding-3-small"
ef = OpenAIEmbeddingFunction(
api_key=os.environ["OPENAI_API_KEY"], # from env / secret store — never hardcode
model_name=MODEL,
)
client = chromadb.PersistentClient(path=str(PERSIST))
col = client.get_or_create_collection(
name="policies",
embedding_function=ef,
metadata={"embedding_model": MODEL},
configuration={"hnsw": {"space": "cosine"}},
)
def chunk_id(source: str, text: str) -> str:
return hashlib.sha256(f"{source}\n{text}".encode()).hexdigest()[:32]
docs = [
("policies/refund.md", "Annual plans may refund within 14 days of purchase.", "public"),
("policies/refund.md", "Enterprise contracts follow the MSA termination clause.", "internal"),
]
col.upsert(
ids=[chunk_id(src, body) for src, body, _ in docs],
documents=[body for _, body, _ in docs],
metadatas=[{"source": src, "acl": acl} for src, _, acl in docs],
)
hits = col.query(
query_texts=["How long is the refund window?"],
n_results=5,
where={"$and": [{"acl": "public"}, {"source": {"$eq": "policies/refund.md"}}]},
include=["documents", "metadatas", "distances"],
)
print(hits["ids"], hits["distances"], hits["documents"])
HttpClient pattern (shared server):
client = chromadb.HttpClient(host="127.0.0.1", port=8000)
# same get_or_create_collection / upsert / query API
Validation loop:
python -c "import chromadb; c=chromadb.PersistentClient('var/chroma'); print(c.heartbeat()); print(c.list_collections())"
| Signature | Likely cause | Fix path |
|---|---|---|
InvalidDimensionException: Embedding dimension X does not match collection dimensionality Y | Upsert/query model differs from first write (e.g. 1536 vs MiniLM 384) | New collection + full re-index with one EF; align @langchain / @llamaindex embedder dim |
| Empty or irrelevant hits | Wrong persist path / collection name; filter too strict | Verify path, list_collections(), relax where types |
| Distances in tens/hundreds | Unnormalized vectors under default l2 | L2-normalize custom embeddings or create with cosine space |
| Filter returns nothing | Metadata type mismatch ("10" vs 10) or missing keys | Consistent types at upsert; $exists checks via get |
| Corrupt / flaky local DB under load | Multiple processes writing same persist dir | Single writer or migrate to HttpClient + server |
| Quality cliff after “model upgrade” | Changed EF without rebuild | Keep old collection read-only; build policies_v2 and cut over |
| Duplicate chunks | Random UUIDs each ingest | Stable ids + upsert |
| Slow ingest | One-by-one remote embed calls | Batch documents; cache embeddings when reindexing unchanged text |
corpus__model__vN.documents; put structure (source, acl, chunk_index, mtime) in metadatas.get for id lookups; reserve query for similarity.@langchain / @llamaindex — RAG orchestration on top of Chroma@openai-api — common remote embedding provider@huggingface-transformers — local embedding / reranker models@prefect — scheduled reindex / rebuild jobs@docker — run Chroma server beside the appMANDATORY: Lock one embedding function and distance space per collection. Use deterministic ids and
upsert. Persist to an explicit path (or HttpClient). Filter withwhere/where_document. Never embed secrets. On dimension mismatch, rebuild a new collection—do not “fix” vectors in place.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job