Inferensys

Glossary

Two-Stage Retrieval (Retrieve-and-Rerank)

Two-stage retrieval is an information retrieval architecture that separates the search process into a fast, recall-oriented candidate retrieval stage and a slow, precision-oriented reranking stage.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
ARCHITECTURE

What is Two-Stage Retrieval (Retrieve-and-Rerank)?

Two-stage retrieval, or retrieve-and-rerank, is a hybrid search architecture designed to balance high recall with high precision in information retrieval systems like Retrieval-Augmented Generation (RAG).

Two-stage retrieval is an information retrieval architecture where a fast, recall-oriented first-stage retriever (e.g., BM25 or a dual encoder) fetches a broad set of candidate documents, which are then reordered by a slower, precision-oriented second-stage reranker (e.g., a cross-encoder). This design optimizes the trade-off between search speed and result accuracy, making it foundational for production RAG systems. The first stage maximizes recall, ensuring relevant information is in the candidate pool, while the second stage refines precision by deeply analyzing context.

The reranker, typically a computationally intensive cross-encoder, performs a full-attention joint analysis of the query and each candidate, producing a more accurate relevance score than the initial similarity search. This stage filters out irrelevant candidates and boosts the most pertinent documents to the top of the list before they are passed to a large language model. This architecture is a core component of hybrid retrieval systems, combining the scalability of approximate nearest neighbor search with the nuanced understanding of transformer-based reranking models.

ARCHITECTURAL BREAKDOWN

Key Components of a Two-Stage System

A two-stage retrieval (retrieve-and-rerank) system decomposes the search problem into two specialized phases: a fast, broad-coverage first stage and a slow, high-precision second stage. This architecture optimizes the trade-off between recall and latency.

01

First-Stage Retriever

The first-stage retriever is optimized for high recall and low latency. Its primary function is to rapidly scan a massive corpus (millions to billions of documents) and return a manageable candidate set (e.g., 100-1000 documents).

  • Common Implementations: Sparse retrievers like BM25 or fast dense retrievers using a dual encoder architecture (e.g., DPR, SBERT).
  • Key Characteristic: Uses efficient, pre-computed indexes—an inverted index for sparse methods or a vector index (e.g., HNSW, IVF) for dense methods—to enable approximate nearest neighbor (ANN) search.
  • Output: A ranked list of candidate documents where the goal is to ensure the truly relevant documents are within the retrieved set, even if the ranking is imperfect.
02

Second-Stage Reranker

The second-stage reranker is a precision-oriented model that reorders and scores the candidate set from the first stage. It is computationally intensive but operates on a small subset, making the cost manageable.

  • Common Implementation: A cross-encoder model, which jointly processes a query-document pair through a transformer to produce a fine-grained relevance score.
  • Key Advantage: Achieves much higher precision and ranking accuracy than the first stage by performing deep, contextual interaction between the query and each candidate.
  • Trade-off: Speed. Reranking 100 documents with a cross-encoder is significantly slower than the initial retrieval of those 100 documents, which is why it's applied only to a shortlist.
03

Hybrid First-Stage Retrieval

Modern systems often use a hybrid retrieval approach in the first stage to maximize recall. This combines the strengths of sparse and dense methods.

  • Method: Executes both a sparse retrieval (e.g., BM25) and a dense retrieval (vector search) in parallel. The results are merged into a single candidate list.
  • Fusion Technique: Uses algorithms like Reciprocal Rank Fusion (RRF) to combine the ranked lists without requiring score normalization. RRF is robust and effective for this purpose.
  • Benefit: Captures both exact keyword matches (crucial for specific entities, codes, or jargon) and semantic matches (for conceptual or paraphrased queries), ensuring comprehensive coverage.
04

Candidate Set & Latency Budget

