Chroma’s default embedding function powered by Sentence Transformers
Chroma uses Sentence Transformers as its default embedding function, providing high-quality embeddings out of the box with no additional configuration.
Chroma uses the all-MiniLM-L6-v2 model by default:
Dimensions: 384
Speed: Very fast
Quality: Excellent for most use cases
Size: ~80MB
Language: English (trained on English data)
import chromadb# Uses default Sentence Transformer automaticallyclient = chromadb.Client()collection = client.create_collection(name="my_collection")# No need to specify embedding functioncollection.add( documents=["This is a document", "This is another document"], ids=["doc1", "doc2"])
from chromadb.utils.embedding_functions import DefaultEmbeddingFunction# Explicitly use the default functionembedding_function = DefaultEmbeddingFunction()collection = client.create_collection( name="my_collection", embedding_function=embedding_function)
# Embedding speed (approximate on CPU)# Single document: ~10ms# Batch of 100: ~200ms# Batch of 1000: ~1.5simport timeimport chromadbclient = chromadb.Client()collection = client.create_collection("benchmark")# Benchmarkstart = time.time()collection.add( documents=[f"Document {i}" for i in range(100)], ids=[f"id{i}" for i in range(100)])end = time.time()print(f"Time for 100 documents: {end - start:.2f}s")
While Sentence Transformers is the default, you can easily switch to other embedding functions:
OpenAI
Cohere
Custom Sentence Transformer
from chromadb.utils.embedding_functions import OpenAIEmbeddingFunctionembedding_function = OpenAIEmbeddingFunction( api_key="your-key", model_name="text-embedding-3-small")
from chromadb.utils.embedding_functions import CohereEmbeddingFunctionembedding_function = CohereEmbeddingFunction( api_key="your-key", model_name="embed-english-v3.0")
from chromadb.utils.embedding_functions import SentenceTransformerEmbeddingFunctionembedding_function = SentenceTransformerEmbeddingFunction( model_name="all-mpnet-base-v2" # Different model)
import chromadbfrom chromadb.utils.embedding_functions import ONNXMiniLM_L6_V2# This will download the model if not cachedembedding_function = ONNXMiniLM_L6_V2()# Now subsequent uses will be instantclient = chromadb.Client()collection = client.create_collection( name="my_collection", embedding_function=embedding_function)
# Manually download modelfrom sentence_transformers import SentenceTransformermodel = SentenceTransformer('all-MiniLM-L6-v2')# Model is now cached for Chroma to use
Slow first run
The first embedding operation downloads the model (~80MB). Subsequent operations are fast. Consider pre-downloading in your deployment process.
Out of memory errors
Process documents in smaller batches:
batch_size = 50 # Reduce if neededfor i in range(0, len(documents), batch_size): collection.add( documents=documents[i:i+batch_size], ids=ids[i:i+batch_size] )
The default Sentence Transformer model provides excellent performance for most use cases. You only need to switch to a different embedding function if you have specific requirements like multilingual support or domain-specific embeddings.