Database / ChromaDB Interview Questions
How do you control what data ChromaDB returns in query and get results using include?
Both query() and get() accept an include parameter — a list of strings specifying which fields to return. Omitting fields you don't need reduces network payload and memory, which matters for large result sets.
import chromadb client = chromadb.Client() col = client.create_collection("demo") col.add( documents=["Alpha document", "Beta document", "Gamma document"], metadatas=[{"tag": "a"}, {"tag": "b"}, {"tag": "c"}], ids=["id1", "id2", "id3"], ) # Default include: documents, metadatas, distances (for query) # Default include for get(): documents, metadatas (no distances) results = col.query(query_texts=["document"], n_results=2) print(results.keys()) # dict_keys(["ids", "distances", "metadatas", "embeddings", "documents", "uris", "data"]) # embeddings, uris, data are None by default # Only return IDs and distances â smallest possible response results = col.query( query_texts=["alpha"], n_results=2, include=["distances"], # ids are always returned ) print(results["documents"]) # None print(results["distances"]) # [[0.05, 0.72]] # Include raw embedding vectors (large! use only when needed) results = col.query( query_texts=["beta"], n_results=1, include=["documents", "metadatas", "distances", "embeddings"], ) print(len(results["embeddings"][0][0])) # 384 floats per vector # get() include â embeddings must be explicitly requested all_data = col.get( include=["documents", "metadatas", "embeddings"], ) print(len(all_data["embeddings"])) # 3 # get() without include â minimal response ids_only = col.get() print(ids_only["ids"]) # ["id1", "id2", "id3"] print(ids_only["documents"]) # ["Alpha...", "Beta...", "Gamma..."]
| Value | Returned in query()? | Returned in get()? |
|---|---|---|
| documents | Yes (default) | Yes (default) |
| metadatas | Yes (default) | Yes (default) |
| distances | Yes (default) | No — not applicable |
| embeddings | No (must request) | No (must request) |
| uris | No (multimodal only) | No (multimodal only) |
| data | No (multimodal only) | No (multimodal only) |
More Related questions...