{"record":{"id":"aa3172d38159f6b1","repo":"chroma-core/chroma","slug":"the-google-generative-ai-python-package-is-not-ins","errorCode":null,"errorMessage":"The Google Generative AI python package is not installed. Please install it with `pip install google-generativeai`","messagePattern":"The Google Generative AI python package is not installed\\. Please install it with `pip install google-generativeai`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/google_embedding_function.py","lineNumber":241,"sourceCode":"    ):\n        \"\"\"\n        Initialize the GoogleGenerativeAiEmbeddingFunction.\n\n        Args:\n            api_key_env_var (str, optional): Environment variable name that contains your API key for the Google Generative AI API.\n                Defaults to \"GEMINI_API_KEY\".\n            model_name (str, optional): The name of the model to use for text embeddings.\n                Defaults to \"gemini-embedding-001\".\n            task_type (str, optional): The task type for the embeddings.\n                Use \"RETRIEVAL_DOCUMENT\" for embedding documents and \"RETRIEVAL_QUERY\" for embedding queries.\n                Defaults to \"RETRIEVAL_DOCUMENT\".\n            dimension (int, optional): The output dimensionality for the embeddings.\n                If None, the model's default dimensionality is used.\n        \"\"\"\n        try:\n            import google.generativeai as genai\n        except ImportError:\n            raise ValueError(\n                \"The Google Generative AI python package is not installed. Please install it with `pip install google-generativeai`\"\n            )\n\n        if api_key is not None:\n            warnings.warn(\n                \"Direct api_key configuration will not be persisted. \"\n                \"Please use environment variables via api_key_env_var for persistent storage.\",\n                DeprecationWarning,\n            )\n        if os.getenv(\"GOOGLE_API_KEY\") is not None:\n            self.api_key_env_var = \"GOOGLE_API_KEY\"\n        else:\n            self.api_key_env_var = api_key_env_var\n\n        self.api_key = api_key or os.getenv(self.api_key_env_var)\n        if not self.api_key:\n            raise ValueError(\n                f\"The {self.api_key_env_var} environment variable is not set.\"","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/google_embedding_function.py#L223-L259","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install it: pip install google-generativeai","Preferably migrate to GoogleGeminiEmbeddingFunction with pip install google-genai, since google-generativeai is deprecated","Verify the interpreter: python -c \"import google.generativeai\""],"exampleFix":"# before\nfrom chromadb.utils.embedding_functions import GoogleGenerativeAiEmbeddingFunction\nef = GoogleGenerativeAiEmbeddingFunction()  # ValueError: package not installed\n\n# after\nfrom chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction\nef = GoogleGeminiEmbeddingFunction()  # requires: pip install google-genai","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec(\"google.generativeai\") is None:\n    # preferred: use the modern class with its own dependency\n    if importlib.util.find_spec(\"google.genai\") is not None:\n        from chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction as EF\n    else:\n        raise SystemExit(\"Run: pip install google-genai (or google-generativeai for the legacy class)\")\nelse:\n    from chromadb.utils.embedding_functions import GoogleGenerativeAiEmbeddingFunction as EF\n\nef = EF()","typeGuard":null,"tryCatchPattern":"try:\n    from chromadb.utils.embedding_functions import GoogleGenerativeAiEmbeddingFunction\n    ef = GoogleGenerativeAiEmbeddingFunction()\nexcept ValueError as e:\n    if \"google-generativeai\" in str(e):\n        raise SystemExit(\"Run: pip install google-generativeai (or migrate to GoogleGeminiEmbeddingFunction)\") from e\n    raise","preventionTips":["Prefer GoogleGeminiEmbeddingFunction + google-genai; google-generativeai is deprecated by Google","Pin whichever optional SDK you use in requirements and verify with find_spec at startup","Keep interpreter selection explicit in IDEs/notebooks to avoid installing into the wrong env"],"tags":["google-generativeai","gemini","chroma","missing-dependency","deprecated-sdk"],"backgroundTag":"python-package-not-installed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}