The size of the candidate set passed from the first to the second stage is a critical engineering parameter that directly impacts system latency and accuracy.

  • Engineering Trade-off: A larger candidate set (e.g., 200 docs) increases the chance of including all relevant documents (higher recall) but linearly increases reranking latency and cost. A smaller set (e.g., 50 docs) is faster but risks missing relevant results.
  • Determining Factors: The optimal size is determined by the latency budget (e.g., < 200ms total) and the performance characteristics of the retrievers. It is typically tuned via offline evaluation on a validation set.
  • Practical Range: In production RAG systems, candidate sets commonly range from 50 to 200 documents.
50-200
Typical Candidate Set Size
< 200ms
Common Latency Budget
05

Indexing & Embedding Pipeline

A robust indexing pipeline is the offline foundation that feeds both retrieval stages. It prepares the document corpus for efficient online querying.

  • For Sparse Retrieval: Builds an inverted index from tokenized document text, often with stopword removal and stemming/lemmatization.
  • For Dense Retrieval: Uses an embedding model (e.g., text-embedding-ada-002, BGE-M3) to generate document embeddings for every chunk. These vectors are then indexed in a specialized vector database like Pinecone, Weaviate, or using a library like FAISS.
  • Pre-computation: All document representations (sparse vectors, dense vectors) are computed and indexed offline, which is what makes the first-stage retrieval so fast.
TWO-STAGE RETRIEVAL ARCHITECTURE

First-Stage vs. Second-Stage: A Technical Comparison

A detailed comparison of the distinct roles, technical characteristics, and performance trade-offs between the first-stage retriever and the second-stage reranker in a retrieve-and-rerank pipeline.

Feature / MetricFirst-Stage RetrieverSecond-Stage Reranker

Primary Objective

Maximize Recall

Maximize Precision

Core Function

Fetch a broad candidate set (e.g., top-1000)

Re-rank the candidate set for final ordering

Typical Model Architecture

Dual Encoder (Bi-Encoder), Sparse (BM25)

Cross-Encoder

Inference Latency

< 10 ms

10-100 ms per candidate pair

Query-Document Interaction

Independent encoding, late similarity (e.g., dot product)

Full, joint attention across the query-document pair

Indexing Requirement

Requires pre-built index (vector or inverted)

Stateless; operates on provided text pairs

Common Algorithms / Models

BM25, DPR, Sentence Transformers, ColBERT

MonoT5, BERT-based cross-encoders, RankT5

Output

Ranked list of candidate IDs/scores

Refined ranked list with recalibrated scores

Scalability to Large Corpora

Highly scalable via ANN search (HNSW, IVF)

Not scalable; applied only to ~100-1000 candidates

TWO-STAGE RETRIEVAL

Primary Use Cases and Applications

The retrieve-and-rerank architecture is deployed to balance the competing demands of recall, precision, and computational efficiency in production retrieval systems. Its primary applications are in domains where the cost of a missed relevant document is high.

01

Enterprise Search & RAG Pipelines

This is the most common application, where a fast first-stage retriever (like BM25 or a dual encoder) fetches 100-1000 candidate documents from a massive corpus. A powerful cross-encoder then reorders these candidates to surface the most relevant 5-10 passages for the Large Language Model context window. This ensures the LLM receives high-precision grounding data, directly mitigating hallucinations.

  • Key Benefit: Maximizes the chance of including the 'needle in the haystack' document (high recall) while ensuring the most relevant documents are prioritized (high precision).
  • Example: A legal RAG system searches millions of case files; BM25 ensures all documents mentioning key statutes are retrieved, and the cross-encoder identifies the most precedential cases for the query.
02

Question Answering & Chatbots

For open-domain QA, the first stage retrieves a broad set of potentially relevant facts or paragraphs from a knowledge base (e.g., Wikipedia). The reranker evaluates each candidate's direct relevance to the specific question's intent, filtering out tangentially related or out-of-context information. This is critical for producing concise, accurate answers.

  • Key Benefit: Dramatically improves answer accuracy by ensuring the final context contains the exact evidence needed, not just semantically similar text.
  • Architecture: Often uses Dense Passage Retrieval (DPR) for stage 1 and a BERT-based cross-encoder (e.g., cross-encoder/ms-marco-MiniLM-L-6-v2) for stage 2.
