GoogleGenerativeAIEmbeddings features and configuration options, please refer to the API reference.
Overview
gemini-embedding-2-preview natively supports text, image, video, audio, and PDF inputs via the Google GenAI SDK’s embed_content() API. However, the LangChain Embeddings interface (embed_query / embed_documents) currently only accepts text inputs. Multimodal embedding support in LangChain is planned for a future release. For multimodal use cases today, use the Google GenAI SDK directly.Integration details
Setup
To access Google Gemini embedding models you’ll need to create a Google Cloud project, enable the Generative Language API, get an API key, and install thelangchain-google-genai integration package.
Credentials
Head to Google AI Studio to sign up and generate an API key. See the Gemini API keys documentation for more details. Once you’ve done this set theGOOGLE_API_KEY environment variable:
Installation
The LangChain Google Generative AI integration lives in thelangchain-google-genai package:
Instantiation
Now we can instantiate our model object and generate embeddings:Reduced dimensionality
gemini-embedding-2-preview supports flexible output dimensions via Matryoshka Representation Learning (MRL). You can reduce dimensionality to optimize storage and latency:
Batch
You can also embed multiple strings at once for a processing speedup:Indexing and retrieval
Embedding models are often used in retrieval-augmented generation (RAG) flows, both as part of indexing data as well as later retrieving it. For more detailed instructions, please see our RAG tutorials. Below, see how to index and retrieve data using theembeddings object we initialized above. In this example, we will index and retrieve a sample document in the InMemoryVectorStore.
Task type
GoogleGenerativeAIEmbeddings optionally support a task_type, which currently must be one of:
SEMANTIC_SIMILARITY: Used to generate embeddings that are optimized to assess text similarity.CLASSIFICATION: Used to generate embeddings that are optimized to classify texts according to preset labels.CLUSTERING: Used to generate embeddings that are optimized to cluster texts based on their similarities.RETRIEVAL_DOCUMENT,RETRIEVAL_QUERY,QUESTION_ANSWERING, andFACT_VERIFICATION: Used to generate embeddings that are optimized for document search or information retrieval.CODE_RETRIEVAL_QUERY: Used to retrieve a code block based on a natural language query, such as sort an array or reverse a linked list. Embeddings of the code blocks are computed usingRETRIEVAL_DOCUMENT.
RETRIEVAL_DOCUMENT in the embed_documents method and RETRIEVAL_QUERY in the embed_query method. If you provide a task type, we will use that for all methods.
Additional configuration
You can pass the following parameters toGoogleGenerativeAIEmbeddings to customize the SDK’s behavior:
base_url: Custom base URL for the API client (e.g., a custom endpoint)output_dimensionality: Reduce the dimensionality of returned embeddings (e.g.,output_dimensionality=256)request_options: Request options dict (e.g.,{"timeout": 10})additional_headers: Additional HTTP headers to include in API requestsclient_args: Additional arguments to pass to the underlying HTTP client
API reference
For detailed documentation onGoogleGenerativeAIEmbeddings features and configuration options, please refer to the API reference.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

