{"record":{"id":"0ca469f25d48c149","repo":"chroma-core/chroma","slug":"the-model-cannot-be-changed-after-the-embedding-fu","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":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/chroma_cloud_qwen_embedding_function.py","lineNumber":209,"sourceCode":"\n    def get_config(self) -> Dict[str, Any]:\n        # Serialize instructions dict with enum keys to string keys for JSON compatibility\n        serialized_instructions = {\n            task: {target.value: instruction for target, instruction in targets.items()}\n            for task, targets in self.instructions.items()\n        }\n        return {\n            \"api_key_env_var\": self.api_key_env_var,\n            \"model\": self.model.value,\n            \"task\": self.task,\n            \"instructions\": serialized_instructions,\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        elif \"task\" in new_config:\n            raise ValueError(\n                \"The task cannot be changed after the embedding function has been initialized.\"\n            )\n        elif \"instructions\" in new_config:\n            raise ValueError(\n                \"The instructions 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","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/chroma_cloud_qwen_embedding_function.py#L191-L227","documentation":"ChromaCloudQwenEmbeddingFunction.validate_config_update raises ValueError the moment 'model' appears in new_config. The Qwen model determines the x-chroma-embedding-model header and the dimensionality of stored vectors, so changing it after initialization would make new embeddings incompatible with existing ones in the collection.","triggerScenarios":"Updating the EF config for a collection initialized with chroma-cloud-qwen where new_config contains the 'model' key (even with the same value — presence alone triggers it, since the check is `if \"model\" in new_config`).","commonSituations":"Round-tripping a get_config() dict into an update call; migrating from one Qwen model to another via modify instead of a new collection; automation that sends the full config on every change.","solutions":["Drop 'model' from the update config; chroma-cloud-qwen has no mutable keys, so only send keys you are allowed to change (none exist today).","To use a different model, create a new collection with a fresh ChromaCloudQwenEmbeddingFunction and re-embed your data.","If your tooling copies get_config() output, filter it to remove model/task/instructions before submitting an update."],"exampleFix":"# before\nnew_config = ef.get_config()  # includes \"model\": \"Qwen/Qwen3-Embedding-0.6B\"\nnew_config[\"task\"] = \"nl_to_code\"\n# -> ValueError: model cannot be changed\n\n# after\nnew_config = {\"task\": \"nl_to_code\"}  # still rejected: task also immutable -> recreate EF instead\nef = ChromaCloudQwenEmbeddingFunction(\n    model=ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,\n    task=\"nl_to_code\",\n)","handlingStrategy":"validation","validationCode":"IMMUTABLE_QWEN_KEYS = {\"model\", \"task\", \"instructions\"}\nupdate = {k: v for k, v in new_config.items() if k not in IMMUTABLE_QWEN_KEYS}\nif not update:\n    raise ValueError(\"Nothing updatable for chroma-cloud-qwen; recreate the EF instead\")","typeGuard":"def is_safe_qwen_update(new_config: dict) -> bool:\n    return not ({\"model\", \"task\", \"instructions\"} & set(new_config))","tryCatchPattern":null,"preventionTips":["Treat model as immutable: plan migrations as new collection + re-embed, never as config edits.","Build update payloads as explicit minimal dicts, not snapshots of get_config().","Add a config filter helper shared by all update paths so immutable keys never slip through."],"tags":["chroma-cloud","qwen","immutable-config","config-validation","embedding-function"],"backgroundTag":"immutable-config-update","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}