High severity beginner · Fix: 2-5 min

ValueError

ValueError: embedding_function not set in ChromaDB client

What this error means
ChromaDB raises a ValueError when the embedding_function is not configured before adding or querying vectors.

Stack trace

traceback
ValueError: embedding_function not set
  File "/usr/local/lib/python3.9/site-packages/chromadb/api/client.py", line 123, in add
    raise ValueError("embedding_function not set")
  File "app.py", line 45, in main
    collection.add(documents=docs)  # triggers error
QUICK FIX
Set the embedding_function parameter when creating or loading your ChromaDB collection to a valid embedding callable.

Why it happens

ChromaDB requires an embedding function to convert text into vector embeddings before storing or querying. If you create a collection without setting this embedding_function, operations that depend on embeddings will fail with this error.

Detection

Check if your ChromaDB collection instance has an embedding_function attribute set before calling add or query methods; log or assert this during initialization.

Causes & fixes

1

Embedding function was never assigned to the ChromaDB collection instance.

✓ Fix

Assign a valid embedding function (e.g., from OpenAI or HuggingFace) to the collection's embedding_function attribute before adding or querying.

2

Using ChromaDB client without passing embedding_function parameter during collection creation.

✓ Fix

Pass embedding_function explicitly when creating or loading the collection, e.g., collection = client.get_collection(name='mycol', embedding_function=my_embed_func).

3

Embedding function variable is None or improperly initialized.

✓ Fix

Ensure the embedding function is properly instantiated and not None before assigning it to the collection.

Code: broken vs fixed

Broken - triggers the error
python
from chromadb import Client
client = Client()
collection = client.get_collection(name="test_collection")
collection.add(documents=["Hello world"])  # triggers ValueError: embedding_function not set
Fixed - works correctly
python
import os
from chromadb import Client
from openai import OpenAI

os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "your_api_key_here")

client = Client()

# Define embedding function using OpenAI embeddings
embedding_function = lambda texts: OpenAI(api_key=os.environ["OPENAI_API_KEY"]).embeddings.create(input=texts).data

collection = client.get_collection(name="test_collection", embedding_function=embedding_function)
collection.add(documents=["Hello world"])  # fixed: embedding_function set
print("Added documents successfully.")
Added a valid embedding_function parameter when creating the collection so ChromaDB can generate embeddings for documents.

Workaround

Wrap calls to add or query in try/except catching ValueError; if embedding_function not set, manually generate embeddings externally and add vectors directly.

Prevention

Always initialize ChromaDB collections with a valid embedding_function before any vector operations to avoid runtime errors.

Python 3.9+ · chromadb >=0.3.0 · tested on 0.4.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.