embeddings
Creates, updates, deletes, gets or lists an embeddings resource.
Overview
| Name | embeddings |
| Type | Resource |
| Id | gemini.models.embeddings |
Fields
The following fields are returned by SELECT queries:
- embed_content
| Name | Datatype | Description |
|---|---|---|
embedding | object | Output only. The embedding generated from the input content. |
usageMetadata | object | Output only. The usage metadata for the request. |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
embed_content | select | modelsId | content, taskType, title, model, embedContentConfig, outputDimensionality | Generates a text embedding vector from the input Content using the specified Gemini Embedding model. |
async_batch_embed_content | exec | modelsId | Enqueues a batch of EmbedContent requests for batch processing. We have a BatchEmbedContents handler in GenerativeService, but it was synchronized. So we name this one to be Async to avoid confusion. |
Parameters
Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.
| Name | Datatype | Description |
|---|---|---|
modelsId | string | |
content | object | The base structured datatype containing multi-part content of a message. A Content includes a role field designating the producer of the Content and a parts field containing multi-part data that contains the content of the message turn. |
embedContentConfig | object | Configurations for the EmbedContent request. |
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 ListModels method. Format: models/{model} |
outputDimensionality | integer | Optional. Deprecated: Please use EmbedContentConfig.output_dimensionality instead. 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). |
taskType | string | Optional. Deprecated: Please use EmbedContentConfig.task_type instead. Optional task type for which the embeddings will be used. Not supported on earlier models (models/embedding-001). |
title | string | Optional. Deprecated: Please use EmbedContentConfig.title instead. 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. |
SELECT examples
- embed_content
Generates a text embedding vector from the input Content using the specified Gemini Embedding model.
- Query Shape
- Query Example
SELECT
embedding,
usageMetadata
FROM gemini.models.embeddings
WHERE modelsId = '{{ modelsId }}' -- required
AND content = '{{ content }}'
AND taskType = '{{ taskType }}'
AND title = '{{ title }}'
AND model = '{{ model }}'
AND embedContentConfig = '{{ embedContentConfig }}'
AND outputDimensionality = '{{ outputDimensionality }}'
;
SELECT
JSON_EXTRACT(embedding, '$.values[0]') AS first_dimension
FROM gemini.models.embeddings
WHERE modelsId = 'gemini-embedding-001'
AND content = '{"parts":[{"text":"stackql lets you query cloud APIs with SQL"}]}'
;
Lifecycle Methods
- async_batch_embed_content
Enqueues a batch of EmbedContent requests for batch processing. We have a BatchEmbedContents handler in GenerativeService, but it was synchronized. So we name this one to be Async to avoid confusion.
EXEC gemini.models.embeddings.async_batch_embed_content
@modelsId='{{ modelsId }}' --required
@@json=
'{
"batch": "{{ batch }}"
}'
;