Set Up Your Environment
Generate Embeddings: POST /v1/embeddings
Single Input
Response
embedding array contains the full vector. For text-embedding-004 and gemini-embedding-001, this is a 768-dimensional float array.
Batch Input
Pass an array of strings to embed multiple texts in a single request:data array contains one embedding object per input string, each with a matching index.
Available Models
| Model | Dimensions | Description |
|---|---|---|
text-embedding-004 | 768 | General-purpose text embedding — recommended starting point |
gemini-embedding-001 | 768 | Gemini native embedding model |
SDK Examples
Common Use Cases
Semantic Search
Embed your document corpus and a user’s query, then rank documents by cosine similarity to surface the most relevant results — without keyword matching.
Retrieval-Augmented Generation (RAG)
Store chunk embeddings in a vector database (Pinecone, pgvector, Weaviate). At query time, retrieve the top-k nearest chunks and pass them as context to a Gemini chat model.
Text Clustering & Deduplication
Group similar documents together or detect near-duplicate content by comparing embedding distances across your dataset.
Recommendation Systems
Compute similarity between item descriptions or user preference vectors to power content or product recommendations.
Measuring Similarity
Use cosine similarity to compare two embedding vectors. Values close to1.0 indicate high semantic similarity; values near 0 indicate unrelated content.
