Skip to main content

Request

Response


Parameters

content
object
required
The content to be embedded. Contains an ordered list of parts.
output_dimensionality
integer
The maximum number of dimensions to include in the output embedding. Truncates the output vector. Recommended values: 768, 1536, 3072.
taskType
string
Only supported on gemini-embedding-001 (legacy). Specifies the task type.Options:
  • SEMANTIC_SIMILARITY: Text similarity — recommendation, duplicate detection
  • CLASSIFICATION: Sentiment analysis, spam detection
  • CLUSTERING: Document organization, market research, anomaly detection
  • RETRIEVAL_DOCUMENT: Documents to be indexed/retrieved
  • RETRIEVAL_QUERY: Search queries (pair with RETRIEVAL_DOCUMENT for the docs)
  • CODE_RETRIEVAL_QUERY: Natural-language code search queries
  • QUESTION_ANSWERING: Questions in a QA system
  • FACT_VERIFICATION: Statements to verify against retrieved evidence

Usage examples

Alternative Route Prefix

You can also use the /v1beta/ route prefix instead of /gemini/v1beta/:
[!NOTE] You can also authenticate using the ?key=$ZnapAI_API_KEY query parameter instead of the header if required by your integration. Both prefix routes support both auth styles.

Multimodal embeddings (gemini-embedding-2 only)

All modalities map into the same embedding space. Example passing base64 image data:

Supported modalities and limits

Batch embeddings (batchEmbedContents)

Returns separate embeddings for multiple inputs in a single API call:

Specify task type to improve performance

Task types with Embeddings 2 (gemini-embedding-2)

gemini-embedding-2 does not accept a task_type field. Instead, prefix the task instruction directly into the text you embed. Retrieval use cases (asymmetric format) Single-input use cases (symmetric format) — use the same prefix for query and document. Example structure query:

Task types with Embeddings 001 (gemini-embedding-001)

For gemini-embedding-001, pass the taskType in the request body:

Controlling embedding size

output_dimensionality truncates the output vector. Both models default to 3072 dimensions. Recommended values: 768, 1536, 3072.
[!NOTE] gemini-embedding-2 auto-normalizes truncated dimensions (e.g. 768, 1536) so cosine similarity works correctly out of the box. gemini-embedding-001 requires you to manually L2-normalize non-3072-dim vectors client-side.

Params to Avoid


Model versions

Gemini Embedding 2

Gemini Embedding 001