{"record":{"id":"f533ae191e63a5e4","repo":"chroma-core/chroma","slug":"config-must-contain-a-name-field","errorCode":null,"errorMessage":"Config must contain a 'name' field.","messagePattern":"Config must contain a 'name' field\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/__init__.py","lineNumber":255,"sourceCode":"\n    if ef_class is not None:\n        return _register(ef_class)  # type: ignore\n\n    return _register\n\n\n# Function to convert config to embedding function\ndef config_to_embedding_function(config: Dict[str, Any]) -> EmbeddingFunction:  # type: ignore\n    \"\"\"Convert a config dictionary to an embedding function.\n\n    Args:\n        config: The config dictionary.\n\n    Returns:\n        The embedding function.\n    \"\"\"\n    if \"name\" not in config:\n        raise ValueError(\"Config must contain a 'name' field.\")\n\n    name = config[\"name\"]\n    if name not in known_embedding_functions:\n        raise ValueError(f\"Unsupported embedding function: {name}\")\n\n    ef_config = config.get(\"config\", {})\n\n    if known_embedding_functions[name] is None:\n        raise ValueError(f\"Unsupported embedding function: {name}\")\n\n    validate_embedding_function_config_is_safe(name, ef_config)\n    return known_embedding_functions[name].build_from_config(ef_config)\n\n\n__all__ = [\n    \"EmbeddingFunction\",\n    \"DefaultEmbeddingFunction\",\n    \"CohereEmbeddingFunction\",","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/__init__.py#L237-L273","documentation":"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.","triggerScenarios":"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\": ...}}).","commonSituations":"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.","solutions":["Include the registered function name at the top level: config_to_embedding_function({\"name\": \"onnx_mini_lm_l6_v2\", \"config\": {...}}).","Generate configs programmatically: cfg = ef.get_config(); cfg[\"name\"] = ef.name() — this guarantees the key exists.","Validate keys before calling: assert \"name\" in cfg to fail with your own clearer error."],"exampleFix":"# before: ValueError \"Config must contain a 'name' field.\"\nef = config_to_embedding_function({\"model_name\": \"all-MiniLM-L6-v2\"})\n\n# after\nef = config_to_embedding_function({\n    \"name\": \"onnx_mini_lm_l6_v2\",\n    \"config\": {\"model_name\": \"all-MiniLM-L6-v2\"},\n})","handlingStrategy":"validation","validationCode":"def to_ef_config(cfg: dict) -> dict:\n    if \"name\" not in cfg:\n        raise KeyError(\"embedding function config needs a top-level 'name' key\")\n    return cfg\n\nfrom chromadb.utils.embedding_functions import config_to_embedding_function\nef = config_to_embedding_function(to_ef_config(persisted_cfg))","typeGuard":"def is_valid_ef_config(cfg: object) -> bool:\n    return isinstance(cfg, dict) and \"name\" in cfg and isinstance(cfg[\"name\"], str)","tryCatchPattern":"from chromadb.utils.embedding_functions import config_to_embedding_function\ntry:\n    ef = config_to_embedding_function(cfg)\nexcept ValueError as e:\n    if \"must contain a 'name'\" in str(e):\n        cfg = {\"name\": \"onnx_mini_lm_l6_v2\", \"config\": cfg}  # wrap inner params\n        ef = config_to_embedding_function(cfg)\n    else:\n        raise","preventionTips":["Always build configs with ef.get_config() plus cfg[\"name\"] = ef.name() instead of hand-writing dicts.","Schema-validate persisted configs (name: string, config: object) before storing them.","Watch for key drift when configs cross chromadb versions — re-emit them after upgrades."],"tags":["python","embedding-functions","config","validation","deserialization","chromadb"],"backgroundTag":"missing-config-field","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}