microsoft/autogen · error · ValueError
Failed to create custom embedding function. Error: {e}
Error message
Failed to create custom embedding function. Error: {e} What it means
CustomEmbeddingFunctionConfig lets you supply an arbitrary callable plus params; it is invoked as config.function(**config.params) inside a try/except, and any exception it raises is re-raised as ValueError with the original error chained. This reports failures in user-supplied embedding factory code.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py:233
raise ImportError(
f"Failed to create SentenceTransformer embedding function with model '{config.model_name}'. "
f"Ensure sentence-transformers is installed and the model is available. Error: {e}"
) from e
elif isinstance(config, OpenAIEmbeddingFunctionConfig):
try:
return embedding_functions.OpenAIEmbeddingFunction(api_key=config.api_key, model_name=config.model_name)
except Exception as e:
raise ImportError(
f"Failed to create OpenAI embedding function with model '{config.model_name}'. "
f"Ensure openai is installed and API key is valid. Error: {e}"
) from e
elif isinstance(config, CustomEmbeddingFunctionConfig):
try:
return config.function(**config.params)
except Exception as e:
raise ValueError(f"Failed to create custom embedding function. Error: {e}") from e
else:
raise ValueError(f"Unsupported embedding function config type: {type(config)}")
def _ensure_initialized(self) -> None:
"""Ensure ChromaDB client and collection are initialized."""
if self._client is None:
try:
from chromadb.config import Settings
settings = Settings(allow_reset=self._config.allow_reset)
if isinstance(self._config, PersistentChromaDBVectorMemoryConfig):
self._client = PersistentClient(
path=self._config.persistence_path,
settings=settings,
tenant=self._config.tenant,
database=self._config.database,View on GitHub (pinned to 027ecf0a37)
Solutions
- Read the trailing 'Error: {e}' — it carries the exception your function raised.
- Make the params dict keys exactly match the callable's keyword parameter names.
- Test the callable standalone: config.function(**config.params) in a REPL before wiring it into the memory.
- Fix the root cause inside your custom embedding function (missing file, bad device, etc.).
Example fix
# before
def make_embedder(model_path): ...
config = CustomEmbeddingFunctionConfig(function=make_embedder, params={"path": "model.bin"})
# after
config = CustomEmbeddingFunctionConfig(function=make_embedder, params={"model_path": "model.bin"}) Defensive patterns
Strategy: try-catch
Validate before calling
# smoke-test the factory before wiring it into memory
try:
fn = config.function(**config.params)
except Exception as e:
raise RuntimeError(f"custom embedding factory broken: {e}") from e Type guard
import inspect
def params_match_signature(func, params: dict) -> bool:
sig = inspect.signature(func)
try:
sig.bind(**params)
return True
except TypeError:
return False Try / catch
try:
memory = ChromaDBVectorMemory(config=config)
await memory.update_context(ctx)
except ValueError as e:
if "custom embedding function" in str(e):
# inspect e.__cause__ for the factory's own error and fix params/function
raise
raise Prevention
- Bind params against the callable's signature with inspect.signature before use.
- Unit-test custom embedding factories standalone before integrating.
When it happens
Trigger: Configuring CustomEmbeddingFunctionConfig whose function raises on invocation: mismatched params (unexpected keyword), missing required args, or the function itself erroring (e.g. loading a local model that does not exist).
Common situations: Param names in the config not matching the callable signature; callables expecting positional args; custom embedding code failing at construction (missing model files, wrong device).
Related errors
- Failed to create SentenceTransformer embedding function with
- Failed to create OpenAI embedding function with model '{conf
- Unsupported embedding function config type: {type(config)}
- Unsupported config type: {type(self._config)}
- Authentication failed
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/435fa71076db130f.
Report an issue: GitHub.