EmbeddingGemma 2
Follow modular encoders into one bidirectional backbone, the contrastive objective and training curriculum, and the trade-offs behind its new Pareto frontier.
Jump to a section
Why this matters
EmbeddingGemma 2 is an open embedding model that maps text, code, images, audio, video and interleaved mixtures of them to one 768-dimensional unit vector. A query in one modality can retrieve a target in another because both land in the same space.
Earlier designs forced a choice. CLIP-style models add a separate tower per modality, so they compare an image with a caption but cannot read an image and a caption together as one input. Embedding models adapted from multimodal LLMs can read mixed input, but they usually have several billion parameters. EmbeddingGemma 2 keeps mixed input at 744M parameters and loads only the encoders a task needs.
The paper's headline result is a new size–quality frontier on four benchmark suites. Each star below sits above the previous frontier at its parameter count.
A new size–quality frontier on four benchmarks
- New frontier
- Prior frontier
- Gain
- Other models
Horizontal: parameters, log scale. Vertical: leaderboard score, Mean(Task) except MIEB(lite), which uses Mean(Type).
Redrawn from Figure 2. Points were digitized from the paper’s vector graphic; the starred and frontier values match Tables 6–10. EmbeddingGemma 2 counts only the parameters each benchmark uses: 271M for code, 439M for vision, 577M for audio. Baselines are as reported on public leaderboards.
Read the plotted frontier values
| Benchmark | EmbeddingGemma 2 | Closest prior frontier point |
|---|---|---|
| MTEB(Code) | 271M · 78.68 | pplx-0.6B · 596M · 75.85 |
| MMEB-v2 | 439M · 59.01 | CAFe-0.5B · 894M · 49.33 |
| MAEB | 577M · 49.87 | jina-v5-nano · 986M · 50.14 |
| MIEB(lite) | 439M · 65.67 | SigLIP-SoViT · 878M · 53.50 |
On a Google Pixel 11 Pro, the int4 per-channel checkpoint peaks at 191 MB for text, 447 MB with vision and 567 MB with every encoder, including runtime compilation overhead.
Build the mental model
Think of the model as one reader with optional eyes and ears. A vision encoder turns an image, or each sampled video frame, into a short sequence of "soft tokens". An audio encoder does the same for sound at 25 tokens per second. Text goes through the ordinary embedding table. Linear adapters project every soft token to the backbone width of 512, and the pieces are concatenated in their original order between delimiter tokens.
The backbone is a Gemma 4 decoder with its causal mask switched to bidirectional attention. A generator must not see future tokens; an embedding model should, because the vector summarizes the whole input. After 24 layers the model mean-pools every position, projects 512 to 768 dimensions and rescales the result to unit length. Similarity is then a dot product.
Because encoders only produce input tokens, they are modular. Text-only search can skip both encoders and run 271M parameters. Use the selector to see which pieces each configuration loads. The audio encoder is frozen and bit-identical to Gemma 4's; the vision encoder is trained, which matters later.
Choose which encoders to load
Soft tokens are projected to dM = 512 and interleaved at their positions in the input.
Redrawn from Figure 1 and §2.1. Component sizes are the paper’s rounded figures; totals are as reported (text 271M, vision–language 439M, audio–language 577M, all 744M). The audio encoder is frozen and identical to Gemma 4’s; the vision encoder is trained.
EmbeddingGemma 2 · Figure 1, §2.1–2.2Work through the math
The embedding. For token embeddings and the 24-layer bidirectional transformer ,
where is a linear map. Every input, whatever its length or modality, becomes one point on the unit sphere.
How long can one input be? Images are pooled to at most soft tokens (280 by default; 70 to 1,120 at inference). Audio gives 25 per second. Video is sampled at 1 frame per second and capped at 32 frames, at 140 tokens per frame by default. Each image, frame or audio segment adds two delimiters. Training sequences reach 8,192 positions. A 120-second clip with its soundtrack therefore needs at most positions, but 32 frames at the image budget alone need . Change the inputs and budgets below.
Count the positions one input can occupy
6,075 positions at most. This fits within the 8,192 positions used in training. The video yields 45 frames at 1 fps; only 32 are kept, by truncation or uniform sampling.
- Text32
- Image 1280
- 32 video frames4,480
- 45 × 1 s soundtrack1,125
- Delimiters and BOS/EOS158
Upper bound from §2.2. Images are pooled to at most the chosen budget; audio produces 25 soft tokens per second; video is sampled at 1 fps and capped at 32 frames. Each image, frame and audio segment adds two delimiters. We count each 1-second soundtrack segment with its own delimiters and do not count the MM:SS timestamp text, so a real sequence differs slightly. The text count is yours to set; it depends on the tokenizer.
EmbeddingGemma 2 · §2.2The contrastive loss. Each example has a query , a positive target and hard negatives . With cosine similarity and temperature ,
sums over the example's own hard negatives. sums over the other examples' positive targets. The same-tower term also pushes query away from query and target away from target, which keeps queries and documents from settling into two separate regions. A mask removes example when its query or target duplicates example 's, so a repeated target is never penalized as a negative.
What query 1 is contrasted against
| p⁺1 | p⁺2 | p⁺3 | p⁺4 | p⁻1 | p⁻2 | p⁻3 | p⁻4 | q1 | q2 | q3 | q4 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| p⁺1 | Targets are also pushed apart: sim(p⁺i, p⁺j) | |||||||||||
- Positive (numerator)
- Hard negative
- In-batch negative
- Same-tower negative
- Masked by 1TN
11 terms in the denominator for query 1: 1 positive, 1 hard negative, 3 in-batch and 6 same-tower.
A batch of B = 4 with one hard negative each. Select a query row. Other examples’ hard negatives are not in LC; the listwise loss in Equation 4 does use them. The 1TN mask removes pairs whose query or target duplicates another example’s, so a repeated target is never treated as a negative.
EmbeddingGemma 2 · §2.3, Equations 2–3Three supporting losses. A spread-out regularizer penalizes and for random pairs. Independent uniform points on a -dimensional sphere have mean dot product 0 and mean squared dot product , so the penalty pushes the space toward that isotropic baseline. Distillation matches the student's vectors to truncated, normalized Gemini Embedding 2 vectors, . For unit vectors that equals : matching a teacher is maximizing cosine similarity with it. Matryoshka Representation Learning applies each loss to the first 768, 512, 256 and 128 coordinates.
Read the implementation
This executable Python example implements Equation 2 for one hard negative per example and checks the duplicate mask. The temperature is our illustrative choice; the paper does not report .
1import math
2
3def cos(a, b):
4 dot = sum(x * y for x, y in zip(a, b))
5 return dot / math.sqrt(sum(x * x for x in a) * sum(y * y for y in b))
6
7def contrastive_loss(q, p, hard, tau=0.2, mask=True):
8 """Equation 2 with one hard negative per example."""
9 B, total = len(q), 0.0
10 e = lambda a, b: math.exp(cos(a, b) / tau)
11 for i in range(B):
12 if mask: # 1_TN drops j when its query or target duplicates example i
13 others = [j for j in range(B) if q[j] != q[i] and p[j] != p[i]]
14 else:
15 others = [j for j in range(B) if j != i]
16 z_p = e(q[i], p[i])
17 z_hn = e(q[i], hard[i])
18 z_ib = sum(e(q[i], p[j]) for j in others)
19 z_stn = sum(e(q[i], q[j]) + e(p[i], p[j]) for j in others)
20 total -= math.log(z_p / (z_p + z_hn + z_ib + z_stn))
21 return total / B
22
23q = [[1.0, 0.2], [0.1, 1.0], [0.9, 0.4]]
24p = [[0.9, 0.1], [0.1, 0.9], [0.9, 0.1]] # example 3 repeats example 1's target
25hard = [[0.2, 1.0], [1.0, 0.3], [0.3, 1.0]]
26
27masked, unmasked = contrastive_loss(q, p, hard), contrastive_loss(q, p, hard, mask=False)
28assert masked < unmasked # without 1_TN, a duplicate target is punished as a negative
29print(round(masked, 3), round(unmasked, 3))
30
31# Section 2.2 upper bounds: soft tokens plus two delimiters per image, frame or audio segment
32video_120s = min(120, 32) * (140 + 2) + 120 * (25 + 2) + 2 # frames, soundtrack, BOS/EOS
33assert video_120s == 7786 and video_120s <= 8192
34assert 32 * (280 + 2) > 8192 # 32 frames at the image budget alone exceed the training lengthA production loss also needs batched matrix operations, multiple hard negatives, MRL sub-losses and the listwise Plackett–Luce variant for ranked targets.
Per-layer embeddings without the table. Gemma 3n and Gemma 4 give each layer an extra input built from a projection of the token embeddings plus a dedicated lookup table indexed by token ID. Image and audio soft tokens have no token ID, so that table cannot help them, and it costs memory. EmbeddingGemma 2 keeps only the projection.
Where each layer’s extra input comes from
| MMEB-v2 (Table 2) | Overall | Image | Video | VisDoc |
|---|---|---|---|---|
| Projection only | 55.46 | 54.67 | 47.82 | 62.37 |
| With lookup table | 55.07 | 54.57 | 47.13 | 61.76 |
One layer l of 24, from §2.1, with dP = dM = 512. Dropping the table removed parameters and scored higher in every category of this intermediate-recipe ablation; the paper reports similar gains on text-only evaluations.
EmbeddingGemma 2 · §2.1, §3.1, Table 2The recipe separates what the model sees from what it optimizes. Text comes first, then every modality under pure distillation, then a contrastive finetune that drops the teacher. The final checkpoint averages the end of finetuning with a much earlier checkpoint from the same run.
Change the data first, then the objective
Width is proportional to tokens seen, about 2.9T in total.
- Text pre-finetuningText: QA, similarity, code and web search pairs
Distillationalmost allContrastivesmall weight
- Multimodal pre-finetuningAdds images, audio, video and documents
Distillationonly
- Multimodal finetuningHigher-quality, task-specific data
Contrastivereplaces distillationSpread-outregularizerMRL768/512/256/128
- Model mergingUnweighted average of the final finetuning checkpoint and a significantly earlier one from the same run.
- Quantization tail patchA separate stage distills int4 (Q4_0, Q4_C) backbone and W8A8 vision checkpoints from the frozen float model.
From §2.4. Distillation matches truncated, normalized Gemini Embedding 2 vectors for queries, positives and hard negatives. Finetuning drops it so the space can fit this model’s size and Matryoshka dimensions.
EmbeddingGemma 2 · §2.4Questions and trade-offs
Why stop distilling? The teacher's space was not shaped for a 744M student or for 128-dimensional prefixes. When the paper continued distillation for roughly the same compute, MMEB-v2 stayed flat at 52.28; switching to the contrastive recipe reached 55.46. Freezing the Gemma 4 vision encoder instead of training it cost 4.1 points.
Third stage
- Multimodal pre-finetuning
- + Extra distillation
- + Contrastive finetuning
Same starting checkpoint and a similar compute budget. More distillation plateaus; the contrastive finetuning recipe adds 3.2 points overall, mostly on images and video. MMEB-v2 on intermediate recipes, so these are not final-model numbers.
EmbeddingGemma 2 · §3, Table 3How many vision tokens? More tokens help visual documents, where small text matters, well past the training budget. Images flatten at 280. Video gets worse at 560 per frame, which the authors attribute to diluted attention and mean pooling over very long sequences.
More vision tokens help documents, not video
Table 5 (top): one intermediate checkpoint trained at 280 tokens per image and 140 per video frame, evaluated with a single budget for all MMEB-v2 tasks. Visual documents keep improving past the training budget; images flatten at 280; video drops from 48.51 to 46.52 at 560, which the paper attributes to diluted attention and mean pooling over long sequences.
EmbeddingGemma 2 · §3.4, Table 5How short can the vector be? Every suite keeps at least 95% of its score at 256 dimensions, a third of the storage. At 128, MMEB-v2 and spoken-query retrieval drop sharply. Native audio also beats transcribing speech first: even 256-dimensional native embeddings outscore full-width embeddings of ASR text. The paper attributes the gap to transcription errors from accents, homophones and audio artifacts, which native audio avoids.
Truncate the vector, keep most of the score
Mean scores from Tables 7–11 (MSEB is overall MRR@10). Byte counts are our arithmetic for uncompressed float32 vectors. Every suite keeps at least 95% of its score at 256 dimensions; MMEB-v2 and MSEB fall sharply at 128. Even the 256-d native-audio embedding beats full-width embeddings of ASR transcripts.
EmbeddingGemma 2 · Tables 7–11Two more cautions. On English text the model regresses slightly against EmbeddingGemma 1 (MTEB English 68.46 versus 69.67) while improving on multilingual text and code. And its speech representations are dominated by meaning: zero-shot clustering by speaker gender scores 0.40, yet a linear probe recovers gender at 66.40. The information is present, but not the main axis of similarity.
Check your understanding
A team stores 768-dimensional vectors for scanned invoices embedded at 280 vision tokens. To cut cost they propose truncating to 128 dimensions and embedding at 70 tokens. What do the paper's results predict?
Both changes hurt documents most. In the budget ablation, visual-document NDCG@5 fell from 63.38 at 280 tokens to 51.61 at 70, while 560 tokens raised it to 67.62. Truncating to 128 dimensions cut the MMEB-v2 visual-document average from 67.8 to 49.5. Truncating to 256 is the safer saving: 62.6 on visual documents for a third of the storage. Re-embed queries and documents with the same dimensions, compare them with cosine similarity, and measure on your own documents, because these are benchmark averages.
Source and scope
EmbeddingGemma 2: Unified and Efficient Multimodal Representations, arXiv:2610.37364, §2–4, Tables 1–11 and Figures 1–2. Architecture, objectives, recipe and all scores come from the paper; ablations use intermediate recipes. Figure 2 was digitized from the paper's vector graphic. Sequence-length totals, byte counts and the code are LiminalML derivations and teaching examples. We have not run the model or reproduced its benchmarks.
Oliver Perrin
Machine Learning Engineer · Founder, LiminalML
LiminalML brings together concept explanations, mathematical examples, and working visuals. Find more writing by Oliver on the LiminalML Substack.
Keep exploring the idea.
Ask a follow-up in a guided session, work through the self-check, or open the visual in Studio to build on it.
Related concepts
LLMs
Embeddings
Compare vectors by direction and magnitude, and connect embedding geometry to retrieval and representation learning.
LLMs
Retrieval-Augmented Generation (RAG)
Follow retrieval into a grounded prompt, then examine chunking, ranking, evidence quality, and generation failures.
LLMs
Reasoning Distillation
Separate imitating a teacher's text from matching its distribution, and see why distillation is cheap but capped by the teacher.