跳转到主要内容
POST
/
v1
/
rerank
Rerank
curl --request POST \
  --url https://openp.ai/v1/rerank
import requests

url = "https://openp.ai/v1/rerank"

response = requests.post(url)

print(response.text)
const options = {method: 'POST'};

fetch('https://openp.ai/v1/rerank', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://openp.ai/v1/rerank",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://openp.ai/v1/rerank"

	req, _ := http.NewRequest("POST", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://openp.ai/v1/rerank")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://openp.ai/v1/rerank")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
对一组候选文档基于查询进行相关性重排,常用于 RAG 召回后的精排。 完全兼容 Cohere / Jina Rerank 协议。

请求

curl https://openp.ai/v1/rerank \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "rerank-multilingual-v3.0",
    "query": "什么是向量数据库?",
    "documents": [
      "向量数据库存储高维向量,用于相似度检索。",
      "Postgres 是关系型数据库。",
      "FAISS / Milvus 是常见向量索引方案。"
    ],
    "top_n": 2,
    "return_documents": true
  }'

参数

字段类型必填说明
modelstringrerank 模型 ID
querystring查询语句
documentsarray文档数组,可为字符串或 { text } 对象
top_ninteger返回前 N 个,默认全部
return_documentsboolean响应中是否带回原文(默认 false 只返回 index + 分数)
max_chunks_per_docintegerCohere v3,超长文档切片

推荐模型

模型 ID厂商上下文
rerank-multilingual-v3.0Cohere4096
rerank-english-v3.0Cohere4096
jina-reranker-v2-base-multilingualJina1024
bge-reranker-v2-m3BAAI8192
bge-reranker-largeBAAI512

响应

{
  "id": "rerank-...",
  "results": [
    {
      "index": 0,
      "relevance_score": 0.98,
      "document": {"text": "向量数据库存储高维向量,用于相似度检索。"}
    },
    {
      "index": 2,
      "relevance_score": 0.83,
      "document": {"text": "FAISS / Milvus 是常见向量索引方案。"}
    }
  ],
  "meta": {
    "api_version": "1",
    "billed_units": {"search_units": 1}
  }
}
results 已按 relevance_score 降序排列,index 指向原 documents 数组下标。

Python(直接 HTTP)

import requests

resp = requests.post(
    "https://openp.ai/v1/rerank",
    headers={"Authorization": "Bearer sk-..."},
    json={
        "model": "bge-reranker-v2-m3",
        "query": "什么是向量数据库?",
        "documents": ["...", "...", "..."],
        "top_n": 5,
    },
).json()
print(resp["results"])

Cohere SDK

import cohere
client = cohere.Client(api_key="sk-...", base_url="https://openp.ai/v1")

resp = client.rerank(
    model="rerank-multilingual-v3.0",
    query="...",
    documents=["...", "..."],
    top_n=3,
)

计费

query + 所有 documents 的 token 总和计费,具体倍率以模型为准。