ChromaDB Embedding Functions
Embedding choice affects retrieval, but inspect chunking and collection design before assuming the model is the problem.
#Default/local baseline
The source describes the all-MiniLM-L6-v2 default as a small local baseline and notes limitations for Chinese tasks. Confirm the default in your installed version and evaluate on your own language/domain examples.
#External provider example
pythonimport os from chromadb.utils import embedding_functions openai_ef = embedding_functions.OpenAIEmbeddingFunction( api_key=os.environ["OPENAI_API_KEY"], model_name="text-embedding-3-small", ) collection = client.get_or_create_collection( name="my_collection", embedding_function=openai_ef )
This invokes a separately configured provider when used; it is not an offline example.
#Language-specific models
The source uses BAAI/bge-small-zh-v1.5 as an example for Chinese retrieval. Distinguish local Sentence Transformers execution from a hosted Hugging Face API embedding function; model location and execution mode are separate choices.
#Custom function interface
pythonfrom chromadb.api.types import Documents, Embeddings class MyEmbeddingFunction: def __call__(self, input: Documents) -> Embeddings: raise NotImplementedError("Return one valid vector per input document")
This is an interface skeleton, not a working embedding implementation. Use the version's required embedding-function protocol and lifecycle methods.
#Do not mix embedding spaces
A collection with stored vectors has a fixed dimension. A 384-dimensional space cannot simply accept 1536-dimensional vectors. Even matching dimensions do not make different model spaces compatible.
Create a separate collection, re-embed the corpus and compare retrieval on a stable evaluation set before switching a production reader. Record the model, dimensions and preprocessing so improvements remain attributable.