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

# 重排序文档

> 使用 Jina rerank 按与查询的相关性对文档重新排序，通过 OpenAI 兼容的 AIsa 中继提供服务。

使用 `jina-reranker-v3` 针对某个 `query` 对文档列表重排序。需要提供非空的 `query` 和非空的 `documents` 数组；结果按 `relevance_score` 排序返回。可选的 `top_n` 用于只返回最相关的若干文档。它与基于 embedding 的检索天然互补：先用 embedding 召回候选，再用重排序确定最终顺序。

通过 AIsa 中继路径 `/v1/rerank` 提供服务——OpenAI 兼容。按 token 计费，**每 100 万 tokens \$0.050**；`usage.total_tokens` 字段给出每次请求计费的 token 数。

<CodeGroup>
  ```bash curl theme={null}
  curl https://api.aisa.one/v1/rerank \
    -H "Authorization: Bearer $AISA_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "jina-reranker-v3",
      "query": "What is the capital of France?",
      "documents": [
        "Paris is the capital of France.",
        "Berlin is the capital of Germany.",
        "The Eiffel Tower is in Paris."
      ],
      "top_n": 2
    }'
  ```

  ```python Python theme={null}
  import requests

  resp = requests.post(
      "https://api.aisa.one/v1/rerank",
      headers={"Authorization": "Bearer sk-aisa-..."},
      json={
          "model": "jina-reranker-v3",
          "query": "What is the capital of France?",
          "documents": [
              "Paris is the capital of France.",
              "Berlin is the capital of Germany.",
              "The Eiffel Tower is in Paris.",
          ],
          "top_n": 2,
      },
  )
  print(resp.json()["results"])
  ```
</CodeGroup>


## OpenAPI

````yaml openapi/zh/jina.json POST /rerank
openapi: 3.0.3
info:
  title: Jina Embeddings & Rerank API
  version: 1.0.0
  description: >-
    通过 AIsa 中继（OpenAI 兼容）路径提供的 Jina embedding 和重排序服务。包含文本
    embedding（jina-embeddings-v3 和 jina-embeddings-v5-text-small，输出均为 1024
    维）以及文档重排序（jina-reranker-v3）。两个 endpoint 均按 token 计费，每 100 万 tokens $0.050。
servers:
  - url: https://api.aisa.one/v1
security:
  - BearerAuth: []
tags:
  - name: Embeddings & Rerank
paths:
  /rerank:
    post:
      summary: 重排序文档
      description: >-
        使用 jina-reranker-v3 针对某个 query 对文档列表重排序，返回按相关性分数排序的文档。通过 AIsa 中继路径
        /v1/rerank 提供服务。按 token 计费，每 100 万 tokens $0.050。
      operationId: createRerank
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - query
                - documents
              properties:
                model:
                  type: string
                  description: 重排序模型名称。
                  example: jina-reranker-v3
                query:
                  type: string
                  description: 用于对文档排序的非空查询字符串。
                  example: What is the capital of France?
                documents:
                  type: array
                  description: 要重排序的非空文档字符串数组。
                  minItems: 1
                  items:
                    type: string
                  example:
                    - Paris is the capital of France.
                    - Berlin is the capital of Germany.
                    - The Eiffel Tower is in Paris.
                top_n:
                  type: integer
                  description: 可选。只返回相关性最高的前 N 个文档。
                  example: 2
            example:
              model: jina-reranker-v3
              query: What is the capital of France?
              documents:
                - Paris is the capital of France.
                - Berlin is the capital of Germany.
                - The Eiffel Tower is in Paris.
              top_n: 2
      responses:
        '200':
          description: 按相关性排序的重排序结果。
          content:
            application/json:
              schema:
                type: object
                properties:
                  model:
                    type: string
                    example: jina-reranker-v3
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                          description: 该文档在原始请求数组中的索引。
                          example: 0
                        relevance_score:
                          type: number
                          format: float
                          example: 0.98
                        document:
                          type: object
                          properties:
                            text:
                              type: string
                              example: Paris is the capital of France.
                  usage:
                    type: object
                    properties:
                      total_tokens:
                        type: integer
                        example: 27
              example:
                model: jina-reranker-v3
                results:
                  - index: 0
                    relevance_score: 0.98
                    document:
                      text: Paris is the capital of France.
                  - index: 2
                    relevance_score: 0.71
                    document:
                      text: The Eiffel Tower is in Paris.
                usage:
                  total_tokens: 27
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key

````