This library provides the official integration for connecting LlamaIndex applications with Google's Generative AI models, including Gemini and Vertex AI. It allows LlamaIndex to leverage Google's LLMs for tasks such as text completion, chat interactions, function calling, and structured prediction. As of version 0.9.1, it is actively maintained with a regular release cadence, often aligning with updates to the core LlamaIndex framework.
pip install llama-index-llms-google-genaiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the GoogleGenAI LLM and perform a basic text completion. It assumes the `GOOGLE_API_KEY` environment variable is set. Replace `YOUR_GOOGLE_API_KEY_HERE` with your actual key for testing if not using environment variables.
Migrate your code to use the `llama-index-llms-google-genai` package and update import statements to `from llama_index.llms.google_genai import GoogleGenAI`.
Ensure `GOOGLE_API_KEY` is correctly set in your environment. For Vertex AI, configure `GOOGLE_GENAI_USE_VERTEXAI=True` and provide `project_id` and `location` (region) either via environment variables or in the `GoogleGenAI` constructor.
Implement retry logic with exponential backoff around your LLM calls. Consider checking and potentially increasing your Google Cloud project quotas if these errors persist.
Check the documentation of your specific observability tool for updates or workarounds. This is often an issue with the integration layer rather than the LLM integration itself. Manual parsing of `usage_metadata` might be required in some cases.
Update your import statement to `from llama_index.llms.google_genai import GoogleGenAI` and ensure `llama-index-llms-google-genai` is installed.
Set the `GOOGLE_API_KEY` environment variable with a valid API key obtained from Google AI Studio. For Vertex AI, verify that `GOOGLE_GENAI_USE_VERTEXAI=True` and that `project_id` and `location` are correctly specified.
Implement a retry mechanism with exponential backoff in your application to handle transient rate limit errors. Review your Google Cloud project's API quotas and consider requesting an increase if your usage consistently exceeds limits.