Gemini Embedding 2 logo

Gemini Embedding 2

Community
Fandry96
gemini-embedding-2

Gemini Embedding 2 — Google's natively multimodal embedding model (GA April 2026). Maps text, images, video, audio, and PDFs into a unified 3072-dim vector space with MRL support (truncate to 128-3072). Use when: embeddings, semantic search, RAG, clustering, classification, multimodal retrieval, vector database, MRL truncation, cosine similarity, narrative memory, code retrieval, cross-modal search, agentic RAG.

Overview

PublisherFandry96
Repositoryk3-agentic-skills
Skill namegemini-embedding-2
Stars
27
Forks
5
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by Fandry96 on GitHub. Read the source before you install it.

Installation

Install the Gemini Embedding 2 AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/Fandry96/k3-agentic-skills/tree/master/skills/gemini-embedding-2
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Fandry96/k3-agentic-skills.git /tmp/k3-agentic-skills
mkdir -p .claude/skills
cp -r /tmp/k3-agentic-skills/skills/gemini-embedding-2 .claude/skills/gemini-embedding-2
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Gemini Embedding 2 in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Gemini Embedding 2 on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Gemini Embedding 2 is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Gemini Embedding 2 — Skill Reference

Model: gemini-embedding-2 (stable) / gemini-embedding-2-flash (speed-optimized) Released: March 10, 2026 (Preview) → April 22, 2026 (GA) Replaces: gemini-embedding-001, text-embedding-005, text-embedding-004 Docs: https://ai.google.dev/gemini-api/docs/embeddings Source: Deep Research synthesis (28 sources, May 2026)


1. Model Specifications

