chroma-core/chroma · error · ValueError

The location cannot be changed after the embedding function

Error message

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

What it means

GoogleGeminiEmbeddingFunction.validate_config_update rejects update payloads containing a 'location' key. The Vertex AI region is fixed when genai.Client is constructed; changing regions after the fact would redirect requests to a different deployment with independently stored state, so it is validated as immutable.

Source

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

    ) -> 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

        Raises:
            ValidationError: If the configuration does not match the schema
        """
        validate_config_schema(config, "google_gemini")


# Backward compatibility alias

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Create a new deployment/collection in the target region and re-embed
  2. Strip 'location' (and the other immutable keys) from update payloads; only api_key_env_var and task_type are meant to change
  3. Choose the region deliberately before first ingestion

Example fix

# before
new_config = {"location": "europe-west1", "task_type": "RETRIEVAL_QUERY"}
ef.validate_config_update(old, new_config)  # ValueError: location immutable

# after
new_config = {"task_type": "RETRIEVAL_QUERY"}
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 "location" 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: Attempting to change region (e.g. us-central1 to europe-west1) through a config update on an existing function; passing a full config dict from get_config() - which always includes location - as the update payload.

Common situations: Data-residency moves across regions; latency optimization attempts after initial deployment; full-config copy-paste used as an update.

Related errors


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