文件重排序
curl --request POST \
--url https://api.mixroute.ai/v1/rerankimport requests
url = "https://api.mixroute.ai/v1/rerank"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.mixroute.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://api.mixroute.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://api.mixroute.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://api.mixroute.ai/v1/rerank")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mixroute.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文本系列
文件重排序
使用 Cohere Rerank v4.0 Fast 和 Pro 進行搜尋與 RAG 重排序。
文件重排序
curl --request POST \
--url https://api.mixroute.ai/v1/rerankimport requests
url = "https://api.mixroute.ai/v1/rerank"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.mixroute.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://api.mixroute.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://api.mixroute.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://api.mixroute.ai/v1/rerank")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mixroute.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根據查詢對候選文件排序,返回相關性分數和原始文件索引,不生成回答。
支援模型
| 模型 ID | 說明 |
|---|---|
rerank-v4.0-pro | Cohere 注重排序質量的多語言相關性重排序模型。 |
rerank-v4.0-fast | Cohere 注重響應速度的多語言相關性重排序模型。 |
請求欄位
| 欄位 | 說明 |
|---|---|
model | 必填:rerank-v4.0-fast 或 rerank-v4.0-pro。 |
query | 必填,查詢字串。 |
documents | 必填,文件字串陣列。 |
top_n | 可選,返回結果數,不超過文件數。 |
請求示例
curl --request POST "https://api.mixroute.ai/v1/rerank" \
--header "Authorization: Bearer $MIXROUTE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "rerank-v4.0-pro",
"query": "API documentation",
"documents": [
"An API reference for developers.",
"A recipe for soup."
],
"top_n": 1
}'
響應
讀取results[].index 和 results[].relevance_score。index 指向原始輸入陣列;不要假設響應一定包含 document 物件。分數用於排序,不是校準後的機率。
import os
import requests
documents = ["An API reference for developers.", "A recipe for soup."]
response = requests.post(
"https://api.mixroute.ai/v1/rerank",
headers={"Authorization": "Bearer " + os.environ["MIXROUTE_API_KEY"]},
json={"model": "rerank-v4.0-pro", "query": "API documentation",
"documents": documents, "top_n": 1},
timeout=60,
)
response.raise_for_status()
for item in response.json()["results"]:
print(item["relevance_score"], documents[item["index"]])