Rerank a list of documents or passages by relevance to a query. Uses LLM-based scoring via MakerAI (CompleteStructured with scoring schema) or cross-encoder models. Essential second stage in RAG pipelines to improve precision.
rerankerragrelevancerankingretrieval
MakerAI Pipeline
pipeline: IPAILLMProvider.CompleteStructured — scoring each document against the query
strategy: LLM pointwise scoring or pairwise comparison
Input Parameters
Parameter
Type
Description
queryrequired
string
The search query or question.
documentsrequired
array[object]
List of documents/passages to rerank.
top_koptional
integer
Return only the top K results after reranking. Default: returns all. Default: 0.
Model for LLM-based reranking. Empty = router default.
Output Fields
Field
Type
Description
query
string
results
array[object]
Reranked documents with relevance scores, best first.
method
string
model
string
Examples
Rerank RAG retrieved chunks
// Input
{
"query": "How do I configure SSL in Nginx?",
"documents": [
{
"id": "a",
"content": "SSL configuration in Apache uses mod_ssl."
},
{
"id": "b",
"content": "To enable SSL in Nginx, add ssl_certificate and ssl_certificate_key directives."
},
{
"id": "c",
"content": "Nginx is a high-performance web server."
}
],
"top_k": 2
}
// Output
{
"results": [
{
"id": "b",
"content": "To enable SSL in Nginx...",
"score": 0.97,
"rank": 1
},
{
"id": "c",
"content": "Nginx is a high-performance...",
"score": 0.41,
"rank": 2
}
]
}
Install & Discovery
Install
ppm install mcp-reranker
Get JSON Schema
GET /v1/packages/mcp-reranker/1.0.0/schema
Discover by keyword
GET /v1/mcp/discover?q=reranker
Discovery hint: Install with ppm install mcp-reranker or invoke remotely via POST /v1/invoke/mcp-reranker on the MCP Service.
PascalAI Usage
uses toolslib;
var Tool := LoadTool('mcp-reranker');
var R := Tool.Call(JsonObj(['query',q,'documents',docs,'top_k',3]));
forvar Item in R['results'] do Writeln(Item['id'] + ': ' + FloatToStr(Item['score']));