What is GoogleGenerativeAIEmbeddings?
GoogleGenerativeAIEmbeddings is the LangChain wrapper for Google's Gemini embedding models accessed through the Google AI (Gemini API) with a GOOGLE_API_KEY. It turns text into dense vectors for semantic search, RAG, and clustering, and is attractive for budget-conscious projects because it has a usable free tier and low per-token pricing. It is distinct from the Vertex AI variant (VertexAIEmbeddings), which targets Google Cloud projects with IAM auth instead of an API key.
You select a model with the model argument — current models use the models/ prefix, for example models/text-embedding-004 (the newer, higher-quality model) or the older models/embedding-001. The class exposes the standard embed_query and embed_documents methods and plugs into any LangChain vector store unchanged. A Gemini-specific feature is task_type: telling the model whether text is a RETRIEVAL_DOCUMENT, a RETRIEVAL_QUERY, a SEMANTIC_SIMILARITY pair, or a CLASSIFICATION input lets it tune the vector for that use, which measurably improves retrieval when set correctly.
Install langchain-google-genai and set GOOGLE_API_KEY (or pass google_api_key directly). Note that older snippets use the model_name keyword; current releases prefer model, and mixing them can raise a validation error. The free tier enforces low requests-per-minute limits, so embed_documents on a large corpus can hit 429s — batch modestly and add backoff for bulk indexing. As always, index and query with the same model and task_type pairing, and re-embed if you upgrade the model.
When to Use
You need low-cost embeddings or are in Google's ecosystem. Use for budget-conscious projects.
Use Cases
- • Low-cost RAG
- • Google Cloud integration
- • Budget projects
- • Multimodal experiments
- • Fast prototyping
- • Free tier access
Key Features
- ✓ Low cost
- ✓ Google-managed
- ✓ Easy setup
- ✓ Decent quality
- ✓ Free tier
- ✓ Simple API
When NOT to Use
For production requiring highest quality.
Notes
Prefer text-embedding-004
models/text-embedding-004 supersedes the older models/embedding-001 with better quality at the same low cost. Use the models/ prefix in the model id; omitting it is a common cause of model-not-found errors.
Set task_type for retrieval
Gemini embeddings accept a task_type such as RETRIEVAL_DOCUMENT for indexed text and RETRIEVAL_QUERY for user questions. Setting the matching type on each side measurably improves search relevance versus embedding everything with the default.
model vs. model_name keyword
Current langchain-google-genai releases expect the model keyword. Older tutorials pass model_name, which can raise a validation error on newer versions. If you hit an unexpected-keyword error, switch to model.
Free-tier rate limits
The free Gemini API tier enforces low requests-per-minute quotas, so embed_documents over a large corpus can hit 429 errors. Batch modestly, add backoff for bulk indexing, or upgrade to a paid key for production throughput.
Import
from langchain_google_genai import GoogleGenerativeAIEmbeddings
Configuration
| Parameter | Type | Default | Purpose |
|---|---|---|---|
| model_name | str | models/embedding-001 | Model ID |
Usage Examples
Embed a single query
from langchain_google_genai import GoogleGenerativeAIEmbeddings
embeddings = GoogleGenerativeAIEmbeddings(model='models/text-embedding-004')
vector = embeddings.embed_query('What is retrieval augmented generation?')
print(len(vector))
Low-cost RAG index
from langchain_google_genai import GoogleGenerativeAIEmbeddings
from langchain_chroma import Chroma
embeddings = GoogleGenerativeAIEmbeddings(model='models/text-embedding-004')
store = Chroma.from_documents(docs, embeddings)
hits = store.similarity_search('refund window', k=4)
Tune the vector with task_type
from langchain_google_genai import GoogleGenerativeAIEmbeddings
embeddings = GoogleGenerativeAIEmbeddings(
model='models/text-embedding-004',
task_type='RETRIEVAL_QUERY',
)
vector = embeddings.embed_query('how do I cancel my plan')
Common Pitfalls
❌ Forget to set GOOGLE_API_KEY
✅ export GOOGLE_API_KEY='...'
Alternative Embedding Models
| Model | When to Use |
|---|---|
| OpenAIEmbeddings | For higher quality embeddings |
Related LangChain References
Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with GoogleGenerativeAIEmbeddings and the wider framework.
GoogleGenerativeAIEmbeddings FAQ
What is GoogleGenerativeAIEmbeddings in LangChain?
Use Google's Generative AI embeddings. GoogleGenerativeAIEmbeddings is the LangChain wrapper for Google's Gemini embedding models accessed through the Google AI (Gemini API) with a GOOGLE_API_KEY. It turns text into dense vectors for semantic search, RAG, and clustering, and is attractive for budget-conscious projects because it has a usable free tier and low per-token pricing. It is distinct from the Vertex AI variant (VertexAIEmbeddings), which targets Google Cloud projects with IAM auth instead of an API key. …
Which package provides GoogleGenerativeAIEmbeddings?
DevShelfHub documents GoogleGenerativeAIEmbeddings from the langchain-google-genai package. Pin your installed LangChain version and match imports to the snippet on this page.
When should I use GoogleGenerativeAIEmbeddings?
You need low-cost embeddings or are in Google's ecosystem. Use for budget-conscious projects.
When should I avoid using GoogleGenerativeAIEmbeddings?
For production requiring highest quality.
How do I import GoogleGenerativeAIEmbeddings in Python?
from langchain_google_genai import GoogleGenerativeAIEmbeddings
Where can I explore more LangChain API reference pages?
Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.