Method: models.embedContent

Generates an embedding from the model given an input Content.

HTTP request

POST https://generativelanguage.googleapis.com/v1/{model=models/*}:embedContent

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
model

string

Required. The model's resource name. This serves as an ID for the Model to use.

This name should match a model name returned by the models.list method.

Format: models/{model}

Request body

The request body contains data with the following structure:

JSON representation
{
  "content": {
    object (Content)
  },
  "taskType": enum (TaskType),
  "title": string
}
Fields
content

object (Content)

Required. The content to embed. Only the parts.text fields will be counted.

taskType

enum (TaskType)

Optional. Optional task type for which the embeddings will be used. Can only be set for models/embedding-001.

title

string

Optional. An optional title for the text. Only applicable when TaskType is RETRIEVAL_DOCUMENT.

Note: Specifying a title for RETRIEVAL_DOCUMENT provides better quality embeddings for retrieval.

Response body

The response to an EmbedContentRequest.

If successful, the response body contains data with the following structure:

JSON representation
{
  "embedding": {
    object (ContentEmbedding)
  }
}
Fields
embedding

object (ContentEmbedding)

Output only. The embedding generated from the input content.

Authorization scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/generative-language
  • https://www.googleapis.com/auth/generative-language.tuning
  • https://www.googleapis.com/auth/generative-language.tuning.readonly
  • https://www.googleapis.com/auth/generative-language.retriever
  • https://www.googleapis.com/auth/generative-language.retriever.readonly

For more information, see the Authentication Overview.