PropertyValue
Model IDgemini-embedding-2
Flash Variantgemini-embedding-2-flash (speed-optimized)
Pinned Variantgemini-embedding-2-flash-001 (reproducible vectors)
Default Dimensions3072 (float32)
MRL Range128, 256, 512, 768, 1536, 3072
Recommended MRL3072 (max quality), 1536 (balanced), 768 (fast/cheap sweet spot)
Max Text Tokens8,192 (4× increase over text-embedding-004's 2,048)
Max Images6 per request (PNG, JPEG, WebP, BMP)
Max Video120s without audio / 80s with audio (MP4, MPEG, MOV)
Max Audio180 seconds native (MP3, WAV — no transcription needed)
Max PDF6 pages per file (integrated OCR)
Languages100+
Multimodal✅ Natively multimodal — single transformer backbone, not stitched encoders
Distance MetricCosine Similarity (recommended)

MTEB Benchmarks

BenchmarkScorevs OpenAI 3-Largevs text-embedding-004
MTEB English68.32+3.72 (64.6)+4-6 points
MTEB Code84.0——
MTEB Multilingual69.9——
Video Retrieval (Vatex/MSR-VTT)68.8N/AN/A

2. Pricing

PlatformTierText/Image/VideoAudioOutput
AI StudioFree$0.00 (rate-limited)$0.00$0.00
AI StudioPaid$0.20 / 1M tokens$0.50 / 1M tokens$0.00
Vertex AIPaid$0.20 / 1M tokens$0.50 / 1M tokens$0.00
Batch APIIndexing~$0.10 / 1M tokens—$0.00

Cost Calculator

Corpus SizeEst. TokensCost
100 docs × 2K tokens200K$0.04
1,000 docs × 4K tokens4M$0.80
K3 MRL index (6,296 chunks)~12M$2.40
Proto_book full rebuild~20M$4.00

3. Critical Breaking Change: Task Prefixes Replace task_type

Gemini Embedding 2 does NOT use the task_type API parameter. You MUST include task instructions as string prefixes in the content itself.

Old Way (001) — DEPRECATED:

python
config=types.EmbedContentConfig(task_type="RETRIEVAL_DOCUMENT")

New Way (embedding-2) — MANDATORY:

python
# Prefix is part of the content string itself
content = "task: search result | query: western romance with grumpy hero"

4. Task Prefix Reference

4.1 Asymmetric Tasks (query ≠ document format)

Use different formats for queries vs documents. This is critical for retrieval/RAG.

TaskQuery SideDocument Side
Search / RAGtask: search result | query: {q}title: {title} | text: {content}
Q&Atask: question answering | query: {q}title: {title} | text: {content}
Fact Checktask: fact checking | query: {q}title: {title} | text: {content}
Code Searchtask: code retrieval | query: {q}title: {title} | text: {content}

If document has no title, use title: none | text: {content}.

4.2 Symmetric Tasks (same format both sides)

TaskBoth Sides
Classificationtask: classification | query: {content}
Clusteringtask: clustering | query: {content}
Similaritytask: sentence similarity | query: {content}

Helper Functions (Python)

python
# Asymmetric retrieval
def prepare_query(query, task="search result"):
    return f"task: {task} | query: {query}"

def prepare_document(content, title=None):
    t = title or "none"
    return f"title: {t} | text: {content}"

# Symmetric
def prepare_symmetric(content, task="clustering"):
    return f"task: {task} | query: {content}"

5. Code Examples

5.1 Python — Basic Embedding

python
from google import genai

client = genai.Client()  # Uses GEMINI_API_KEY env var

result = client.models.embed_content(
    model="gemini-embedding-2",
    contents="What is the meaning of life?"
)

vector = result.embeddings[0].values  # 3072 floats

5.2 Python — MRL Truncation (768 dims)

python
from google import genai
from google.genai import types

client = genai.Client()

result = client.models.embed_content(
    model="gemini-embedding-2",
    contents="Ryder leaned against the fence post, jaw tight.",
    config=types.EmbedContentConfig(
        output_dimensionality=768  # MRL truncation — API normalizes for you
    )
)

vector = result.embeddings[0].values  # 768 floats, pre-normalized

5.3 Python — Asymmetric Search with Prefixes

python
from google import genai
from google.genai import types
import numpy as np

client = genai.Client()

# Query side — uses task prefix
query = "task: search result | query: ranch romance with grumpy cowboy"
q_result = client.models.embed_content(
    model="gemini-embedding-2",
    contents=query,
    config=types.EmbedContentConfig(output_dimensionality=768)
)
q_vec = np.array(q_result.embeddings[0].values, dtype=np.float32)

# Document side — uses title/text prefix
docs = [
    "title: Flawless | text: Small-town western romance, grumpy cowboy mechanic...",
    "title: Ice Planet Barbarians | text: Sci-fi alien romance, survival...",
    "title: Heartless | text: Single dad rancher, woman next door...",
]
d_result = client.models.embed_content(
    model="gemini-embedding-2",
    contents=docs,
    config=types.EmbedContentConfig(output_dimensionality=768)
)

# Rank by cosine similarity
for i, emb in enumerate(d_result.embeddings):
    d_vec = np.array(emb.values, dtype=np.float32)
    score = np.dot(q_vec, d_vec) / (np.linalg.norm(q_vec) * np.linalg.norm(d_vec))
    print(f"{score:.4f}  {docs[i][:60]}")

5.4 Python — Multimodal (Image + Text)

python
from google import genai
from google.genai import types

client = genai.Client()

# Embed image + text together as interleaved content
image_part = types.Part.from_uri(
    file_uri="gs://bucket/cover.jpg",
    mime_type="image/jpeg"
)

result = client.models.embed_content(
    model="gemini-embedding-2",
    contents=types.Content(parts=[
        types.Part(text="Romance novel cover with cowboy"),
        image_part
    ]),
    config=types.EmbedContentConfig(output_dimensionality=768)
)

5.5 JavaScript — Node.js (@google/genai)

javascript
import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({});

// Single embedding
const response = await ai.models.embedContent({
    model: "gemini-embedding-2",
    contents: "task: search result | query: western romance",
    config: { outputDimensionality: 768 }
});
const vector = response.embeddings[0].values;  // 768 floats

// Batch embedding
const batchResponse = await ai.models.embedContent({
    model: "gemini-embedding-2",
    contents: [
        "title: Flawless | text: A grumpy cowboy mechanic...",
        "title: Heartless | text: A single dad rancher...",
    ],
    config: { outputDimensionality: 768 }
});

5.6 REST API — cURL

bash
# Single embedding
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:embedContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: ${GEMINI_API_KEY}" \
  -d '{
    "model": "models/gemini-embedding-2",
    "content": {
      "parts": [{"text": "task: search result | query: western romance"}]
    }
  }'

# Batch embedding
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:batchEmbedContents" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: ${GEMINI_API_KEY}" \
  -d '{
    "model": "models/gemini-embedding-2",
    "requests": [
      {"model": "models/gemini-embedding-2", "content": {"parts": [{"text": "doc 1"}]}},
      {"model": "models/gemini-embedding-2", "content": {"parts": [{"text": "doc 2"}]}}
    ]
  }'

6. MRL Strategy Guide

Dimension Selection

