chroma-core/chroma · error · ValueError

Config must contain a 'name' field.

Error message

Config must contain a 'name' field.

What it means

config_to_embedding_function(config) deserializes a dict into a live embedding function; the expected shape is {"name": <registered name>, "config": {<params>}}, mirroring what you get from ef.get_config() plus the function name. The very first check requires the top-level "name" key, and raises this ValueError when it is absent — before any registry lookup or schema validation happens.

Source

Thrown at chromadb/utils/embedding_functions/__init__.py:255

    if ef_class is not None:
        return _register(ef_class)  # type: ignore

    return _register


# Function to convert config to embedding function
def config_to_embedding_function(config: Dict[str, Any]) -> EmbeddingFunction:  # type: ignore
    """Convert a config dictionary to an embedding function.

    Args:
        config: The config dictionary.

    Returns:
        The embedding function.
    """
    if "name" not in config:
        raise ValueError("Config must contain a 'name' field.")

    name = config["name"]
    if name not in known_embedding_functions:
        raise ValueError(f"Unsupported embedding function: {name}")

    ef_config = config.get("config", {})

    if known_embedding_functions[name] is None:
        raise ValueError(f"Unsupported embedding function: {name}")

    validate_embedding_function_config_is_safe(name, ef_config)
    return known_embedding_functions[name].build_from_config(ef_config)


__all__ = [
    "EmbeddingFunction",
    "DefaultEmbeddingFunction",
    "CohereEmbeddingFunction",

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Include the registered function name at the top level: config_to_embedding_function({"name": "onnx_mini_lm_l6_v2", "config": {...}}).
  2. Generate configs programmatically: cfg = ef.get_config(); cfg["name"] = ef.name() — this guarantees the key exists.
  3. Validate keys before calling: assert "name" in cfg to fail with your own clearer error.

Example fix

# before: ValueError "Config must contain a 'name' field."
ef = config_to_embedding_function({"model_name": "all-MiniLM-L6-v2"})

# after
ef = config_to_embedding_function({
    "name": "onnx_mini_lm_l6_v2",
    "config": {"model_name": "all-MiniLM-L6-v2"},
})
Defensive patterns

Strategy: validation

Validate before calling

def to_ef_config(cfg: dict) -> dict:
    if "name" not in cfg:
        raise KeyError("embedding function config needs a top-level 'name' key")
    return cfg

from chromadb.utils.embedding_functions import config_to_embedding_function
ef = config_to_embedding_function(to_ef_config(persisted_cfg))

Type guard

def is_valid_ef_config(cfg: object) -> bool:
    return isinstance(cfg, dict) and "name" in cfg and isinstance(cfg["name"], str)

Try / catch

from chromadb.utils.embedding_functions import config_to_embedding_function
try:
    ef = config_to_embedding_function(cfg)
except ValueError as e:
    if "must contain a 'name'" in str(e):
        cfg = {"name": "onnx_mini_lm_l6_v2", "config": cfg}  # wrap inner params
        ef = config_to_embedding_function(cfg)
    else:
        raise

Prevention

When it happens

Trigger: Calling config_to_embedding_function with a dict that lacks "name", e.g. passing only the inner parameter dict {"model_name": ...}, using a typo'd key ("Name", "model", "ef_name"), or double-nesting configs ({"config": {"name": ...}}).

Common situations: Hand-building config dicts instead of round-tripping get_config(); loading persisted collection configs from an older chromadb version or an external store that dropped the name field; passing the "config" sub-dict directly after JSON round-trip.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/f533ae191e63a5e4. Report an issue: GitHub.