Skip to content
Framework
Component Guides
Models

Rerankers

A reranker takes the top-k nodes returned by an initial retriever (usually a dense vector search, keyword search, or a hybrid of the two) and re-orders them based on a stronger, and typically slower, measure of query-document relevance. Reranking is one of the highest-leverage knobs in a RAG pipeline: initial retrievers are tuned for recall over a large corpus, and a reranker lets you recover precision before nodes reach the LLM.

In LlamaIndex, rerankers are implemented as node postprocessors that run between retrieval and response synthesis.

from llama_index.core.postprocessor import SentenceTransformerRerank
reranker = SentenceTransformerRerank(
model="cross-encoder/ms-marco-MiniLM-L6-v2", top_n=3
)
query_engine = index.as_query_engine(
similarity_top_k=10,
node_postprocessors=[reranker],
)
response = query_engine.query("What did the author do in college?")

The retriever fetches a wider set (similarity_top_k=10) and the reranker prunes it down to the best top_n=3 before the LLM sees them.

For the full reference including every integration and every model, see the Node Postprocessors guide. Rerankers are one category of node postprocessors.

Note for AI agents: this documentation is built for programmatic access. - Overview of all docs: https://developers.llamaindex.ai/llms.txt - Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md - Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters. - A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/for-agents/mcp/ - Other LlamaIndex tooling for agents — the LlamaParse Platform MCP server, agent skills and plugins, and the n8n node — is mapped at https://developers.llamaindex.ai/for-agents/