Skip to content

Rerank API

根据查询对文档或段落进行相关性重排序。兼容 Cohere Rerank API 格式。适用于 RAG 管线、搜索结果优化和上下文窗口优化。

基础 URL: https://api.jarvisclaw.ai/v1

认证

方式Header描述
API KeyAuthorization: Bearer sk-...平台自动处理计费
x402PAYMENT-SIGNATUREAgent 按调用付费

端点

POST /v1/rerank

根据查询对文档列表进行相关性重排序。

请求

json
{
  "model": "cohere/rerank-v3.5",
  "query": "What is the capital of France?",
  "documents": [
    "Paris is the capital of France.",
    "Berlin is the capital of Germany.",
    "France is a country in Europe.",
    "The Eiffel Tower is in Paris."
  ],
  "top_n": 3,
  "return_documents": true
}

参数

参数类型必填描述
modelstring重排序模型
querystring用于排序的搜索查询
documentsarray待重排序的文本字符串或对象列表
top_ninteger仅返回前 N 个结果(默认:全部)
return_documentsboolean是否在响应中包含文档文本(默认:false)

响应

json
{
  "id": "rerank-abc123",
  "results": [
    {
      "index": 0,
      "relevance_score": 0.98,
      "document": { "text": "Paris is the capital of France." }
    },
    {
      "index": 3,
      "relevance_score": 0.82,
      "document": { "text": "The Eiffel Tower is in Paris." }
    },
    {
      "index": 2,
      "relevance_score": 0.45,
      "document": { "text": "France is a country in Europe." }
    }
  ],
  "meta": {
    "billed_units": { "search_units": 1 }
  }
}

快速开始

python
import httpx

response = httpx.post(
    "https://api.jarvisclaw.ai/v1/rerank",
    headers={"Authorization": "Bearer sk-your-api-key"},
    json={
        "model": "cohere/rerank-v3.5",
        "query": "machine learning frameworks",
        "documents": [
            "TensorFlow is a popular ML framework by Google.",
            "React is a JavaScript UI library.",
            "PyTorch is widely used for deep learning research.",
            "Django is a Python web framework."
        ],
        "top_n": 2,
        "return_documents": True
    }
)
print(response.json())
bash
curl https://api.jarvisclaw.ai/v1/rerank \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cohere/rerank-v3.5",
    "query": "machine learning frameworks",
    "documents": [
      "TensorFlow is a popular ML framework by Google.",
      "React is a JavaScript UI library.",
      "PyTorch is widely used for deep learning research."
    ],
    "top_n": 2,
    "return_documents": true
  }'

可用模型

当前没有上架任何重排序模型

/v1/rerank 路由已注册且兼容 Cohere 格式,但当前模型清单(GET /v1/models)中不含任何重排序 模型 —— 因此指定下表模型的请求会被判为未知模型,直到你的部署启用了重排序渠道。

构建之前请先查询 GET /v1/models

以下是此端点设计代理的模型参考列表:

模型供应商描述
cohere/rerank-v3.5Cohere最新多语言重排序模型
cohere/rerank-english-v3.0Cohere英语优化重排序
cohere/rerank-multilingual-v3.0Cohere多语言重排序
jina/jina-reranker-v2Jina AI快速精准重排序器

使用场景

  • RAG 管线 — 在输入 LLM 前对检索到的片段进行重排序
  • 搜索优化 — 改善搜索结果排序
  • 上下文优化 — 为有限的上下文窗口选择最相关的文档
  • 多阶段检索 — 粗检索 → 重排序 → LLM 生成