Skip to main content

🧬 Embeddings

Embeddings are the A.I-native way to represent any kind of data, making them the perfect fit for working with all kinds of A.I-powered tools and algorithms. They can represent text, images, and soon audio and video. There are many options for creating embeddings, whether locally using an installed library, or by calling an API.

Chroma provides lightweight wrappers around popular embedding providers, making it easy to use them in your apps. You can set an embedding function when you create a Chroma collection, which will be used automatically, or you can call them directly yourself.

PythonJS
OpenAI
Google Generative AI
Cohere
Google PaLM
Hugging Face
Instructor
Hugging Face Embedding Server
Jina AI

We welcome pull requests to add new Embedding Functions to the community.


Default: all-MiniLM-L6-v2

By default, Chroma uses the Sentence Transformers all-MiniLM-L6-v2 model to create embeddings. This embedding model can create sentence and document embeddings that can be used for a wide variety of tasks. This embedding function runs locally on your machine, and may require you download the model files (this will happen automatically).

from chromadb.utils import embedding_functions
default_ef = embedding_functions.DefaultEmbeddingFunction()
note

Embedding functions can linked to a collection, which are used whenever you call add, update, upsert or query. You can also be use them directly which can be handy for debugging.

val = default_ef(["foo"])

-> [[0.05035809800028801, 0.0626462921500206, -0.061827320605516434...]]


Custom Embedding Functions

Select a language

You can create your own embedding function to use with Chroma, it just needs to implement the EmbeddingFunction protocol. The .generate method in a class is strictly all you need.

class MyEmbeddingFunction {
private api_key: string;

constructor(api_key: string) {
this.api_key = api_key;
}

public async generate(texts: string[]): Promise<number[][]> {
// do things to turn texts into embeddings with an api_key perhaps
return embeddings;
}
}