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 |
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
