Model chooser / Search and answer from your own content / Recurring
A help-centre assistant or internal search runs thousands of queries against content that changes. That needs embeddings. Gemini Embedding 2 embeds text, images, video, audio and PDF into one space, with adjustable dimensions and a low price per token.
Why Gemini Embedding 2
How to use it
Gemini API, TypeScript
Edit the parts in capitals, then run it.
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({}); // reads GEMINI_API_KEY
export async function embed(text: string, kind: "query" | "document") {
const res = await ai.models.embedContent({
model: "gemini-embedding-2",
// gemini-embedding-2 takes the task hint in the text, not a task_type parameter
contents: kind === "query" ? `Search query: ${text}` : `Document: ${text}`,
config: { outputDimensionality: 768 },
});
return res.embeddings[0].values; // number[] of length 768
}
Alternatives that also work
Pick it when search quality is the priority, including multilingual and code. Voyage calls it its best general-purpose model, with a 32K context.
Pick it when you self-host. NVIDIA reports first place on the RTEB retrieval leaderboard in July 2026, with a commercial-use license.
Pick it when you are already on OpenAI and the index is text only.
Watch out for
Sources
Checked . Models change monthly; we re-check this page when they do.
Wiring it into a workflow that runs every week, with evals, fallbacks and a cost you can predict, is the work. Fifteen minutes, no deck.