Embeddings are a numerical representation of text input that open up a number of unique use cases, such as clustering, similarity measurement and information retrieval. For an introduction, check out the Embeddings guide.
Method: models.embedContent
Generates a text embedding vector from the input Content
using the specified Gemini Embedding model.
Endpoint
post https://generativelanguage.googleapis.com/v1beta/{model=models/*}:embedContentPath 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}
It takes the form models/{model}
.
Request body
The request body contains data with the following structure:
Required. The content to embed. Only the parts.text
fields will be counted.
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.
outputDimensionality
integer
Optional. Optional reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end. Supported by newer models since 2024 only. You cannot set this value if using the earlier model (models/embedding-001
).
Example request
Python
Node.js
Shell
Response body
The response to an EmbedContentRequest
.
If successful, the response body contains data with the following structure:
Output only. The embedding generated from the input content.
JSON representation |
---|
{
"embedding": {
object ( |
Method: models.batchEmbedContents
- Endpoint
- Path parameters
- Request body
- Response body
- Authorization scopes
- Example request
- EmbedContentRequest
Generates multiple embedding vectors from the input Content
which consists of a batch of strings represented as EmbedContentRequest
objects.
Endpoint
post https://generativelanguage.googleapis.com/v1beta/{model=models/*}:batchEmbedContentsPath 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}
It takes the form models/{model}
.
Request body
The request body contains data with the following structure:
Required. Embed requests for the batch. The model in each of these requests must match the model specified BatchEmbedContentsRequest.model
.
Example request
Python
Node.js
Shell
Response body
The response to a BatchEmbedContentsRequest
.
If successful, the response body contains data with the following structure:
Output only. The embeddings for each request, in the same order as provided in the batch request.
JSON representation |
---|
{
"embeddings": [
{
object ( |
EmbedContentRequest
Request containing the Content
for the model to embed.
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}
Required. The content to embed. Only the parts.text
fields will be counted.
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.
outputDimensionality
integer
Optional. Optional reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end. Supported by newer models since 2024 only. You cannot set this value if using the earlier model (models/embedding-001
).
ContentEmbedding
A list of floats representing an embedding.
values[]
number
The embedding values.
JSON representation |
---|
{ "values": [ number ] } |
TaskType
Type of task for which the embedding will be used.
Enums | |
---|---|
TASK_TYPE_UNSPECIFIED |
Unset value, which will default to one of the other enum values. |
RETRIEVAL_QUERY |
Specifies the given text is a query in a search/retrieval setting. |
RETRIEVAL_DOCUMENT |
Specifies the given text is a document from the corpus being searched. |
SEMANTIC_SIMILARITY |
Specifies the given text will be used for STS. |
CLASSIFICATION |
Specifies that the given text will be classified. |
CLUSTERING |
Specifies that the embeddings will be used for clustering. |
QUESTION_ANSWERING |
Specifies that the given text will be used for question answering. |
FACT_VERIFICATION |
Specifies that the given text will be used for fact verification. |