{"record":{"id":"52108b4fde7786a8","repo":"chroma-core/chroma","slug":"the-task-cannot-be-changed-after-the-embedding-fun","errorCode":null,"errorMessage":"The task cannot be changed after the embedding function has been initialized.","messagePattern":"The task 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":213,"sourceCode":"            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\n\n        Raises:\n            ValidationError: If the configuration does not match the schema\n        \"\"\"","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/chroma_cloud_qwen_embedding_function.py#L195-L231","documentation":"validate_config_update for chroma-cloud-qwen raises ValueError when 'task' appears in new_config. The task (e.g. 'nl_to_code') selects the instruction string sent with every embed request and is baked into the function at construction time; Chroma forbids changing it afterwards because embeddings produced with a different task are not comparable to those already stored.","triggerScenarios":"An EF config update whose new_config contains the 'task' key — reaching this branch means 'model' was absent (checks are if/elif in order model, task, instructions). Example: collection.modify-style update with {\"task\": \"nl_to_code\"}.","commonSituations":"Trying to repoint an existing collection from general-purpose to code-retrieval embeddings by editing config; piping a serialized get_config() dict back as an update; config-templating code that always includes all fields.","solutions":["Remove 'task' (and model/instructions) from the update config — chroma-cloud-qwen currently has no updatable keys.","Create a new ChromaCloudQwenEmbeddingFunction with the desired task and a new collection, then re-ingest.","Filter get_config() output down to nothing before reuse in update paths."],"exampleFix":"# before\nnew_config = {\"task\": \"nl_to_code\"}  # ValueError: task cannot be changed\n\n# after: rebuild the function with the task you want\nef = ChromaCloudQwenEmbeddingFunction(\n    model=ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,\n    task=\"nl_to_code\",\n)","handlingStrategy":"validation","validationCode":"if \"task\" in new_config:\n    raise ValueError(\n        \"task is immutable for chroma-cloud-qwen; recreate the embedding function with the new task\"\n    )","typeGuard":"def is_safe_qwen_update(new_config: dict) -> bool:\n    return not ({\"model\", \"task\", \"instructions\"} & set(new_config))","tryCatchPattern":null,"preventionTips":["Decide the task (e.g. nl_to_code) once at collection design time.","Never reuse full config snapshots as update payloads.","If retrieval quality demands new instructions/task, budget for re-embedding."],"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"}