> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aihubmax.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini 格式 - 嵌入

> - 适用于所有兼容 Gemini 原生格式的嵌入 API
- 将文本转换为高维向量表示
- 支持多种任务类型：检索、分类、聚类、语义相似度等
- 支持自定义输出维度（降维）




## OpenAPI

````yaml openapi/zh/gemini-format-embeddings.json POST /v1beta/models/{model}:embedContent
openapi: 3.1.0
info:
  title: Gemini Format - Embeddings
  version: '1.0'
servers:
  - url: https://api.aihubmax.com
security:
  - BearerAuth: []
paths:
  /v1beta/models/{model}:embedContent:
    post:
      tags:
        - Text Series > Gemini Format
      summary: Gemini Format - Embeddings
      description: |
        - 适用于所有兼容 Gemini 原生格式的嵌入 API
        - 将文本转换为高维向量表示
        - 支持多种任务类型：检索、分类、聚类、语义相似度等
        - 支持自定义输出维度（降维）
      operationId: gemini-format-embed-content
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
            example: gemini-embedding-2-preview
          description: 嵌入模型名称，如 gemini-embedding-2-preview
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EmbedContentRequest'
            examples:
              simple:
                summary: 单文本嵌入
                description: 最基础的单文本嵌入请求
                value:
                  content:
                    parts:
                      - text: 什么是深度学习？
              with-task-type:
                summary: 指定任务类型和输出维度
                description: 使用 taskType 和 outputDimensionality 控制嵌入行为
                value:
                  content:
                    parts:
                      - text: Transformer 模型如何处理长序列？
                  taskType: RETRIEVAL_QUERY
                  outputDimensionality: 768
              retrieval-document:
                summary: 文档检索嵌入
                description: 用于检索的文档嵌入，带 title 参数
                value:
                  content:
                    parts:
                      - text: >-
                          深度学习是机器学习的一个子领域，通过多层神经网络从数据中学习复杂的模式和表示。它在图像识别、自然语言处理和语音识别等领域取得了突破性进展。
                  taskType: RETRIEVAL_DOCUMENT
                  title: 深度学习概述
      responses:
        '200':
          $ref: '#/components/responses/EmbedContentSuccess'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    EmbedContentRequest:
      type: object
      required:
        - content
      properties:
        content:
          type: object
          description: 要嵌入的内容
          required:
            - parts
          properties:
            parts:
              type: array
              description: >-
                内容部分列表。`gemini-embedding-2-preview`
                支持多模态输入（图片/音频/视频/PDF），旧版模型仅支持文本
              items:
                type: object
                properties:
                  text:
                    type: string
                    description: 要嵌入的文本内容
                  inlineData:
                    type: object
                    description: >-
                      内联二进制数据（base64 编码）。仅 `gemini-embedding-2-preview`
                      支持。可嵌入图片（≤6 张）、音频（≤80 秒）、视频（≤120 秒）、PDF（≤6 页）。
                    required:
                      - mimeType
                      - data
                    properties:
                      mimeType:
                        type: string
                        description: IANA 标准 MIME 类型
                        examples:
                          - image/png
                          - image/jpeg
                          - audio/mp3
                          - audio/wav
                          - video/mp4
                          - video/quicktime
                          - application/pdf
                      data:
                        type: string
                        description: Base64 编码的二进制数据
        taskType:
          type: string
          description: >-
            嵌入任务类型，影响嵌入向量的优化方向。**注意**：`gemini-embedding-2-preview` 不支持此字段，该模型改用
            prompt prefix 方式指定任务类型（如 `task: search result | query: {content}`）
          enum:
            - RETRIEVAL_QUERY
            - RETRIEVAL_DOCUMENT
            - SEMANTIC_SIMILARITY
            - CLASSIFICATION
            - CLUSTERING
            - QUESTION_ANSWERING
            - FACT_VERIFICATION
            - CODE_RETRIEVAL_QUERY
        title:
          type: string
          description: 文档标题，仅在 taskType 为 RETRIEVAL_DOCUMENT 时有效
        outputDimensionality:
          type: integer
          description: 输出向量的维度，用于降维输出。默认 3072
    EmbedContentResponse:
      type: object
      properties:
        embedding:
          type: object
          description: 嵌入结果
          properties:
            values:
              type: array
              description: 嵌入向量值
              items:
                type: number
              example:
                - 0.0123
                - -0.0456
                - 0.0789
                - 0.0234
                - -0.0567
    ErrorResponse400:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求参数无效
            type:
              type: string
              example: invalid_request_error
    ErrorResponse401:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: API密钥无效
            type:
              type: string
              example: authentication_error
    ErrorResponse403:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 访问被拒绝
            type:
              type: string
              example: permission_error
    ErrorResponse429:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求频率超限
            type:
              type: string
              example: rate_limit_error
    ErrorResponse500:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 服务器内部错误
            type:
              type: string
              example: server_error
  responses:
    EmbedContentSuccess:
      description: 嵌入响应
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/EmbedContentResponse'
    BadRequest:
      description: 请求错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse401'
    PaymentRequired:
      description: 余额不足
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Forbidden:
      description: 禁止访问
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse403'
    TooManyRequests:
      description: 请求过多
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse429'
    InternalServerError:
      description: 服务器内部错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse500'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        ## 所有接口均需要使用Bearer Token进行认证 ##

        使用时在请求头中添加：

        `Authorization: Bearer YOUR_API_KEY`

````