SuperAPI AI Directory

rerank-service

Agents & models

View repository

Updated 10-16 00:00

About this skill

Features

Score and rank candidate documents for relevance based on the query statement, improving retrieval accuracy.

Invocation Method

from services.rerank_service.client import RerankServiceClient

client = RerankServiceClient()

query = "什么是机器学习?"
documents = [
    "机器学习是人工智能的一个分支,通过数据训练模型。",
    "今天天气很好,适合出去散步。",
    "深度学习是机器学习的子领域,使用神经网络。"
]

# 完整重排序结果
result = client.rerank(query, documents, top_n=2)
Simplified result: list of (index, score, document) tuples

ranked = client.rerank_documents(query, documents, top_n=2)

Retrieve only the indices of the most relevant documents

indices = client.get_top_indices(query, documents, top_n=2) # -> [0, 2]


## 返回格式
```json
{
  "id": "rerank-xxx",
  "model": "BAAI/bge-reranker-v2-m3",
  "results": [
    {
      "index": 0,
      "document": {"text": "机器学习是人工智能的一个分支..."},
      "relevance_score": 0.999
    },
    {
      "index": 2,
      "document": {"text": "深度学习是机器学习的子领域..."},
      "relevance_score": 0.098
    }
  ]
}