跳转到内容
EN

重排文档

POST/model/v1/rerank● 支持

官方文档 ↗

请求体

  • modelstring必填

    Rerank model id; list candidates with listModels?type=reranking. Router support (supported): Verified to take effect.

    已验证生效。

  • querystring必填

    Query to rank the documents against, at least 1 character. Router support (supported): Verified to take effect.

    已验证生效。

  • documentsarray必填◐ 部分支持

    Documents to rank, as plain strings, at least one. Router support (partial): Only string arrays are supported; object arrays return 400.

    只支持字符串数组;对象数组返回 400。

  • top_ninteger可选

    Number of best results to return, at least 1; omit it to return every document. Router support (supported): Controls returned result count; zero returns 400.

    控制返回条数;0 返回 400。

  • return_documentsboolean可选○ 未支持

    bge-reranker-base 返回 400;只支持 model、query、documents、top_n。

  • max_tokens_per_docinteger可选○ 未支持

    bge-reranker-base 返回 400;只支持 model、query、documents、top_n。

  • rank_fieldsarray可选○ 未支持

    bge-reranker-base 返回 400;只支持 model、query、documents、top_n。

  • max_chunks_per_docinteger可选○ 未支持

    bge-reranker-base 返回 400;只支持 model、query、documents、top_n。

  • userstring可选○ 未支持

    bge-reranker-base 返回 400;只支持 model、query、documents、top_n。

返回

200

标准请求字段;不能表达的参数返回 input_not_representable。

鉴权、限流、参数校验等平台错误按 problem+json 返回;OCR 的错误也为 problem+json,其它模型调用的错误按该端点所属格式(OpenAI 或 Anthropic)返回,参见 错误码

请求示例

curl
curl https://api.deepraxis.com/model/v1/rerank \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"bge-reranker-base","query":"What is the capital of France?","documents":["Paris is the capital of France.","Berlin is the capital of Germany."],"top_n":2}'
Python
import requests

opts = dict(
    base_url="https://api.deepraxis.com/model/v1",
    api_key="$PRAXIS_API_KEY",
)

resp = requests.post(
    f"{opts['base_url']}/rerank",
    headers={"Authorization": f"Bearer {opts['api_key']}"},
    json={
        "model": "bge-reranker-base",
        "query": "What is the capital of France?",
        "documents": ["Paris is the capital of France.", "Berlin is the capital of Germany."],
        "top_n": 2,
    },
)
print(resp.json())
TypeScript
const opts = {
  baseURL: "https://api.deepraxis.com/model/v1",
  apiKey: "$PRAXIS_API_KEY",
};

const resp = await fetch(`${opts.baseURL}/rerank`, {
  method: "POST",
  headers: { Authorization: `Bearer ${opts.apiKey}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "bge-reranker-base",
    query: "What is the capital of France?",
    documents: ["Paris is the capital of France.", "Berlin is the capital of Germany."],
    top_n: 2,
  }),
});
console.log(await resp.json());

响应示例 200

{
  "results": [
    {
      "index": 0,
      "relevance_score": 0.997886598110199
    },
    {
      "index": 1,
      "relevance_score": 0.0251021608710289
    }
  ]
}

响应

HTTP 200

Cohere v2 rerank results.

application/json

名称 类型 说明
results array<object> Results ordered by relevance, best first. Each entry points back to a document with index.
results[].index integer Zero-based position of the document in the request documents array.
results[].relevance_score number Relevance of the document to the query, from 0 to 1; larger is more relevant.