"Gemini Embedding 2 Tutorial: Text, Images, Audio, One Space"

"Stop captioning images to search them. Gemini Embedding 2 maps text, images, audio, video, and PDFs into a single vector space — so a text query finds the right photo directly. This tutorial builds cross-modal search in Python."

The standard advice for searching images used to be: run a vision model over every image, generate captions, then embed the captions as text. That's a Rube Goldberg machine — slow, lossy, and expensive, and the search can only ever be as good as the captions. Here's the contrarian take this gemini embedding 2 tutorial is built on: stop captioning things to search them. Gemini Embedding 2 maps text, images, audio, video, and PDFs into one shared vector space, so a text query compares directly against raw media at the vector level. No middleman. Let's build it. What you'll build A single API call that embeds text, an image, and audio together A cross-modal image search: text query in, matching photos out Audio embedding and audio-to-audio similarity PDF page embedding for document search Matryoshka dimension truncation to control cost and speed A limits cheat-sheet so you never hit a silent truncation Prerequisites: Python 3.10+, pip install google-genai==2.25.0 numpy , and a Gemini API key. One model, every modality: how the shared vector space works An embedding model converts input into a list of floats (a vector) where similar meanings sit close together. Multimodal embedding models do this for every modality in the same space — so the vector for the text "a red sneaker" lands near the vector for a photo of a red sneaker, with no captioning step in between. Search becomes one cosine-similarity comparison across modalities. Know the input limits before you build — exceeding them silently truncates: Modality Limit per request Text 8,192 tokens (shared cap across all modalities) Images 6 images; PNG or JPEG Audio 180 seconds; MP3 or WAV Video 120 seconds; MP4/MOV; max 32 frames sampled PDF 1 file, up to 6 pages Two gotchas worth memorizing now: audio…

Explore