Use CaseDimsStorage (1M vecs)Quality
Mobile/edge2561 GBGood for coarse filtering
Narrative memory (sqlite-vec)7683 GBSweet spot — near-peak quality
MRL index (K3 skill search)7683 GBFast local queries
Production RAG15366 GBHigh quality
Max precision307212 GBFull resolution

Two-Stage Retrieval Pattern

Phase 1 (Fast):  768D vectors → scan full index → top-K candidates
Phase 2 (Precise): 3072D vectors → rerank top-K only → final results

L2 Normalization

When using output_dimensionality API parameter: vectors are pre-normalized. When truncating client-side with numpy: you must normalize manually:

python
import numpy as np

def truncate_and_normalize(vec_raw, dim=768):
    vec = np.array(vec_raw, dtype=np.float32)[:dim]
    norm = np.linalg.norm(vec)
    return vec / norm if norm > 0 else vec

7. Migration from Legacy Models

Incompatibility Warning

Vectors from different models are NOT compatible. You cannot compare:

  • gemini-embedding-001 vectors with gemini-embedding-2 vectors
  • text-embedding-004 vectors with gemini-embedding-2 vectors

Full re-indexing is required.

Shadow Indexing Strategy (Production)

  1. Build shadow index: re-embed entire corpus with gemini-embedding-2 in background
  2. Keep production running on legacy model
  3. Route 10% traffic to shadow index for A/B testing
  4. Recalibrate similarity thresholds (scores will shift — e.g., 0.6 → 0.7)
  5. Cut over when metrics are validated

K3 Migration Checklist

  • Update build_mrl_index.py: change MODEL to models/gemini-embedding-2
  • Update forge-embeddings.js: use gemini-embedding-2 model name
  • Add task prefixes to all embedding calls
  • Re-embed entire MRL index (~6,296 chunks, ~2 min, ~$2.40)
  • Re-embed Proto_book extraction summaries (~236 chunks, ~$0.10)
  • Recalibrate similarity thresholds in narrative search
  • Update AGENTS.md §300 MRL section with new model name

8. K3 Integration — Proto_book Narrative Memory

Indexing Scene Beats

python
doc = prepare_document(
    content=scene_summary,
    title=f"Ch{chapter_num} Scene {scene_num}"
)
# → "title: Ch3 Scene 2 | text: Ryder confronts Val about the fence..."

Querying Character Knowledge

python
query = prepare_query(
    "What does Ryder know about Val's corporate past?",
    task="question answering"
)
# → "task: question answering | query: What does Ryder know about..."

Clustering Dialogue Voices

python
sample = prepare_symmetric(
    '"Fence ain\'t gonna fix itself." He didn\'t look up.',
    task="clustering"
)
# → "task: clustering | query: "Fence ain't gonna fix itself."..."

9. Common Pitfalls

  1. Missing task prefixes = silent failure. The model still returns vectors, but they're sub-optimal. Always prefix.
  2. Mixing prefix formats. If docs use title: X | text: Y, queries MUST use task: search result | query: Z. Never mix.
  3. Cross-model comparison. Never compare vectors from different embedding models. The latent spaces are incompatible.
  4. Forgetting to normalize after manual truncation. API-side truncation auto-normalizes. Client-side numpy truncation does not.
  5. Using task_type parameter. This param is for gemini-embedding-001 only. Embedding-2 ignores it silently.
  6. Batch for throughput. Use batchEmbedContents for 20+ items. Single calls have per-request overhead.
  7. Rate limits. Free tier: 1,500 RPM. Use time.sleep(0.3) between batches.
  8. Threshold drift. After migration, cosine similarity scores shift. Always recalibrate thresholds.

Frequently asked questions

What does the Gemini Embedding 2 AI skill do?

Gemini Embedding 2 — Google's natively multimodal embedding model (GA April 2026). Maps text, images, video, audio, and PDFs into a unified 3072-dim vector space with MRL support (truncate to 128-3072). Use when: embeddings, semantic search, RAG, clustering, classification, multimodal retrieval, vector database, MRL truncation, cosine similarity, narrative memory, code retrieval, cross-modal search, agentic RAG.

Why use Gemini Embedding 2 on TypingMind?

Because you install it once and use it with any model. Gemini Embedding 2 is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Gemini Embedding 2 in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/Fandry96/k3-agentic-skills/tree/master/skills/gemini-embedding-2. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Gemini Embedding 2?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Gemini Embedding 2?

As many as you like. As long as a model supports skills, you can use Gemini Embedding 2 with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Gemini Embedding 2 AI skill free?

It is published on GitHub by Fandry96. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