SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
14 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
4.8 KB · 55 lines markdown
Rendered Raw Blame History
1# Gemini embeddings — `embedContent`, `batchEmbedContents`, `asyncBatchEmbedContent`23**Status:** `DOCUMENTED` + `LIVE_VERIFIED` (`gemini-embedding-001`, `gemini-embedding-2`; 12 probes, 2026-09-18). `asyncBatchEmbedContent` → `ACCOUNT_RESTRICTED` (400 FAILED_PRECONDITION on the free tier).4**Sources:** https://ai.google.dev/gemini-api/docs/embeddings · https://ai.google.dev/api/embeddings · https://ai.google.dev/gemini-api/docs/pricing#gemini-embedding-2 · discovery `EmbedContentRequest`, `EmbedContentConfig`, `EmbedContentBatch`5**Machine-readable:** `generated/fragments/parameters/gemini-embeddings.json`, `generated/fragments/endpoints/gemini-core.json`, `generated/fragments/objects/gemini-core-objects.json#EmbedContentResponse|BatchEmbedContentsResponse|EmbedContentBatch`, matrix rows `gemini-embedding-*`6**Last verified:** 2026-09-1878## 1. Models910| Model | Input | Input limit | Output dims | Task type | Normalization of truncated vectors | Latest update |11|---|---|---|---|---|---|---|12| `gemini-embedding-001` | text | 2,048 tokens | 3072 default; 128–3072 (recommended 768/1536/3072) | `taskType` param (8 values) | manual | Jun 2025 |13| `gemini-embedding-2` (+ `-preview`) | text, image (≤6 PNG/JPEG), audio (≤180 s MP3/WAV), video (≤120 s MP4/MOV, 32 frames, no audio track), PDF (1 file ≤6 pages, 258 tokens/page + text) | 8,192 tokens (shared) | same | **not supported** — put `task: search result | query: …` / `title: … | text: …` prefixes in the text (live: `taskType` was accepted silently) | automatic | Apr 2026 |1415Embedding spaces of 001 and 2 are incompatible — re-embed when migrating. Generation models → `404 … not supported for embedContent`.1617## 2. `POST /v1beta/models/{model}:embedContent`1819```json20{"content": {"parts": [{"text": "task: classification | query: Hello world"}]}, "outputDimensionality": 64}21```2223| Field | Notes |24|---|---|25| `content` (required) | one Content; embedding-2 **aggregates all parts into one vector** (text + PNG → 1 vector, usage TEXT 3 + IMAGE 258). |26| `outputDimensionality` | truncation (MRL). Live: 64 → 64 floats on both models (below the documented 128 floor); default → 3072; 4096 → `400 Unable to submit request because the outputDimensionality value is not supported.` |27| `taskType` | `RETRIEVAL_QUERY`, `RETRIEVAL_DOCUMENT`, `SEMANTIC_SIMILARITY`, `CLASSIFICATION`, `CLUSTERING`, `QUESTION_ANSWERING`, `FACT_VERIFICATION`, `CODE_RETRIEVAL_QUERY` (001). |28| `title` | only with `RETRIEVAL_DOCUMENT` (001). |29| `embedContentConfig` | nested equivalent `{taskType, title, outputDimensionality, autoTruncate, documentOcr, audioTrackExtraction}` — verified `{outputDimensionality: 64, autoTruncate: true}`. Top-level `taskType/title/outputDimensionality` are marked deprecated in discovery. |30| `model` (body) | optional `models/{id}` echo (required inside batch requests). |3132Response: `{"embedding": {"values": [...]}, "usageMetadata": {"promptTokenCount", "promptTokenDetails": [{modality, tokenCount}]}}` — `usageMetadata` returned by **embedding-2 only** (001 returns just `embedding`).3334## 3. `POST …:batchEmbedContents` (sync)3536`{"requests": [{"model": "models/gemini-embedding-001", "content": {...}, "outputDimensionality": 64}, ...]}` → `{"embeddings": [{values}, {values}]}` in order. Each request must repeat `model` (`400 * BatchEmbedContentsRequest.requests[0].model: model is not specified`). The SDK's `embed_content(contents=[...])` uses this. For embedding-2, separate `Content` objects → separate vectors; parts inside one content → one vector.3738## 4. `POST …:asyncBatchEmbedContent` (Batch API, 50 % price)3940Body `{"batch": {"displayName", "inputConfig": {"requests": {"requests": [{"request": EmbedContentRequest, "metadata": {...}}]}} | {"fileName": "files/…"}, "priority"}}` → `Operation` whose response is an `EmbedContentBatch` (`state BATCH_STATE_PENDING|RUNNING|SUCCEEDED|FAILED|CANCELLED|EXPIRED`, `output.inlinedResponses | responsesFile`, `batchStats`). Live on this key: `400 FAILED_PRECONDITION Precondition check failed.` (requires billing). Batch lifecycle (`/v1beta/batches`) is documented by the batch domain.4142## 5. Pricing (2026-09)4344| Model | Text input / 1M | Image | Audio | Video | Batch |45|---|---|---|---|---|---|46| gemini-embedding-2 | $0.20 | $0.45/1M tok ($0.00012/image) | $6.50/1M ($0.00016/s) | $12.00/1M ($0.00079/frame) | 50 % |47| gemini-embedding-001 | (see pricing page, "Gemini Embedding") | — | — | — | 50 % |4849MTEB (001): 3072/2048/1536 ≈ 68.2, 768 ≈ 68.0, 512 ≈ 67.6, 256 ≈ 66.2, 128 ≈ 63.3.5051## 6. Legacy52`embedText` / `batchEmbedText` / `countTextTokens` (PaLM) → 404 even though `countTextTokens` is still listed in the embedding models' `supportedGenerationMethods`. See `legacy-palm-methods.md`.5354Examples: `examples/gemini/embeddings/`. Tests: `tests/gemini/test_embeddings.py`.55