{"record":{"id":"69c9dc93fe0cd15f","repo":"chroma-core/chroma","slug":"the-google-genai-python-package-is-not-installed","errorCode":null,"errorMessage":"The google-genai python package is not installed. Please install it with `pip install google-genai`","messagePattern":"The google-genai python package is not installed\\. Please install it with `pip install google-genai`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/google_embedding_function.py","lineNumber":46,"sourceCode":"            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                Valid values include SEMANTIC_SIMILARITY, CLASSIFICATION, CLUSTERING,\n                RETRIEVAL_DOCUMENT, RETRIEVAL_QUERY, CODE_RETRIEVAL_QUERY,\n                QUESTION_ANSWERING, FACT_VERIFICATION.\n            dimension (int, optional): The output dimensionality for the embeddings.\n                Supported range: 128–3072. If None, the model's default is used.\n            api_key_env_var (str, optional): Environment variable name that contains your API key.\n                Defaults to \"GEMINI_API_KEY\".\n            vertexai (bool, optional): Whether to use Vertex AI.\n                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.\n            project (str, optional): The Google Cloud project ID (required for Vertex AI).\n            location (str, optional): The Google Cloud location/region (required for Vertex AI).\n        \"\"\"\n        try:\n            import google.genai as genai\n        except ImportError:\n            raise ValueError(\n                \"The google-genai python package is not installed. Please install it with `pip install google-genai`\"\n            )\n\n        self.model_name = model_name\n        self.task_type = task_type\n        self.dimension = dimension\n        self.api_key_env_var = api_key_env_var\n        self.vertexai = vertexai\n        self.project = project\n        self.location = location\n        self.api_key = os.getenv(self.api_key_env_var) if self.api_key_env_var else None\n        if self.api_key and self.vertexai:\n            raise ValueError(\n                \"Vertex AI and API key are mutually exclusive in the client initializer.\"\n            )\n        if not self.api_key and not self.vertexai:\n            raise ValueError(\n                f\"The {self.api_key_env_var} environment variable must be set if vertexai is not enabled.\"","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/google_embedding_function.py#L28-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install the package: pip install google-genai","Verify the same interpreter can import it: python -c \"import google.genai; print(google.genai.__version__)\"","If it imports in your shell but not at runtime, rebuild the venv/container so the running interpreter matches","If you cannot add dependencies, fall back to the default ONNXMiniLM_L6_V2 embedding function which needs no extra packages"],"exampleFix":"# before\nfrom chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction\nef = GoogleGeminiEmbeddingFunction()  # ValueError: google-genai not installed\n\n# after (shell)\n# pip install google-genai\nfrom chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction\nef = GoogleGeminiEmbeddingFunction()  # constructs fine","handlingStrategy":"validation","validationCode":"import importlib.util\n\ndef google_genai_available() -> bool:\n    return importlib.util.find_spec(\"google.genai\") is not None\n\nif google_genai_available():\n    from chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction\n    ef = GoogleGeminiEmbeddingFunction()\nelse:\n    raise SystemExit(\"Missing dependency: pip install google-genai\")","typeGuard":null,"tryCatchPattern":"try:\n    from chromadb.utils.embedding_functions import GoogleGeminiEmbeddingFunction\n    ef = GoogleGeminiEmbeddingFunction()\nexcept ValueError as e:\n    if \"google-genai\" in str(e):\n        raise SystemExit(\"Run: pip install google-genai\") from e\n    raise","preventionTips":["Pin optional embedding dependencies (google-genai) explicitly in requirements/pyproject alongside chromadb","Add a startup dependency check (importlib.util.find_spec) that fails fast with an actionable message","Verify the running interpreter with 'python -c \"import google.genai\"' after installing in CI and Docker builds"],"tags":["google-genai","gemini","chroma","missing-dependency","importerror"],"backgroundTag":"python-package-not-installed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}