03

Document Ranking & Recommendation

Used in systems that must personalize or prioritize content from a large inventory, such as news feeds, e-commerce product listings, or internal knowledge base articles. The first stage applies broad user interest or content filters. The second stage uses a fine-tuned reranker to predict engagement (click-through rate, dwell time) or relevance for the specific user context.

  • Key Benefit: Enables real-time personalization at scale by decoupling broad filtering from fine-grained scoring.
  • Contrast with Learned Retrieval: Unlike a single end-to-end model, this architecture allows the reranker to be updated frequently with new engagement data without rebuilding the entire retrieval index.
04

Hybrid Search Orchestration

Two-stage retrieval naturally complements hybrid retrieval. The first stage can execute parallel sparse (BM25) and dense (vector) searches, merging their results using a technique like Reciprocal Rank Fusion (RRF). This merged list, rich in both lexical and semantic matches, is then passed to the reranker for final precision scoring.

  • Key Benefit: The reranker acts as a sophisticated judge, resolving conflicts between lexical and semantic signals to produce a unified, optimal ranking.
  • System Design: This is a core pattern in platforms like Elasticsearch with a vector search plugin, where a knn search and a bm25 query are combined before a rescoring script (the reranker) is applied.
05

Mitigating Embedding Model Limitations

Dense retrieval can fail on out-of-domain vocabulary, long-tail entities, or exact keyword matches. A first-stage sparse retriever (BM25) guarantees coverage for these cases. The subsequent reranker, which sees the full text, can then down-rank irrelevant keyword matches and up-rank semantically correct results that the dense retriever may have missed.

  • Key Benefit: Provides a robustness safety net, ensuring the system doesn't fail completely if the embedding model encounters unfamiliar terminology.
  • Example: Searching for 'JVM' in a tech corpus. BM25 retrieves documents containing the acronym. The reranker identifies which documents are actually about the Java Virtual Machine versus those just mentioning 'JVM' in a list.
06

Computational Efficiency at Scale

The architecture is fundamentally an optimization. Running a heavyweight cross-encoder on every document in a million-document corpus is infeasible. By limiting its application to a small candidate set (e.g., 100 docs), the system achieves near-state-of-the-art accuracy with tractable latency and cost.

  • Key Trade-off: The system's upper-bound accuracy is capped by the recall@K of the first stage. If the correct document is not in the initial candidate set, the reranker cannot recover it.
  • Performance: Typical latency is dominated by the first-stage ANN search (milliseconds) plus the reranker inference on K documents (tens to hundreds of milliseconds).
TWO-STAGE RETRIEVAL

Frequently Asked Questions

Two-stage retrieval, or retrieve-and-rerank, is a production-grade architecture for high-accuracy search. It balances the speed of initial candidate fetching with the precision of deep neural reordering. These FAQs address its core mechanisms, trade-offs, and implementation for enterprise RAG systems.

Two-stage retrieval is an information retrieval architecture designed to optimize both recall and precision by separating the search process into two distinct phases. In the first stage (retrieval), a fast, recall-oriented model—such as BM25 for sparse retrieval or a dual encoder for dense retrieval—scans a large corpus to fetch a broad set of candidate documents (e.g., 100-1000). This stage prioritizes speed and ensuring the relevant document is in the candidate pool. In the second stage (reranking), a slower, computationally intensive but highly accurate model—typically a cross-encoder—jointly processes the query with each candidate to produce a refined relevance score. The final list is reordered based on these scores, delivering high-precision top results.

This decoupled design is fundamental to scalable Retrieval-Augmented Generation (RAG), as it allows the system to use an efficient approximate nearest neighbor (ANN) search over millions of vectors initially, then apply a powerful but expensive model only to a manageable subset.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.