chroma-core/chroma · error · ValueError

The task cannot be changed after the embedding function has

Error message

The task cannot be changed after the embedding function has been initialized.

What it means

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.

Source

Thrown at chromadb/utils/embedding_functions/chroma_cloud_qwen_embedding_function.py:213

            task: {target.value: instruction for target, instruction in targets.items()}
            for task, targets in self.instructions.items()
        }
        return {
            "api_key_env_var": self.api_key_env_var,
            "model": self.model.value,
            "task": self.task,
            "instructions": serialized_instructions,
        }

    def validate_config_update(
        self, old_config: Dict[str, Any], new_config: Dict[str, Any]
    ) -> None:
        if "model" in new_config:
            raise ValueError(
                "The model cannot be changed after the embedding function has been initialized."
            )
        elif "task" in new_config:
            raise ValueError(
                "The task cannot be changed after the embedding function has been initialized."
            )
        elif "instructions" in new_config:
            raise ValueError(
                "The instructions cannot be changed after the embedding function has been initialized."
            )

    @staticmethod
    def validate_config(config: Dict[str, Any]) -> None:
        """
        Validate the configuration using the JSON schema.

        Args:
            config: Configuration to validate

        Raises:
            ValidationError: If the configuration does not match the schema
        """

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Remove 'task' (and model/instructions) from the update config — chroma-cloud-qwen currently has no updatable keys.
  2. Create a new ChromaCloudQwenEmbeddingFunction with the desired task and a new collection, then re-ingest.
  3. Filter get_config() output down to nothing before reuse in update paths.

Example fix

# before
new_config = {"task": "nl_to_code"}  # ValueError: task cannot be changed

# after: rebuild the function with the task you want
ef = ChromaCloudQwenEmbeddingFunction(
    model=ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,
    task="nl_to_code",
)
Defensive patterns

Strategy: validation

Validate before calling

if "task" in new_config:
    raise ValueError(
        "task is immutable for chroma-cloud-qwen; recreate the embedding function with the new task"
    )

Type guard

def is_safe_qwen_update(new_config: dict) -> bool:
    return not ({"model", "task", "instructions"} & set(new_config))

Prevention

When it happens

Trigger: 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"}.

Common situations: 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.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/52108b4fde7786a8. Report an issue: GitHub.