跳轉到主要內容

Documentation Index

Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt

Use this file to discover all available pages before exploring further.

使用語義相似度模型對文件進行重排。適用於優化搜尋結果和 RAG 應用程式。

請求主體

同步請求逾時: 這個非聊天端點會等待路由到的模型完成處理。大型輸入、長音訊或大量批次可能超過常見的 30s 用戶端預設逾時,因此請將 HTTP 用戶端逾時設定為至少 120s
model
string
必填
要使用的重排模型 ID(例如:BAAI/bge-reranker-v2-m3qwen3-rerank)。
query
string
必填
用於對文件進行排名的查詢語句。最大長度:32,000 個字元。
documents
array
必填
要進行重排的文件列表(字串)。限制:最多 1,000 份文件;每份文件最多 100,000 個字元;所有文件合計最多 2,000,000 個字元。
top_n
integer
要返回的前幾個結果數量。預設為所有文件。必須至少為 1,且不能大於 documents.length。TokenLab 目前沒有已治理的供應商專屬更低硬上限;若供應商日後發布此類上限,必須先加入 rerank request-shape truth,再對外文件化或執行。
return_documents
boolean
預設值:"false"
是否在回應中包含原始文件文本。

回應

results
array
帶有評分的已排序文件列表。每個結果包含:
  • index (integer):原始文件索引
  • relevance_score (number):相關性評分 (0-1)
  • document (string):原始文本(若 return_documents=true
model
string
用於重排的模型。
usage
object
Token 使用量統計。
curl -X POST "https://api.tokenlab.sh/v1/rerank" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "BAAI/bge-reranker-v2-m3",
    "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
  }'
{
  "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": "BAAI/bge-reranker-v2-m3",
  "usage": {
    "prompt_tokens": 45,
    "total_tokens": 45
  }
}