# EmbeddingGemma

On-device text embedding model. Released **September 2025**. Built on **Gemma 3 with T5Gemma initialization**. No Gemma 4 generation yet.

## What it is

A **308M-parameter** open embedding model. Trained on 100+ languages. State-of-the-art on MTEB for its size class. Uses **Matryoshka Representation Learning (MRL)** — one model produces embeddings at 768, 512, 256, or 128 dimensions by truncation + renormalization, with graceful quality degradation.

## Sizes

- **308M** — only size.

## Model card

- https://ai.google.dev/gemma/docs/embeddinggemma/model_card
- HF: https://huggingface.co/google/embeddinggemma-300m
- HF blog: https://huggingface.co/blog/embeddinggemma
- DeepMind: https://deepmind.google/models/gemma/embeddinggemma/
- Paper: https://arxiv.org/html/2509.20354v2

## Prompt format

EmbeddingGemma uses **task-prefixed inputs** — you prepend a task descriptor to each string before embedding.

### Query prompts

```
task: {task description} | query: {your query}
```

Default task description: `search result`.

Example: `task: search result | query: what is the capital of France?`

### Document prompts

```
title: {title or "none"} | text: {document text}
```

Providing a real title improves retrieval; use `none` if unavailable.

Example: `title: Eiffel Tower | text: The Eiffel Tower is a wrought-iron lattice tower...`

## Minimum invocation

### Sentence-Transformers (easy path)

```python
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("google/embeddinggemma-300m")

query = "Which planet is known as the Red Planet?"
documents = [
    "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
    "Venus is often called Earth's twin due to its similar size.",
]

q_emb = model.encode_query(query)
d_emb = model.encode_document(documents)

print(model.similarity(q_emb, d_emb))
```

The `encode_query` / `encode_document` methods apply the task prefixes automatically.

### Shorter embeddings (MRL)

```python
emb_768 = model.encode(text)                       # full
emb_256 = emb_768[:, :256]                         # truncate
emb_256 = emb_256 / emb_256.norm(dim=-1, keepdim=True)  # renormalize
```

## Gotcha

**Activations do not support `float16`.** Use `bfloat16` or `float32`. This is explicit in the model card.

## When to choose it over base Gemma 4

Always, when you want embeddings. Base Gemma 4 is a generative decoder — not trained as an embedding model. EmbeddingGemma is the correct tool for retrieval, clustering, semantic search, RAG.

Its main competitor is `nomic-embed-text` (already in Seth's pantry). EmbeddingGemma's MRL and multilingual coverage (100+ vs. nomic's ~English-focused) are the differentiators.

## Homelab fit

**Highest-impact variant for Seth right now, along with TranslateGemma.**

- **Family history agent:** 100+ language support + 128d embeddings = tight, multilingual indices over scanned documents, letters, census records. MRL lets you serve fast 128d approximate search and fall back to 768d for reranking.
- **SearXNG / SethSearch:** drop-in upgrade from nomic-embed-text for the semantic-search layer. Bigger model but better quality.
- **Mortdecai memory:** use 308M EmbeddingGemma for long-term memory over chat logs. Small enough to run alongside the big mortdecai qwen35 models on pve197 or steel141 without resource contention.
- **Gemma-cookbook already has a tutorial** (`tutorials_RAG_EmbeddingGemma.ipynb` in the corpus) — skip straight to working code.
