Skip to main content

Gemini Embedding 2 (Multimodal Embeddings)

gemini-embedding-2 is Google's hosted multimodal embedding model. Text, images, audio, video and PDFs land in one shared space (100+ languages), so one index serves text-to-image, image-to-image and video/audio search. It uses the same GEMINI_API_KEY as Nano Banana, Veo and Gemini understanding.

export GEMINI_API_KEY="your_api_key"
ItemValue
CLI modelgemini-embedding-2 (service embed)
Adaptertryon.api.gemini.GeminiEmbeddingAdapter
Output3072-d by default; --dim 128–3072 (768 / 1536 / 3072 recommended), re-normalised
Not comparable withgemini-embedding-001 (text-only, different space) or other models; re-embed if you switch

Input limits​

ModalityLimit
Text8,192 tokens
ImagePNG / JPEG, up to 6 per aggregated request
AudioMP3 / WAV, up to 180 s
VideoMP4 / MOV, up to 120 s (≤32 sampled frames; audio track not processed)
PDF1 file, up to 6 pages

Files above ~18 MB are sent through the Gemini Files API automatically.

CLI​

# One vector per input, plus cosine scores against a text query
opentryon embed --model gemini-embedding-2 --image boot1.jpg boot2.jpg --query "black leather ankle boots"

# "More like this": image query
opentryon embed --model gemini-embedding-2 --image catalogue/*.jpg --query-image reference.jpg

# One fused vector for a product (title + photo), smaller dimension
opentryon embed --model gemini-embedding-2 --text "Linen shirt" --image shirt.jpg --aggregate --dim 768

Vectors are written to an .npz file in the output directory (emb_0, emb_1, …); the call returns its path, shapes, labels and, with a query, the scores.

Flags​

FlagMeaning
--text, --image, --audio, --video, --pdfInputs (any mix)
--query, --query-imageOptional query; adds cosine scores (use one of the two)
--taskText task prefix: search result (default), question answering, fact checking, code retrieval, classification, clustering, sentence similarity
--roledocument (default) or query for --text items (retrieval tasks)
--dimOutput dimensionality, 128–3072
--aggregateFuse all inputs into one embedding

Semantics worth knowing​

  • Separate vs aggregated. Gemini collapses several parts in one request into a single embedding. By default OpenTryOn wraps each input separately (one vector each, batched); --aggregate sends them together.
  • No task_type. The model ignores task types, so for text OpenTryOn adds the prompt prefix itself: queries use task: search result | query: …, documents title: none | text: …, and symmetric tasks task: clustering | query: …. Media is never prefixed, and text inside an aggregated multimodal embedding is left unprefixed (Google's guidance).
  • Truncated dimensions are re-normalised client-side, so cosine similarity stays valid.

Python​

from tryon.api.gemini import GeminiEmbeddingAdapter

adapter = GeminiEmbeddingAdapter()
out = adapter.embed(image=["boot1.jpg", "boot2.jpg"], query="black leather ankle boots", output_dimensionality=768)
print(out["scores"]) # cosine similarity to the query
vectors = out["embeddings"] # numpy array, L2-normalised

Related: the open-weight alternatives EmbeddingGemma 2 and the fashion embedders. Official docs: ai.google.dev/gemini-api/docs/embeddings.