使用語義相似度模型對文件進行重排。適用於優化搜尋結果和 RAG 應用程式。
請求主體
同步請求逾時: 這個非聊天端點會等待路由到的模型完成處理。大型輸入、長音訊或大量批次可能超過常見的 30s 用戶端預設逾時,因此請將 HTTP 用戶端逾時設定為至少 120s。
要使用的重排模型 ID(例如:qwen3-vl-rerank、qwen3-vl-rerank)。
用於對文件進行排名的查詢語句。最大長度:32,000 個字元。
要進行重排的文件列表(字串)。限制:最多 1,000 份文件;每份文件最多 100,000 個字元;所有文件合計最多 2,000,000 個字元。
要返回的前幾個結果數量。預設為所有文件。必須至少為 1,且不能大於 documents.length。如果供應商日後公開更嚴格的限制,TokenLab 會在這裡文件化並執行。
帶有評分的已排序文件列表。每個結果包含:
index (integer):原始文件索引
relevance_score (number):相關性評分 (0-1)
document (string):原始文本(若 return_documents=true)
curl -X POST "https://api.tokenlab.sh/v1/rerank" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-vl-rerank",
"query": "What is machine learning?",
"documents": [
"Machine learning is a subset of AI",
"The weather is nice today",
"Deep learning uses neural networks"
],
"top_n": 2,
"return_documents": true
}'
import requests
response = requests.post(
"https://api.tokenlab.sh/v1/rerank",
headers={"Authorization": "Bearer sk-your-api-key"},
json={
"model": "qwen3-vl-rerank",
"query": "What is machine learning?",
"documents": [
"Machine learning is a subset of AI",
"The weather is nice today",
"Deep learning uses neural networks"
],
"top_n": 2
}
)
print(response.json())
const response = await fetch('https://api.tokenlab.sh/v1/rerank', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk-your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'qwen3-vl-rerank',
query: 'What is machine learning?',
documents: [
'Machine learning is a subset of AI',
'The weather is nice today',
'Deep learning uses neural networks'
],
top_n: 2
})
});
const data = await response.json();
console.log(data.results);
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
payload := map[string]interface{}{
"model": "qwen3-vl-rerank",
"query": "What is machine learning?",
"documents": []string{
"Machine learning is a subset of AI",
"The weather is nice today",
"Deep learning uses neural networks",
},
"top_n": 2,
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://api.tokenlab.sh/v1/rerank", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer sk-your-api-key")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result["results"])
}
<?php
$ch = curl_init('https://api.tokenlab.sh/v1/rerank');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer sk-your-api-key'
],
CURLOPT_POSTFIELDS => json_encode([
'model' => 'qwen3-vl-rerank',
'query' => 'What is machine learning?',
'documents' => [
'Machine learning is a subset of AI',
'The weather is nice today',
'Deep learning uses neural networks'
],
'top_n' => 2
])
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
print_r($data['results']);
{
"results": [
{
"index": 0,
"relevance_score": 0.95,
"document": "Machine learning is a subset of AI"
},
{
"index": 2,
"relevance_score": 0.82,
"document": "Deep learning uses neural networks"
}
],
"model": "qwen3-vl-rerank",
"usage": {
"prompt_tokens": 45,
"total_tokens": 45
}
}