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

# 文本重排序

> `Rerank` 用于文本重排序，通过接收用户的查询文本及候选文本列表，使用模型计算候选文本与查询文本的相关性得分并返回分数。适用于智能问答、信息检索等场景。点击 **Try it** 按钮可快速试用。



## OpenAPI

````yaml /openapi/openapi.json post /paas/v4/rerank
openapi: 3.0.1
info:
  title: ZHIPU AI API
  description: ZHIPU AI 接口提供强大的 AI 能力，包括聊天对话、工具调用和视频生成。
  license:
    name: ZHIPU AI 开发者协议和政策
    url: https://chat.z.ai/legal-agreement/terms-of-service
  version: 1.0.0
  contact:
    name: Z.AI 开发者
    url: https://chat.z.ai/legal-agreement/privacy-policy
    email: user_feedback@z.ai
servers:
  - url: https://open.bigmodel.cn/api/
    description: 开放平台服务
security:
  - bearerAuth: []
tags:
  - name: 模型 API
    description: Chat API
  - name: 工具 API
    description: Web Search API
  - name: Agent API
    description: Agent API
  - name: 文件 API
    description: File API
  - name: 知识库 API
    description: Knowledge API
  - name: 实时 API
    description: Realtime API
  - name: 批处理 API
    description: Batch API
  - name: 助理 API
    description: Assistant API
  - name: 智能体 API（旧）
    description: QingLiu Agent API
paths:
  /paas/v4/rerank:
    post:
      tags:
        - 模型 API
      summary: 文本重排序
      description: >-
        `Rerank`
        用于文本重排序，通过接收用户的查询文本及候选文本列表，使用模型计算候选文本与查询文本的相关性得分并返回分数。适用于智能问答、信息检索等场景。点击
        **Try it** 按钮可快速试用。
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RerankRequest'
            examples:
              文本重排序示例:
                value:
                  model: rerank
                  query: 查询候选文本A
                  top_n: 4
                  documents:
                    - 需要打分的候选文本A
                    - 需要打分的候选文本B
        required: true
      responses:
        '200':
          description: 业务处理成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RerankResponse'
        default:
          description: 请求失败。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    RerankRequest:
      type: object
      required:
        - model
        - query
        - documents
      properties:
        model:
          type: string
          example: rerank
          description: 要调用的模型编码，默认为`rerank`。
          enum:
            - rerank
        query:
          type: string
          example: 查询候选文本A
          description: 查询文本，用于与候选文本进行匹配`query`，最大长度为 `4096` 字符。
        top_n:
          type: integer
          description: 返回得分最高的前 `n` 条结果，默认`0`返回所有。
        documents:
          type: array
          items:
            type: string
          example:
            - 需要打分的候选文本A
            - 需要打分的候选文本B
          description: 需要打分的候选文本数组,最多容纳 `128` 条。单条最大长度为 `4096` 字符。
        return_documents:
          type: boolean
          description: 是否返回原始文本，默认值为`FALSE`。
        return_raw_scores:
          type: boolean
          description: 是否返回原始分数。默认 `FALSE`。
        request_id:
          type: string
          description: >-
            请求唯一标识符。由用户端传递，`ID`长度要求：最少`6`个字符，最多`64`个字符，建议使用`UUID`格式确保唯一性，若未提供平台将自动生成。
          minLength: 6
          maxLength: 64
        user_id:
          type: string
          description: 终端用户的唯一`ID`
    RerankResponse:
      type: object
      properties:
        created:
          type: integer
          format: int64
          example: 1732083164
        id:
          type: string
          example: 20241120141244890ab4ee4af84acf
          description: 智谱开放平台生成的任务序号，调用请求结果接口时请使用此序号
        request_id:
          type: string
          example: '1111111111'
          description: 用户在客户端请求时提交的任务编号或者平台生成的任务编号
        results:
          type: array
          items:
            $ref: '#/components/schemas/RerankResult'
        usage:
          $ref: '#/components/schemas/RerankUsage'
      required:
        - id
        - results
        - usage
    Error:
      type: object
      properties:
        error:
          required:
            - code
            - message
          type: object
          properties:
            code:
              type: string
            message:
              type: string
    RerankResult:
      type: object
      properties:
        document:
          type: string
          example: Washington, D.C. is the capital of the United States.
          description: 原文本
        index:
          type: integer
          example: 1
        relevance_score:
          type: number
          format: float
          example: 0.99866986
      required:
        - document
        - index
        - relevance_score
    RerankUsage:
      type: object
      properties:
        prompt_tokens:
          type: integer
          example: 72
        total_tokens:
          type: integer
          example: 72
      required:
        - prompt_tokens
        - total_tokens
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        标准的 HTTP Bearer 认证方式，在 [API
        Keys](https://bigmodel.cn/usercenter/proj-mgmt/apikeys) 页面获取密钥。

````