{"record":{"id":"18a2680a8e217949","repo":"chroma-core/chroma","slug":"the-model-cannot-be-changed-after-the-embedding-fu-18a268","errorCode":null,"errorMessage":"The model cannot be changed after the embedding function has been initialized.","messagePattern":"The model cannot be changed after the embedding function has been initialized\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/mistral_embedding_function.py","lineNumber":80,"sourceCode":"    def build_from_config(config: Dict[str, Any]) -> \"EmbeddingFunction[Documents]\":\n        model = config.get(\"model\")\n        api_key_env_var = config.get(\"api_key_env_var\")\n\n        if model is None or api_key_env_var is None:\n            assert False, \"This code should not be reached\"  # this is for type checking\n        return MistralEmbeddingFunction(model=model, api_key_env_var=api_key_env_var)\n\n    def get_config(self) -> Dict[str, Any]:\n        return {\n            \"model\": self.model,\n            \"api_key_env_var\": self.api_key_env_var,\n        }\n\n    def validate_config_update(\n        self, old_config: Dict[str, Any], new_config: Dict[str, Any]\n    ) -> None:\n        if \"model\" in new_config:\n            raise ValueError(\n                \"The model 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        validate_config_schema(config, \"mistral\")\n","sourceCodeStart":62,"sourceCodeEnd":93,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/mistral_embedding_function.py#L62-L93","documentation":"MistralEmbeddingFunction.validate_config_update rejects any config update containing the key 'model', raising this ValueError. The model determines the embedding dimension and vector space (mistral-embed = 1024 dims), so changing it in place would make existing stored vectors incomparable; it is deliberately immutable. Only api_key_env_var is updatable.","triggerScenarios":"Applying a config update with {'model': 'mistral-embed-new'} to an existing EF; round-tripping get_config() (which returns model and api_key_env_var) straight into an update; admin tooling PUTting full config objects.","commonSituations":"Mistral releasing a new embedding model and attempting an in-place upgrade; config-sync scripts echoing stored config back; manually editing serialized EF config JSON.","solutions":["Create a new collection with the new model EF and re-embed your corpus","Strip the immutable key: cfg = {k: v for k, v in new_config.items() if k != 'model'}","Treat model changes as a migration (export documents, new collection, re-import), not a config edit"],"exampleFix":"# before\nupdate = ef.get_config()          # {\"model\": \"mistral-embed\", \"api_key_env_var\": \"MISTRAL_API_KEY\"}\nupdate[\"model\"] = \"mistral-embed-v2\"\nef.validate_config_update(ef.get_config(), update)  # ValueError\n\n# after\nupdate = {\"api_key_env_var\": \"MISTRAL_API_KEY_PROD\"}  # only mutable keys\nef.validate_config_update(ef.get_config(), update)","handlingStrategy":"validation","validationCode":"def safe_mistral_update(ef, new_config: dict) -> dict:\n    if \"model\" in new_config:\n        raise ValueError(\n            \"model is immutable; create a new collection and re-embed instead\"\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\"}\n        ef.validate_config_update(old, new)\n    else:\n        raise","preventionTips":["Model changes = migration: new collection, re-embed, repoint clients","Diff configs and send only mutable changed keys (api_key_env_var is safe)","Never round-trip get_config() directly into an update"],"tags":["python","configuration","immutable-field","mistral","config-update"],"backgroundTag":"immutable-configuration","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}