Gemini Embedding 2: A Python Guide to Multimodal Understanding
Unlocking Multimodal Understanding with Gemini Embedding 2
I remember a time when digital information felt siloed, locked within its format. Text lived in one space, images in another, and audio entirely separate. Now, with advances like Google's Gemini Embedding 2, we are witnessing a convergence, a unified understanding of diverse data types that promises to transform how we interact with information.
Google's Gemini Embedding 2 model, released in public preview on March 10, 2026, marks the company's first fully multimodal embedding model, designed for complex retrieval and analysis tasks. You can read more about it on the official Google AI blog. This model efficiently maps various inputs—text, images, video, audio, and PDFs—into a single, unified semantic space. This capability is particularly beneficial for applications requiring multimodal semantic search, document retrieval, and recommendation systems, as detailed in the announcement blog post.
Quick Summary
- Multimodal Capabilities: Processes text, images, video, audio, and PDFs into a unified semantic space.
- Unified Semantic Space: Maps diverse inputs into a single embedding space for efficient retrieval and analysis.
- Vector Dimensionality: Generates 3,072-dimensional vectors by default, with options for 768, 1536, and 3072.
- Matryoshka Representation Learning (MRL): Allows dynamic scaling of information across dimensions for flexible performance and storage.
- Language Support: Captures semantic intent across more than 100 languages.
- Access: Available via the Gemini API and Vertex AI, requiring a free API key.
- Python Integration: Easily integrate with the
google-genailibrary. - Migration Note: Incompatible with
gemini-embedding-001; requires re-embedding all data. - Key Applications: Enhances Retrieval-Augmented Generation (RAG), semantic search, sentiment analysis, and data clustering.
Capabilities of Gemini Embedding 2
Gemini Embedding 2 accepts a broad range of multimodal inputs, as explained in the Google AI blog post. It can process up to 8,192 input tokens for text, and up to six images per request in PNG and JPEG formats. Video inputs, supported in MP4 and MOV, can be up to 120 seconds long. The model natively processes audio data without requiring intermediate text transcription, and it can analyze PDF documents up to six pages in length directly. Furthermore, it understands nested inputs, allowing multiple modalities, such as an image combined with text, in a single request. One significant feature is its ability to perform Optical Character Recognition (OCR) on document inputs. For video inputs, it can extract audio tracks and intertwine them with video frames.
The model generates 3,072-dimensional floating-point vectors by default, as stated in the Vertex AI documentation. However, this output dimensionality is customizable using the output_dimensionality parameter, allowing for the generation of smaller vectors to balance performance and storage costs. Recommended output dimensions for optimal quality are 768, 1536, and 3072. Gemini Embedding 2 employs Matryoshka Representation Learning (MRL), which dynamically scales information across dimensions. MRL supports a two-stage retrieval pattern: smaller vectors for quick pre-selection, followed by full vectors for re-ranking. The default 3,072-dimensional output is already normalized; for reduced dimensions like 768D or 1536D, L2 normalization should be applied manually.

Source: dreamstime.com
Gemini Embedding 2 uses Matryoshka Representation Learning, allowing dynamic scaling of information across vector dimensions.
Crucially, the model captures semantic intent across more than 100 languages. Custom task instructions, such as task:code retrieval or task:search result, further optimize embeddings for specific relationships, enhancing accuracy. The model’s knowledge cutoff is specified as November 2025.
Accessing and Integrating Gemini Embedding 2
Developers can access Gemini Embedding 2 through the Gemini API and Vertex AI, as outlined in the Vertex AI documentation for Gemini Embedding 2. The preview version’s model ID is gemini-embedding-2-preview. To utilize the Gemini API, a free API key is required, which you can obtain from Google AI Studio. Python users can install the google-genai library using pip install --upgrade google-genai, as detailed in the Gemini API embeddings documentation. The API key can be set as an environment variable, GEMINI_API_KEY. The Google Gen AI SDK provides a unified interface for Gemini 2.5 Pro and Gemini 2.0 models across both the Gemini Developer API and Vertex AI, and more information can be found in the Google Gemini Cookbook on GitHub. This allows for code execution on either platform with minimal modification.
pip install --upgrade google-genai
GEMINI_API_KEY
When upgrading from the older gemini-embedding-001 to gemini-embedding-2-preview, note that embeddings exist in different vector spaces and are not compatible. Consequently, all data needs re-embedding, and similarity thresholds must be recalibrated after migration. For new projects, starting directly with gemini-embedding-2-preview, ideally with 768 dimensions, is recommended.
For storing vectors, AlloyDB with the pgvector extension presents a viable option, offering a ScaNN index with tree quantization and automatic dimensionality reduction. The choice of task_type (e.g., RETRIEVAL_DOCUMENT for indexing and RETRIEVAL_QUERY for searching) significantly impacts quality. Gemini Embedding 2 supports eight task types, including classification, clustering, and semantic similarity.
Practical Applications and Examples
Google’s GitHub repository offers examples and guidance on using the Gemini API, including Python code, available in the Google Gemini Cookbook. Additional examples specifically for Gemini Embedding 2, covering text embedding, video embedding, multimodal search, and semantic search, are available on the Gemini Multimodal Embedding Examples GitHub repository.

Source: textstudio.com
The Google GitHub repository provides valuable examples and guidance for implementing the Gemini API.
These examples include scripts designed to demonstrate specific functionalities:
01_text_embedding.py: Covers single and batch text embedding, different task types, and 768D normalization.02_video_embedding.py: Shows inline uploads, Files API usage, video and text cross-modal embedding, and chunking for longer videos. Each embedding call accommodates up to 128 seconds of video; for longer videos, a chunking helper function is provided.03_multimodal_embedding.py: Illustrates cross-modal search, such as finding videos using text queries.04_search.py: Performs semantic search over stored embeddings.05_describe.py: Analyzes video embeddings against 100 predefined topics.
Frequently Asked Questions (FAQs)
| Question | Answer |
|---|---|
| What is Gemini Embedding 2? | It is Google's first fully multimodal embedding model, designed for complex retrieval and analysis tasks, capable of processing text, images, video, audio, and PDFs into a unified semantic space. |
| How do I get started with Gemini Embedding 2 in Python? | Install the google-genai library via pip, obtain a free API key from Google AI Studio, and set it as an environment variable (GEMINI_API_KEY). |
| Can I use Gemini Embedding 2 for multimodal search? | Yes, it excels at multimodal semantic search, allowing you to find videos with text queries, for example, and supports nested inputs (e.g., image + text). |
| What output dimensions does Gemini Embedding 2 support? | By default, it generates 3,072-dimensional vectors. You can customize this to 768, 1536, or 3072 for optimal quality, balancing performance and storage. |
| Is Gemini Embedding 2 compatible with older embedding models? | No, embeddings from gemini-embedding-001 are not compatible. All data must be re-embedded, and similarity thresholds recalibrated when migrating to Gemini Embedding 2. |
Conclusion
Gemini Embedding 2 represents a significant step towards more intuitive and contextual data interaction. By transforming diverse data types into a unified semantic representation, it simplifies complex pipelines, enhancing capabilities in areas like Retrieval-Augmented Generation (RAG), semantic search, sentiment analysis, and data clustering. Its multimodal understanding and flexible dimensionality options offer developers powerful tools to build sophisticated AI applications, pushing the boundaries of what integrated AI models can achieve.