home / skills / lin-a1 / skills-agent / rerank_service

rerank_service skill

/services/rerank_service

This skill reranks search results by scoring and ordering candidate documents with a deep learning model to boost top-k accuracy.

npx playbooks add skill lin-a1/skills-agent --skill rerank_service

Review the files below or copy the command above to add this skill to your agents.

Files (4)
SKILL.md
1.4 KB
---
name: rerank-service
description: 文档重排序服务(Reranker)。基于深度学习模型对检索候选结果进行细粒度相关性打分与重新排序,显著提升检索结果的精准度(Top-K 准确率)。
---

## 功能
根据查询语句对候选文档进行相关性评分和排序,提升检索准确性。

## 调用方式
```python
from services.rerank_service.client import RerankServiceClient

client = RerankServiceClient()

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

# 完整重排序结果
result = client.rerank(query, documents, top_n=2)

# 简化结果:(索引, 分数, 文档) 元组列表
ranked = client.rerank_documents(query, documents, top_n=2)

# 只获取最相关的文档索引
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
    }
  ]
}
```

Overview

This skill is a document reranking service that refines retrieval results by scoring candidate documents with a deep learning reranker. It boosts Top-K accuracy by assigning fine-grained relevance scores and returning a reordered list or top indices. The service exposes simple client calls for full results, compact tuples, or just top indices.

How this skill works

The reranker takes a query and a set of candidate documents, computes relevance scores using a pretrained deep learning model, and sorts documents by score. It can return structured results with metadata, compact (index, score, text) tuples, or only the top document indices for downstream use. Responses include model id, per-item scores, and original document text.

When to use it

  • After an initial retrieval step to improve precision of top results.
  • When you need fine-grained relevance ordering for user-facing search results.
  • To rerank candidates from vector or lexical search before ranking fusion.
  • When downstream tasks depend on most-relevant documents (QA, summarization).
  • To measure or improve Top-K accuracy during evaluation.

Best practices

  • Feed a focused candidate set (dozens to a few hundred) rather than the entire corpus for cost and latency efficiency.
  • Normalize or truncate long documents to avoid input length issues and maintain consistent scoring.
  • Combine with a fast retriever (BM25 or vector search) to produce high-quality candidates before reranking.
  • Use the returned relevance scores to threshold or merge results across sources.
  • Cache reranker outputs for repeated queries to reduce repeated computation.

Example use cases

  • Rerank top 100 vector-search results to surface the most relevant passages for a QA system.
  • Improve search result ordering in an enterprise document portal for better user satisfaction.
  • Select the top-N supporting documents to feed into a summarization or evidence-aggregation pipeline.
  • Filter and rank multilingual or noisy retrieval outputs where lexical signals are weak.
  • Evaluate model impact by comparing Top-K accuracy before and after reranking.

FAQ

What output formats are available?

You can get a full structured JSON with ids and documents, compact (index, score, document) tuples, or just top indices for lightweight needs.

How many candidates should I rerank?

Typically rerank dozens to a few hundred candidates. Larger sets increase latency and cost with diminishing returns on Top-K quality.