{"record":{"id":"ea5f12efab2d6df1","repo":"chroma-core/chroma","slug":"the-model-name-cannot-be-changed-after-the-embeddi-ea5f12","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":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/cloudflare_workers_ai_embedding_function.py","lineNumber":144,"sourceCode":"            api_key_env_var=api_key_env_var,\n            model_name=model_name,\n            account_id=account_id,\n            gateway_id=gateway_id,\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            \"account_id\": self.account_id,\n            \"gateway_id\": self.gateway_id,\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, \"cloudflare_workers_ai\")\n","sourceCodeStart":126,"sourceCodeEnd":160,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/cloudflare_workers_ai_embedding_function.py#L126-L160","documentation":"Embedding-function configs are patchable except for fields that would silently change the vector space. For CloudflareWorkersAIEmbeddingFunction, model_name is such a field: validate_config_update rejects any new_config that contains 'model_name', even if the value is unchanged. Embeddings from two different models are not comparable, so a model swap requires a new collection.","triggerScenarios":"A config update that calls validate_config_update(old, new) with 'model_name' present in new - most commonly because the full get_config() dict was echoed back with one other field (api_key_env_var, account_id, gateway_id) edited.","commonSituations":"Round-tripping configs: users fetch get_config(), mutate a key, and pass the whole dict to the update API, forgetting that model_name rides along.","solutions":["Send a minimal patch dict containing only the keys you actually change, with 'model_name' removed.","If you need a different model, create a new collection with a fresh embedding function and re-embed your documents.","Construct the update payload explicitly (e.g. {'api_key_env_var': ...}) instead of copying get_config() output."],"exampleFix":"# before\ncfg = ef.get_config()\ncfg['api_key_env_var'] = 'CLOUDFLARE_API_KEY_PROD'\nef.validate_config_update(old, cfg)  # ValueError: model_name cannot change\n\n# after\npatch = {'api_key_env_var': 'CLOUDFLARE_API_KEY_PROD'}  # changed keys only\nef.validate_config_update(old, patch)","handlingStrategy":"validation","validationCode":"patch = {k: v for k, v in new_cfg.items() if k != 'model_name'}\nef.validate_config_update(old_cfg, patch)","typeGuard":null,"tryCatchPattern":"try:\n    ef.validate_config_update(old_cfg, new_cfg)\nexcept ValueError as e:\n    if 'model name cannot be changed' in str(e):\n        new_cfg.pop('model_name', None)  # retry with immutable fields stripped\n        ef.validate_config_update(old_cfg, new_cfg)\n    else:\n        raise","preventionTips":["Send minimal diff dicts to config updates; never echo full get_config() payloads.","Treat model_name as immutable: a model change means a new collection and re-embedding.","Centralize config-update building in one helper that strips known-immutable keys."],"tags":["chroma","cloudflare","config-update","embedding-function","immutable-field"],"backgroundTag":"immutable-config-field","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}