The add contract
collection.add() takes parallel lists: ids, documents, metadatas, optionally embeddings. If you pass documents without embeddings, Chroma calls its default embedding function (which is not what you want in production — always control the model yourself).
The query contract
collection.query() takes query_embeddings (or query_texts) and returns the top-k nearest. The result includes ids, documents, metadatas, and distances. Distances are cosine DISTANCE, not similarity — 0 = identical, 2 = opposite.
Three result modes you should know
- Default — returns ids, distances, and embeddings. Pass
include=['documents','metadatas']to get text/metadata back. - Embedding-only — useful for re-ranking with a separate model.
- Where-filtered — pre-filter by metadata before ranking.