Database / ChromaDB Interview Questions
What is ChromaDB's default embedding function and how does it work?
When you create a collection without specifying an embedding function, ChromaDB uses the SentenceTransformerEmbeddingFunction backed by the all-MiniLM-L6-v2 model from the sentence-transformers library. This model is downloaded automatically on first use and cached locally.
import chromadb from chromadb.utils import embedding_functions # Default â uses all-MiniLM-L6-v2 automatically client = chromadb.Client() collection_default = client.create_collection("default_embeddings") # Equivalent explicit usage ef = embedding_functions.SentenceTransformerEmbeddingFunction( model_name="all-MiniLM-L6-v2", # 384-dim, fast, good English quality ) # Using a different Sentence Transformer model ef_large = embedding_functions.SentenceTransformerEmbeddingFunction( model_name="all-mpnet-base-v2", # 768-dim, higher quality, slower ) collection_large = client.create_collection( name="large_model", embedding_function=ef_large, metadata={"hnsw:space": "cosine"}, ) # You can call embedding functions directly to inspect output embed = embedding_functions.SentenceTransformerEmbeddingFunction() vectors = embed(["Hello world", "ChromaDB is great"]) print(len(vectors)) # 2 â one vector per input print(len(vectors[0])) # 384 â dimensions
| Property | Value |
|---|---|
| Model name | all-MiniLM-L6-v2 |
| Output dimensions | 384 |
| Download size | ~80 MB (cached after first use) |
| Library required | sentence-transformers |
| Runs on | CPU (default) or GPU |
| Strength | Fast, good English semantic similarity |
| Limitation | Weaker on non-English, domain-specific text |
More Related questions...