Registry /
llm-agents / llama-index-embeddings-google-genai
Install & Compatibility
Where this runs
tested against v0.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 267.2MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 21.8s · import 0.000s · 264MB
279MB installed
● package 279MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
GoogleGenerativeAIEmbedding
✓ from llama_index.embeddings.google_genai import GoogleGenerativeAIEmbedding
✗ from llama_index.embeddings.google_genai import GoogleGenerativeAIEmbedding
This quickstart demonstrates how to initialize the `GoogleGenerativeAIEmbedding` model and set it as the default embedding model in LlamaIndex's global `Settings`. It then generates an embedding for a sample text. Ensure the `GOOGLE_API_KEY` environment variable is set for authentication with Google GenAI.
import os
from llama_index.embeddings.google import GoogleGenerativeAIEmbedding
from llama_index.core import Settings
# Ensure GOOGLE_API_KEY environment variable is set
# For testing purposes, you can uncomment and set it:
# os.environ["GOOGLE_API_KEY"] = os.environ.get("GOOGLE_API_KEY", "YOUR_GOOGLE_API_KEY")
try:
# Initialize the embedding model
# Optionally specify model_name, e.g., model_name="models/embedding-001"
embed_model = GoogleGenerativeAIEmbedding(api_key=os.environ.get('GOOGLE_API_KEY'))
# Set as the default embedding model for LlamaIndex operations
Settings.embed_model = embed_model
# Generate an embedding for a piece of text
text_to_embed = "The quick brown fox jumps over the lazy dog."
embedding = embed_model.get_text_embedding(text_to_embed)
print(f"Successfully generated embedding.")
print(f"Embedding dimension: {len(embedding)}")
# print(f"First 5 values of embedding: {embedding[:5]}") # Uncomment to see values
except ValueError as e:
print(f"Error initializing or using model: {e}")
if "API key not found" in str(e) or "authentication" in str(e):
print("Please ensure GOOGLE_API_KEY environment variable is set and valid.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingLlamaIndex v0.10+ modularized core components and integrations. The import path for `GoogleGenerativeAIEmbedding` changed from a potentially monolithic `llama_index.embeddings` (if it existed there) to `llama_index.embeddings.google`.fixUpdate your import statement to `from llama_index.embeddings.google import GoogleGenerativeAIEmbedding` and ensure `llama-index-embeddings-google-genai` is installed.
affects: llama-index-core < 0.10
gotchaGoogle API key authentication is typically handled via the `GOOGLE_API_KEY` environment variable. If it's not set, or is invalid, you will encounter authentication errors.fixSet the `GOOGLE_API_KEY` environment variable with a valid key. You can also pass it directly to the constructor: `GoogleGenerativeAIEmbedding(api_key="your_key")`.
affects: All
gotchaWhen specifying a model name, it's best practice to use the full resource name (e.g., 'models/embedding-001') as expected by the Google Generative AI API, though the library might sometimes infer it.fixExplicitly pass `model_name="models/embedding-001"` or `model_name="models/text-embedding-004"` to the `GoogleGenerativeAIEmbedding` constructor to avoid ambiguity.
affects: All
Upgrade
Version history
0.5.1latest on PyPI · released May 19, 2026
Audit
Dependencies
llama-index-corerequiredCore LlamaIndex functionalities, including Settings and schema definitions.
google-generativeairequiredOfficial Google Generative AI SDK for interacting with Google's models.