chroma-core/chroma · error · ValueError

The google-genai python package is not installed. Please ins

Error message

The google-genai python package is not installed. Please install it with `pip install google-genai`

What it means

GoogleGeminiEmbeddingFunction imports google.genai lazily inside __init__ and converts the ImportError into this ValueError with install instructions. The google-genai package is an optional dependency: chromadb's core install does not include it, so constructing the Gemini embedding function in an environment without it fails immediately.

Source

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

            model_name (str, optional): The name of the model to use for text embeddings.
                Defaults to "gemini-embedding-001".
            task_type (str, optional): The task type for the embeddings.
                Valid values include SEMANTIC_SIMILARITY, CLASSIFICATION, CLUSTERING,
                RETRIEVAL_DOCUMENT, RETRIEVAL_QUERY, CODE_RETRIEVAL_QUERY,
                QUESTION_ANSWERING, FACT_VERIFICATION.
            dimension (int, optional): The output dimensionality for the embeddings.
                Supported range: 128–3072. If None, the model's default is used.
            api_key_env_var (str, optional): Environment variable name that contains your API key.
                Defaults to "GEMINI_API_KEY".
            vertexai (bool, optional): Whether to use Vertex AI.
                If enabled, an API key must not be provided, and the environment variable `GOOGLE_APPLICATION_CREDENTIALS` must be set to the path of your service account JSON file.
            project (str, optional): The Google Cloud project ID (required for Vertex AI).
            location (str, optional): The Google Cloud location/region (required for Vertex AI).
        """
        try:
            import google.genai as genai
        except ImportError:
            raise ValueError(
                "The google-genai python package is not installed. Please install it with `pip install google-genai`"
            )

        self.model_name = model_name
        self.task_type = task_type
        self.dimension = dimension
        self.api_key_env_var = api_key_env_var
        self.vertexai = vertexai
        self.project = project
        self.location = location
        self.api_key = os.getenv(self.api_key_env_var) if self.api_key_env_var else None
        if self.api_key and self.vertexai:
            raise ValueError(
                "Vertex AI and API key are mutually exclusive in the client initializer."
            )
        if not self.api_key and not self.vertexai:
            raise ValueError(
                f"The {self.api_key_env_var} environment variable must be set if vertexai is not enabled."

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Install the package: pip install google-genai
  2. Verify the same interpreter can import it: python -c "import google.genai; print(google.genai.__version__)"
  3. If it imports in your shell but not at runtime, rebuild the venv/container so the running interpreter matches
  4. If you cannot add dependencies, fall back to the default ONNXMiniLM_L6_V2 embedding function which needs no extra packages

Example fix

# before
from chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction
ef = GoogleGeminiEmbeddingFunction()  # ValueError: google-genai not installed

# after (shell)
# pip install google-genai
from chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction
ef = GoogleGeminiEmbeddingFunction()  # constructs fine
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util

def google_genai_available() -> bool:
    return importlib.util.find_spec("google.genai") is not None

if google_genai_available():
    from chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction
    ef = GoogleGeminiEmbeddingFunction()
else:
    raise SystemExit("Missing dependency: pip install google-genai")

Try / catch

try:
    from chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction
    ef = GoogleGeminiEmbeddingFunction()
except ValueError as e:
    if "google-genai" in str(e):
        raise SystemExit("Run: pip install google-genai") from e
    raise

Prevention

When it happens

Trigger: Instantiating GoogleGeminiEmbeddingFunction (or the backward-compat alias GoogleGenaiEmbeddingFunction), or rebuilding it via GoogleGeminiEmbeddingFunction.build_from_config / get_embedding_function('google_gemini'), in any environment where 'import google.genai' raises ImportError - package never installed, installed into a different virtualenv/interpreter, or a broken partial install.

Common situations: Fresh environment with only 'pip install chromadb'; slim Docker images that drop optional extras; IDE or notebook attached to a different interpreter than the one where the package was installed; a dependency-resolver conflict that uninstalled google-genai; stale CI cache restoring an old env.

Related errors


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