{"id":9896,"library":"llama-index-embeddings-google-genai","title":"LlamaIndex Google Generative AI Embeddings","description":"This library provides the integration for Google Generative AI embedding models within LlamaIndex. It allows users to leverage Google's powerful text embedding capabilities, such as 'embedding-001' or 'text-embedding-004', for various RAG applications and data indexing tasks. The current version is 0.5.0, and it follows the LlamaIndex release cadence, often updating with new core versions or Google GenAI SDK updates.","status":"active","version":"0.5.0","language":"en","source_language":"en","source_url":"https://github.com/run-llama/llama_index/tree/main/llama-index-integrations/embeddings/google","tags":["llama-index","embeddings","google-genai","google-generative-ai","gemini"],"install":[{"cmd":"pip install llama-index-embeddings-google-genai","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"Core LlamaIndex functionalities, including Settings and schema definitions.","package":"llama-index-core","optional":false},{"reason":"Official Google Generative AI SDK for interacting with Google's models.","package":"google-generativeai","optional":false}],"imports":[{"note":"After LlamaIndex v0.10+, integrations moved to their own namespaces. The monolithic `llama_index.embeddings` path is deprecated for external integrations.","wrong":"from llama_index.embeddings import GoogleGenerativeAIEmbedding","symbol":"GoogleGenerativeAIEmbedding","correct":"from llama_index.embeddings.google import GoogleGenerativeAIEmbedding"},{"note":"LlamaIndex v0.10+ replaced `ServiceContext` with the `Settings` global configuration object for managing LLMs, embedding models, etc.","wrong":"from llama_index.legacy.service_context import ServiceContext","symbol":"Settings","correct":"from llama_index.core import Settings"}],"quickstart":{"code":"import os\nfrom llama_index.embeddings.google import GoogleGenerativeAIEmbedding\nfrom llama_index.core import Settings\n\n# Ensure GOOGLE_API_KEY environment variable is set\n# For testing purposes, you can uncomment and set it:\n# os.environ[\"GOOGLE_API_KEY\"] = os.environ.get(\"GOOGLE_API_KEY\", \"YOUR_GOOGLE_API_KEY\")\n\ntry:\n    # Initialize the embedding model\n    # Optionally specify model_name, e.g., model_name=\"models/embedding-001\"\n    embed_model = GoogleGenerativeAIEmbedding(api_key=os.environ.get('GOOGLE_API_KEY'))\n\n    # Set as the default embedding model for LlamaIndex operations\n    Settings.embed_model = embed_model\n\n    # Generate an embedding for a piece of text\n    text_to_embed = \"The quick brown fox jumps over the lazy dog.\"\n    embedding = embed_model.get_text_embedding(text_to_embed)\n\n    print(f\"Successfully generated embedding.\")\n    print(f\"Embedding dimension: {len(embedding)}\")\n    # print(f\"First 5 values of embedding: {embedding[:5]}\") # Uncomment to see values\n\nexcept ValueError as e:\n    print(f\"Error initializing or using model: {e}\")\n    if \"API key not found\" in str(e) or \"authentication\" in str(e):\n        print(\"Please ensure GOOGLE_API_KEY environment variable is set and valid.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Update your import statement to `from llama_index.embeddings.google import GoogleGenerativeAIEmbedding` and ensure `llama-index-embeddings-google-genai` is installed.","message":"LlamaIndex 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`.","severity":"breaking","affected_versions":"llama-index-core < 0.10"},{"fix":"Set the `GOOGLE_API_KEY` environment variable with a valid key. You can also pass it directly to the constructor: `GoogleGenerativeAIEmbedding(api_key=\"your_key\")`.","message":"Google 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.","severity":"gotcha","affected_versions":"All"},{"fix":"Explicitly pass `model_name=\"models/embedding-001\"` or `model_name=\"models/text-embedding-004\"` to the `GoogleGenerativeAIEmbedding` constructor to avoid ambiguity.","message":"When 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install llama-index-embeddings-google-genai`. If using an older `llama-index` core, consider upgrading or checking the documentation for your specific version.","cause":"The `llama-index-embeddings-google-genai` package is not installed, or the LlamaIndex version is very old and doesn't support the modularized import path.","error":"ModuleNotFoundError: No module named 'llama_index.embeddings.google'"},{"fix":"Set the environment variable: `export GOOGLE_API_KEY='your_api_key'` in your shell, or pass `api_key='your_api_key'` directly to the `GoogleGenerativeAIEmbedding` constructor.","cause":"The `GOOGLE_API_KEY` environment variable is not set or accessible by the application.","error":"ValueError: API key not found. Please set the GOOGLE_API_KEY environment variable."},{"fix":"Verify your `GOOGLE_API_KEY` is correct and active. Double-check the `model_name` you are using (e.g., ensure it's `models/embedding-001` and not just `embedding-001`). Also check Google Cloud project quotas.","cause":"This error typically indicates an issue with the request parameters, such as an invalid or expired API key, or an incorrect `model_name`.","error":"google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument. Target: embeddings.google.ai"}]}