API 參考
Rerank
透過單一端點使用 Cohere、Jina AI 及其他供應商的模型進行 Rerank,重新排序文件相關性以提升搜尋與檢索品質。
端點
http
POST https://api.tokspan.com/v1/rerank請求參數
| 參數 | 類型 | 必要 | 說明 |
|---|---|---|---|
| model | string | 是 | Rerank 模型 ID(例如 cohere-rerank-v3、jina-reranker-v2) |
| query | string | 是 | 用於評估文件的搜尋查詢 |
| documents | array | 是 | 要重新排序的文件字串或物件清單 |
| top_n | integer | 否 | 僅返回前 N 個結果。預設值:返回全部 |
| return_documents | boolean | 否 | 在回應中包含文件文字。預設值:true |
範例
發送查詢及候選文件清單,接收相關性評分結果:
python
import requests
response = requests.post(
"https://api.tokspan.com/v1/rerank",
headers={
"Authorization": "Bearer sk-your-key",
"Content-Type": "application/json",
},
json={
"model": "cohere-rerank-v3",
"query": "What is the capital of France?",
"documents": [
"Paris is the capital of France.",
"Berlin is the capital of Germany.",
"France is a country in Europe.",
],
"top_n": 2,
},
)
for result in response.json()["results"]:
print(f"Score: {result['relevance_score']:.3f} — {result['document']['text']}")常見用例
- RAG 管線 — 在傳遞給 LLM 前重新排序檢索區塊以獲得更準確的答案
- 混合搜尋 — 結合關鍵字(BM25)和向量搜尋結果,然後重新排序以獲得最佳相關性
- 多階段檢索 — 粗略檢索 → 重排序 → 生成管線
可用模型
支援的重排序模型包含 Cohere Rerank v3、Jina Reranker v2 和 BGE-Reranker。請參閱模型頁面了解完整目錄及各模型定價。