> ## 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.

> ## Agent Instructions
> - Base URLs: models `https://api.aisa.one/v1` (Gemini GenerateContent: `https://api.aisa.one/v1beta`); data APIs `https://api.aisa.one/apis/v1`. The `servers` of each operation in https://aisa.one/openapi.yaml is authoritative.
> - Auth: `Authorization: Bearer $AISA_API_KEY`. Never print, log, or commit the key.
> - MCP (preferred for agents): `https://mcp.aisa.one/mcp`, signed in with OAuth, so there is no key to paste.
> - Agent Skill: `npx skills add AIsa-team/agent-skills --skill aisa`. Fallback with the AIsa CLI: `aisa skills install aisa`.
> - Spending: docs, https://aisa.one/models, https://aisa.one/api, `/v1/models`, and MCP `search`, `list_categories`, `get_details`, `batch_quote`, and the `account` operation are free. Quote the exact calls before running them (MCP `batch_quote`, CLI `aisa quote --json`). If the quote reports `auto_execute_eligible: true`, run it unless the user set a tighter limit or asked only for a quote. Otherwise, tell the user in one message the planned calls, the quoted price, and a total USD budget for the task, then wait for approval. Direct HTTP calls follow the stricter rule at https://aisa.one/docs/get-started/cli.md#direct-http-fallback. Do not make paid calls to test availability. Full rule: https://aisa.one/llms.txt

# 重排序文档

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

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

通过 AIsa API 路径 `/v1/rerank` 提供服务——OpenAI 兼容。按 token 计费；`usage.total_tokens` 字段给出每次请求计费的 token 数。

```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"])
```

## 请求规范

* **方法与路径:** POST /rerank
* **请求 URL 模板:** `https://api.aisa.one/v1/rerank`

[完整 OpenAPI 定义](https://aisa.one/docs/reference-contracts/zh/jina.json)

有效请求声明（包括认证和引用的 schema）：

```json theme={null}
{
  "operationId": "createRerank",
  "method": "POST",
  "path": "/rerank",
  "servers": [
    {
      "url": "https://api.aisa.one/v1"
    }
  ],
  "parameters": [],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "example": {
          "documents": [
            "Paris is the capital of France.",
            "Berlin is the capital of Germany.",
            "The Eiffel Tower is in Paris."
          ],
          "model": "jina-reranker-v3",
          "query": "What is the capital of France?",
          "top_n": 2
        },
        "schema": {
          "properties": {
            "documents": {
              "description": "要重排序的非空文档字符串数组。",
              "example": [
                "Paris is the capital of France.",
                "Berlin is the capital of Germany.",
                "The Eiffel Tower is in Paris."
              ],
              "items": {
                "type": "string"
              },
              "minItems": 1,
              "type": "array"
            },
            "model": {
              "description": "重排序模型名称。",
              "example": "jina-reranker-v3",
              "type": "string"
            },
            "query": {
              "description": "用于对文档排序的非空查询字符串。",
              "example": "What is the capital of France?",
              "type": "string"
            },
            "top_n": {
              "description": "可选。只返回相关性最高的前 N 个文档。",
              "example": 2,
              "type": "integer"
            }
          },
          "required": [
            "model",
            "query",
            "documents"
          ],
          "type": "object"
        }
      }
    },
    "required": true
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "bearerFormat": "API Key",
        "scheme": "bearer",
        "type": "http"
      }
    }
  }
}
```


## OpenAPI

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

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.