Method: models.batchEmbedContents

Generates multiple embeddings from the model given input text in a synchronous call.

HTTP request

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

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
{
  "requests": [
    {
      object (EmbedContentRequest)
    }
  ]
}
Fields
requests[]

object (EmbedContentRequest)

Required. Embed requests for the batch. The model in each of these requests must match the model specified BatchEmbedContentsRequest.model.

Response body

The response to a BatchEmbedContentsRequest.

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

JSON representation
{
  "embeddings": [
    {
      object (ContentEmbedding)
    }
  ]
}
Fields
embeddings[]

object (ContentEmbedding)

Output only. The embeddings for each request, in the same order as provided in the batch request.

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.

EmbedContentRequest

Request containing the Content for the model to embed.

JSON representation
{
  "model": string,
  "content": {
    object (Content)
  },
  "taskType": enum (TaskType),
  "title": string
}
Fields
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}

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.