批量生成向量嵌入
一次请求为多段文本生成向量嵌入。
/google/v1beta/models/{modelsId}:batchEmbedContents● 支持请求参数
modelstring必填path: 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}`
requestsarray必填Required. Embed requests for the batch. The model in each of these requests must match the model specified `BatchEmbedContentsRequest.model`.
支持 1–100 项,返回顺序与输入一致;维度必须一致。
▸ 展开子字段(6)
contentobject可选◐ 部分支持Required. The content to embed. Only the `parts.text` fields will be counted.
仅文本部件生效;图片(含多模态嵌入模型)返回 400。
embedContentConfigobject可选◐ 部分支持Optional. Configuration for the EmbedContent request.
仅 outputDimensionality 可用(受模型限制);autoTruncate、documentOcr、audioTrackExtraction 等其余配置返回 400。
▸ 展开子字段(6)
audioTrackExtractionboolean可选○ 未支持Optional. Whether to extract audio from video content.
传入返回 400;此嵌入配置当前不支持。
autoTruncateboolean可选○ 未支持Optional. Whether to silently truncate the input content if it's longer than the maximum sequence length.
传入返回 400;此嵌入配置当前不支持。
documentOcrboolean可选○ 未支持Optional. Whether to enable OCR for document content.
传入返回 400;此嵌入配置当前不支持。
outputDimensionalityinteger可选◐ 部分支持Optional. Reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end.
text-embedding-3-small、qwen3-vl-embedding 支持已测维度;doubao-embedding-vision 需至少 1024;bge-m3、qwen3-embedding-0.6b 报错。
taskTypestring可选○ 未支持Optional. The task type of the embedding.
传入返回 400;此嵌入配置当前不支持。
titlestring可选○ 未支持Optional. The title for the text.
传入返回 400;此嵌入配置当前不支持。
modelstring可选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}`
必须与 URL 路径中的模型一致,否则返回 400。
outputDimensionalityinteger可选◐ 部分支持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`).
text-embedding-3-small、qwen3-vl-embedding 支持已测维度;doubao-embedding-vision 需至少 1024;bge-m3、qwen3-embedding-0.6b 报错。
taskTypestring可选○ 未支持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`).
传入返回 400。
titlestring可选○ 未支持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.
传入返回 400。
返回
200
requests 中每一项的约束与 embedContent 相同(文本部件、同上拒绝规则);批量内 所有条目的 outputDimensionality 必须一致。当前官方 JS 与 Python SDK 的 embedContent 调用实际走的就是这个批量端点。
错误按 Gemini API 格式返回,参见 错误码
响应
HTTP 200
Successful response
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| embeddings | array<object> | Output only. The embeddings for each request, in the same order as provided in the batch request. |
| embeddings[].shape | array<integer> | This field stores the soft tokens tensor frame shape (e.g. [1, 1, 256, 2048]). |
| embeddings[].values | array<number> | The embedding values. This is for 3P users only and will not be populated for 1P calls. |
| usageMetadata | object | Output only. The usage metadata for the request. |
| usageMetadata.promptTokenCount | integer | Output only. Number of tokens in the prompt. |
| usageMetadata.promptTokenDetails | array<object> | Output only. List of modalities that were processed in the request input. |