Next meetup: SelfEvaluate Agent · Sat, Oct 31, 9:00 AM IST · both mandatory for venue entryRSVPGoogle Form
All postsGuest post

EmbeddingGemma 2: A Compact Multimodal Embedding Model

Khaja Moinuddin Mohammed 3 min read
EmbeddingGemma 2: A Compact Multimodal Embedding Model

EmbeddingGemma 2 is Google’s latest open embedding model for semantic search and retrieval-augmented generation (RAG). Built on Gemma 4, it maps text, source code, images, video, and audio into a shared 768-dimensional vector space. It is released under the Apache 2.0 license and scales from 270 million to 740 million parameters depending on the modalities you enable.

Why EmbeddingGemma 2 matters?

Traditional multimodal search systems often require separate models for text, images, audio, and video. EmbeddingGemma 2 provides a unified alternative:

  • Search source code using natural-language queries.
  • Find images using text descriptions.
  • Search audio recordings and video clips semantically.
  • Build multimodal RAG pipelines.
  • Run local or on-device retrieval with a relatively small model.
  • Store embeddings in a single compatible vector space.

For example, a query such as “waterproof trail shoes” can be compared with text, product images, or a video showing the shoes being tested on wet rocks.

Main Specifications

Feature Details
Model EmbeddingGemma 2
Base model Gemma 4
License Apache 2.0
Modalities Text, code, images, video, and audio
Maximum embedding size 768 dimensions
Context window 8,192 tokens
Parameter range 270M to 740M
Embedding compression 768, 512, 256, or 128 dimensions
Main use cases Semantic search, code search, multimodal retrieval, RAG, recommendation systems

Modular architecture

You do not need to load the complete model if your application uses only one or two modalities.

  • 270M parameters: Text and code.
  • 440M parameters: Text, images, and video.
  • 570M parameters: Text and audio.
  • 740M parameters: Text, code, images, video, and audio.

The different configurations still project inputs into the same vector space. This means a text-only encoder can be used with embeddings generated by the full multimodal configuration, provided the embedding dimensions and processing settings match.

Stronger code retrieval

One of the most useful improvements is its code-understanding capability. Google reports that EmbeddingGemma 2 performs 14% better than EmbeddingGemma 1 on the MTEB Code benchmark.

This makes it suitable for:

  • Searching large GitHub repositories.
  • Finding relevant functions from natural-language questions.
  • Building coding assistants.
  • Indexing technical documentation and source code.
  • Supporting agentic code-search workflows.

A developer could ask:

“Where is authentication token refresh implemented?”

The embedding model can retrieve the most relevant files, classes, or functions before an LLM generates the final answer.

Matryoshka Representation Learning

EmbeddingGemma 2 supports Matryoshka Representation Learning, or MRL. This allows the original 768-dimensional vector to be truncated to a smaller size while preserving much of its semantic quality.

Dimensions Recommended use
768 or 512 Highest recall and multimodal retrieval
256 Storage-constrained indexes
128 Large text-only indexes and first-stage shortlisting

At 256 dimensions, the model retains most of its quality for text and code and approximately 95% of its retrieval quality for image, video, and speech. At 128 dimensions, text and code retain around 90% quality, while multimodal retrieval quality can fall to approximately 75%. These figures should be validated against your own data before deployment.

Reducing the vector size can significantly lower storage requirements. For example, one million 768-dimensional vectors require roughly 1.5 GB in bfloat16, while 128-dimensional vectors require approximately 250 MB.

Basic Python example

Install the required libraries:

from sentence_transformers import SentenceTransformer

model = SentenceTransformer("google/embeddinggemma-2")

For a text- and code-only application, load the smaller configuration:

text_model = SentenceTransformer(
    "google/embeddinggemma-2",
    config_kwargs={
        "vision_config": None,
        "audio_config": None,
    },
)

Text and code retrieval

EmbeddingGemma 2 uses task-specific prompts for retrieval. Queries and documents should be encoded with different prompts:

query = "How does Kubernetes restart a failed container?"
document = """
Kubernetes uses the kubelet to monitor containers and restart them
according to the pod's restart policy.
"""

query_embedding = text_model.encode(
    query,
    prompt_name="SearchQuery",
)

document_embedding = text_model.encode(
    document,
    prompt_name="Document",
)

similarity = text_model.similarity(
    query_embedding,
    document_embedding,
)

print(similarity)

Using the correct query and document prompts helps the model distinguish between the question being asked and the content being searched.

Multimodal example

The same model can embed different media types:

image_embedding = model.encode({
    "image": "sunset_beach.jpg"
})

audio_embedding = model.encode({
    "audio": "ocean_waves.wav"
})

query_embedding = model.encode(
    "ocean waves at sunset",
    prompt_name="SearchQuery",
)

print(model.similarity(query_embedding, image_embedding))
print(model.similarity(query_embedding, audio_embedding))

It also supports interleaved inputs containing text, images, and video:

listing_embedding = model.encode({
    "text": (
        "Waterproof trail shoe. "
        "<|image|> Grip test on wet rock: <|video|>"
    ),
    "image": "trail_shoe.jpg",
    "video": "grip_test.mp4",
})

Practical applications

EmbeddingGemma 2 could be useful for:

  • Multimodal RAG: Retrieve information from documents, diagrams, screenshots, audio, and videos.
  • Codebase search: Search source code using natural-language questions.
  • Technical documentation: Match questions with documentation, charts, and architecture diagrams.
  • Media search: Find images, recordings, or video moments using text queries.
  • On-device AI: Build local search applications with lower memory requirements.
  • Product discovery: Match text queries with product descriptions, images, and demonstration videos.
  • Agent systems: Give AI agents a unified retrieval layer across different data types.
#EmbeddingGemma#Gemma#Multimodal AI#AI Embeddings#RAG#Semantic Search

Written by

Khaja Moinuddin Mohammed

Khaja Moinuddin Mohammad is a seasoned AI researcher With two decades of experience in various fields belonging to information technology. He is the founder of AIYatra and leads the AIYatra Student Ambassador Program and AIYatra Research Labs.

Have a story of your own? Anyone can write for the AIYatra blog.

Writing guideWrite a guest post