{"record":{"id":"22db79a168b181b5","repo":"chroma-core/chroma","slug":"the-model-name-cannot-be-changed-after-the-embeddi-22db79","errorCode":null,"errorMessage":"The model name cannot be changed after the embedding function has been initialized.","messagePattern":"The model name cannot be changed after the embedding function has been initialized\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/morph_embedding_function.py","lineNumber":132,"sourceCode":"            api_key_env_var=api_key_env_var,\n            model_name=model_name,\n            api_base=api_base if api_base is not None else \"https://api.morphllm.com/v1\",\n            encoding_format=encoding_format if encoding_format is not None else \"float\",\n        )\n\n    def get_config(self) -> Dict[str, Any]:\n        return {\n            \"api_key_env_var\": self.api_key_env_var,\n            \"model_name\": self.model_name,\n            \"api_base\": self.api_base,\n            \"encoding_format\": self.encoding_format,\n        }\n\n    def validate_config_update(\n        self, old_config: Dict[str, Any], new_config: Dict[str, Any]\n    ) -> None:\n        if \"model_name\" in new_config:\n            raise ValueError(\n                \"The model name cannot be changed after the embedding function has been initialized.\"\n            )\n\n    @staticmethod\n    def validate_config(config: Dict[str, Any]) -> None:\n        \"\"\"\n        Validate the configuration using the JSON schema.\n\n        Args:\n            config: Configuration to validate\n\n        Raises:\n            ValidationError: If the configuration does not match the schema\n        \"\"\"\n        validate_config_schema(config, \"morph\")","sourceCodeStart":114,"sourceCodeEnd":147,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/morph_embedding_function.py#L114-L147","documentation":"MorphEmbeddingFunction.validate_config_update rejects any update config containing 'model_name', raising this ValueError. The embedding model defines the output vector space, so changing it after data has been embedded would corrupt similarity search over existing records — hence immutable. Mutable keys include api_key_env_var, api_base, and encoding_format.","triggerScenarios":"Config-update calls that include model_name (e.g. attempting to move from morph-embedding-v2 to a newer model in place); re-submitting a full get_config() dict as the update payload; automation that diffs whole configs and PUTs everything.","commonSituations":"Model-version upgrades treated as config edits; config round-tripping through admin UIs; debugging sessions pasting get_config() output into update calls.","solutions":["Spin up a new EF/collection with the new model_name and re-embed the data","Remove the key before update: new_config.pop('model_name', None)","Only send changed, mutable keys in update payloads"],"exampleFix":"# before\nnew_cfg = ef.get_config()          # includes \"model_name\"\nnew_cfg[\"model_name\"] = \"morph-embedding-v3\"\nef.validate_config_update(ef.get_config(), new_cfg)  # ValueError\n\n# after\nnew_cfg = {\"encoding_format\": \"base64\", \"api_base\": \"https://api.morphllm.com/v1\"}\nef.validate_config_update(ef.get_config(), new_cfg)  # ok","handlingStrategy":"validation","validationCode":"def safe_morph_update(ef, new_config: dict) -> dict:\n    if \"model_name\" in new_config:\n        raise ValueError(\n            \"model_name is immutable; create a new collection and re-embed\"\n        )\n    ef.validate_config_update(ef.get_config(), new_config)\n    return new_config","typeGuard":null,"tryCatchPattern":"try:\n    ef.validate_config_update(old, new)\nexcept ValueError as e:\n    if \"cannot be changed\" in str(e):\n        new = {k: v for k, v in new.items() if k != \"model_name\"}\n        ef.validate_config_update(old, new)\n    else:\n        raise","preventionTips":["Send only changed mutable keys (api_base, encoding_format, api_key_env_var) in updates","Handle model upgrades as re-index migrations with a fresh collection","Strip immutable keys in a shared update helper instead of relying on API failures"],"tags":["python","configuration","immutable-field","morph","config-update"],"backgroundTag":"immutable-configuration","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}