chroma-core/chroma · error · ValueError

The Google Generative AI python package is not installed. Pl

Error message

The Google Generative AI python package is not installed. Please install it with `pip install google-generativeai`

What it means

The legacy GoogleGenerativeAiEmbeddingFunction imports google.generativeai lazily in __init__ and converts ImportError into this ValueError. The google-generativeai package is optional (not installed with chromadb core), and Google has deprecated it in favor of the newer google-genai package used by GoogleGeminiEmbeddingFunction.

Source

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

    ):
        """
        Initialize the GoogleGenerativeAiEmbeddingFunction.

        Args:
            api_key_env_var (str, optional): Environment variable name that contains your API key for the Google Generative AI API.
                Defaults to "GEMINI_API_KEY".
            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.
                Use "RETRIEVAL_DOCUMENT" for embedding documents and "RETRIEVAL_QUERY" for embedding queries.
                Defaults to "RETRIEVAL_DOCUMENT".
            dimension (int, optional): The output dimensionality for the embeddings.
                If None, the model's default dimensionality is used.
        """
        try:
            import google.generativeai as genai
        except ImportError:
            raise ValueError(
                "The Google Generative AI python package is not installed. Please install it with `pip install google-generativeai`"
            )

        if api_key is not None:
            warnings.warn(
                "Direct api_key configuration will not be persisted. "
                "Please use environment variables via api_key_env_var for persistent storage.",
                DeprecationWarning,
            )
        if os.getenv("GOOGLE_API_KEY") is not None:
            self.api_key_env_var = "GOOGLE_API_KEY"
        else:
            self.api_key_env_var = api_key_env_var

        self.api_key = api_key or os.getenv(self.api_key_env_var)
        if not self.api_key:
            raise ValueError(
                f"The {self.api_key_env_var} environment variable is not set."

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Install it: pip install google-generativeai
  2. Preferably migrate to GoogleGeminiEmbeddingFunction with pip install google-genai, since google-generativeai is deprecated
  3. Verify the interpreter: python -c "import google.generativeai"

Example fix

# before
from chromadb.utils.embedding_functions import GoogleGenerativeAiEmbeddingFunction
ef = GoogleGenerativeAiEmbeddingFunction()  # ValueError: package not installed

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

Strategy: validation

Validate before calling

import importlib.util

if importlib.util.find_spec("google.generativeai") is None:
    # preferred: use the modern class with its own dependency
    if importlib.util.find_spec("google.genai") is not None:
        from chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction as EF
    else:
        raise SystemExit("Run: pip install google-genai (or google-generativeai for the legacy class)")
else:
    from chromadb.utils.embedding_functions import GoogleGenerativeAiEmbeddingFunction as EF

ef = EF()

Try / catch

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

Prevention

When it happens

Trigger: Instantiating GoogleGenerativeAiEmbeddingFunction (name 'google_generative_ai') in an environment where 'import google.generativeai' fails - never installed, installed under a different interpreter, or removed during a dependency cleanup.

Common situations: Environments with only 'pip install chromadb'; teams migrating off the deprecated SDK who still import the legacy class; Docker/CI images without optional extras; google-generativeai uninstalled by a resolver conflict.

Related errors


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