chroma-core/chroma · error · ValueError

The vertexai cannot be changed after the embedding function

Error message

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

What it means

GoogleGeminiEmbeddingFunction.validate_config_update rejects update payloads containing a 'vertexai' key. Auth mode (API key vs Vertex AI ADC) is fixed at client construction; flipping it later would silently change credential resolution against an existing client, so the field is immutable by design.

Source

Thrown at chromadb/utils/embedding_functions/google_embedding_function.py:183

        if self.task_type is not None:
            config["task_type"] = self.task_type
        if self.dimension is not None:
            config["dimension"] = self.dimension
        return config

    def validate_config_update(
        self, old_config: Dict[str, Any], new_config: Dict[str, Any]
    ) -> None:
        if "model_name" in new_config:
            raise ValueError(
                "The model name cannot be changed after the embedding function has been initialized."
            )
        if "dimension" in new_config:
            raise ValueError(
                "The dimension cannot be changed after the embedding function has been initialized."
            )
        if "vertexai" in new_config:
            raise ValueError(
                "The vertexai cannot be changed after the embedding function has been initialized."
            )
        if "project" in new_config:
            raise ValueError(
                "The project cannot be changed after the embedding function has been initialized."
            )
        if "location" in new_config:
            raise ValueError(
                "The location 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

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Recreate the embedding function (and effectively the collection workflow) with the desired auth mode from the start
  2. Drop the 'vertexai' key from update payloads that only intend to change mutable settings like api_key_env_var or task_type
  3. Model auth changes as a migration: new collection, re-embed, repoint readers

Example fix

# before
new_config = {"vertexai": True, "project": "my-proj", "location": "us-central1"}
ef.validate_config_update(old, new_config)  # ValueError: vertexai immutable

# after - only mutable keys in the update
new_config = {"api_key_env_var": "GOOGLE_API_KEY"}
ef.validate_config_update(old, new_config)
Defensive patterns

Strategy: validation

Validate before calling

IMMUTABLE = {"model_name", "dimension", "vertexai", "project", "location"}

update = {k: v for k, v in desired_config.items() if k not in IMMUTABLE}
assert "vertexai" not in update
ef.validate_config_update(old_config, update)

Type guard

from typing import Any, TypeGuard

MUTABLE_GEMINI_KEYS = {"api_key_env_var", "task_type"}

def is_mutable_update(cfg: Any) -> TypeGuard[dict]:
    return isinstance(cfg, dict) and set(cfg) <= MUTABLE_GEMINI_KEYS

Prevention

When it happens

Trigger: Trying to switch a collection's embedding function from Gemini API-key auth to vertexai=True (or vice versa) via modify/config update; passing a full get_config() dict (which always includes the vertexai key) as the new config.

Common situations: Promoting a prototype from AI Studio keys to production Vertex credentials and attempting an in-place swap; copy-pasting full configs as update payloads.

Related errors


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