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

# 重排序

> 根据查询对文档列表进行相关性重排序，返回按相关性排序的结果。

## 请求头

**Authorization** `string` *required*

使用 Bearer Token 认证。格式：`Authorization: Bearer sk-xxxxxx`

## 请求体

格式：`application/json`

**model** `string` *required*

模型 ID

**query** `string` *required*

查询文本

**documents** `(string | object)[]` *required*

要重排序的文档列表

**top\_n** `integer`

返回前 N 个结果

**return\_documents** `boolean` (default: false)

是否在结果中返回原始文档内容

## 响应

### 200 成功重排序

格式：`application/json`

**id** `string`

重排序任务 ID

**results** `object[]`

重排序结果列表

**属性**

**index** `integer`

原始文档索引

**relevance\_score** `number`

相关性得分

**document** `object`

原始文档内容（仅当 `return_documents` 为 `true` 时返回）

**meta** `object`

元数据

```bash cURL theme={"dark"}
curl -X POST "https://t.ato2.nodesms.com/v1/rerank" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "rerank-english-v2.0",
    "query": "What is the capital of the United States?",
    "documents": [
      "Carson City is the capital city of the American state of Nevada.",
      "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
      "Washington, D.C. is the capital of the United States.",
      "Capital punishment has existed in the United States since before it was a country."
    ],
    "top_n": 3
  }'
```

```python Python theme={"dark"}
from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxxxx",
    base_url="https://t.ato2.nodesms.com/v1"
)

response = client.post(
    "/rerank",
    json={
        "model": "rerank-english-v2.0",
        "query": "What is the capital of the United States?",
        "documents": [
            "Carson City is the capital city of the American state of Nevada.",
            "Washington, D.C. is the capital of the United States."
        ],
        "top_n": 2
    }
)
print(response.json())
```

```json 200 theme={"dark"}
{
  "id": "string",
  "results": [
    {
      "index": 2,
      "relevance_score": 0.9871293,
      "document": {}
    },
    {
      "index": 1,
      "relevance_score": 0.3456789,
      "document": {}
    }
  ],
  "meta": {}
}
```


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