A cross-encoder is a transformer-based model that takes a concatenated query and document as a single input sequence. It passes this sequence through its encoder stack and uses a classification head on the [CLS] token to output a single relevance score. This joint processing allows for deep, bidirectional attention across the entire query-document pair, capturing complex semantic interactions and term dependencies that simpler models miss. Consequently, cross-encoders achieve state-of-the-art reranking accuracy but are computationally expensive, as each candidate document requires a full forward pass through the model.
Glossary
Cross-Encoder

What is a Cross-Encoder?
A cross-encoder is a neural network model used in information retrieval to score the relevance of a query-document pair by processing them jointly through a single transformer encoder.
Due to their high computational cost, cross-encoders are almost exclusively deployed in a two-stage retrieval pipeline, also known as retrieve-and-rerank. A fast, recall-oriented first-stage retriever (like BM25 or a dual encoder) fetches a candidate set (e.g., 100-1000 documents). The cross-encoder then reorders this smaller set, providing a final precision-optimized ranking. Models like MonoT5, BGE-Reranker, and fine-tuned versions of BERT or RoBERTa are common cross-encoder architectures used for this critical reranking step in production Retrieval-Augmented Generation (RAG) systems.
Key Features of Cross-Encoders
Cross-encoders are computationally intensive neural models used in a two-stage retrieval pipeline to reorder and score candidate documents for maximum precision. Unlike efficient dual encoders, they process query-document pairs jointly.
Joint Input Processing
A cross-encoder processes a query-document pair as a single, concatenated input sequence. This allows the model's attention mechanism to perform full cross-attention across every token in the query and every token in the document simultaneously. This deep, token-level interaction captures nuanced semantic relationships and contextual dependencies that are lost when inputs are encoded separately.
- Example Input:
[CLS] What is the capital of France? [SEP] Paris is the capital and most populous city of France. [SEP] - The model can directly learn that the token
capitalin the query strongly attends to the tokencapitalin the document, within the specific context ofFrance.
Precision-Oriented Scoring
The primary output of a cross-encoder is a single, fine-grained relevance score (e.g., a value between 0 and 1) for the input pair. This score is optimized for precision at the top of a ranked list. Because the model sees the full context of both texts, it can identify subtle indicators of relevance or irrelevance that simpler models miss.
- Key Application: Reranking. A fast first-stage retriever (like BM25 or a dual encoder) fetches 100-1000 candidate documents. The cross-encoder then scores each
(query, candidate)pair, reordering the list to place the most relevant documents at the top. - This dramatically improves metrics like Mean Reciprocal Rank (MRR) and Precision@K for small K (e.g., P@1, P@5).
High Computational Cost
The architectural strength of cross-encoders is also their primary limitation: inference is computationally expensive and slow. Since each query-document pair must be processed through the full transformer model, scoring a large set of candidates is prohibitive for real-time, large-scale search.
- Cost Scaling: Scoring
Ncandidates requiresNforward passes through the model. For a candidate set of 100 documents, this is 100x more expensive than a dual encoder, which encodes the query once and compares it to all pre-computed document embeddings. - Latency: This makes them unsuitable as a first-stage retriever. They are deployed exclusively as a second-stage reranker where the candidate set has already been drastically reduced (e.g., from millions to hundreds).
Training for Pairwise Ranking
Cross-encoders are typically trained using a pairwise or listwise ranking loss on datasets of labeled query-document pairs. Common objectives include:
- Binary Cross-Entropy Loss: Treats relevance as a binary classification task (relevant vs. non-relevant).
- Margin Ranking Loss (e.g., Triplet Loss): Trains the model to score a positive document higher than a negative one by a defined margin.
- Softmax Cross-Entropy Loss: For datasets with graded relevance labels (e.g., 0 to 4), this treats ranking as a multi-class classification problem.
Training data often comes from clickstream logs, human annotations, or synthetically generated hard negatives.
Common Model Architectures
Most modern cross-encoders are based on pre-trained transformer models like BERT, RoBERTa, or DeBERTa, with a classification head added on top of the [CLS] token output. The model is then fine-tuned for the text-pair scoring task.
- Examples:
cross-encoder/ms-marco-MiniLM-L-6-v2,BAAI/bge-reranker-large. - These models are often distilled from larger, more powerful cross-encoders or sequence-to-sequence models to reduce inference latency while preserving most of the ranking performance.
Optimal Deployment Context
Cross-encoders are the tool of choice when precision is paramount and computational budget allows. Their use is dictated by a clear trade-off analysis.
Ideal Use Cases:
- Enterprise RAG Systems: Reranking the top 50-100 chunks retrieved by a hybrid system before passing them to an LLM, critically reducing hallucinations.
- Legal & Medical Search: Where finding the single most relevant precedent or research paper is crucial, and query volume is moderate.
- E-commerce Product Search: Reranking product results for complex, multi-faceted queries to maximize conversion.
Poor Fit:
- Real-time web-scale search (billions of documents).
- Low-latency applications where sub-100ms total response is required.
- Environments with severe GPU/compute constraints.
Cross-Encoder vs. Dual Encoder (Bi-Encoder)
A technical comparison of two primary neural architectures for semantic search and relevance scoring in retrieval-augmented generation (RAG) systems.
| Architectural Feature | Cross-Encoder | Dual Encoder (Bi-Encoder) |
|---|---|---|
Core Mechanism | Jointly encodes query and document pair in a single forward pass | Independently encodes query and document into separate fixed-size vectors |
Interaction Type | Full, deep cross-attention between all query and document tokens | Late or no interaction; similarity computed post-encoding (e.g., dot product) |
Primary Use Case | Re-ranking (precision stage) in a two-stage retrieval pipeline | First-stage retrieval (recall stage) for dense vector search |
Inference Latency | High (50-500 ms per query-document pair) | Low (< 10 ms per query after initial encoding) |
Pre-Training Objective | Typically trained on Next Sentence Prediction (NSP) or similar pair-wise tasks | Trained via contrastive learning (e.g., Multiple Negatives Ranking) |
Indexing & Search | Cannot pre-compute document representations; scores computed at query time | Document embeddings pre-computed and indexed for fast ANN search |
Typical Model Size | Large (e.g., 110M - 440M parameters) | Medium to Large (e.g., 110M - 340M parameters) |
Representative Models | BERT, RoBERTa, DeBERTa in a cross-encoder configuration | Sentence-BERT, DPR, E5, GTE models |
Accuracy / Precision | Higher (superior at modeling complex query-document relationships) | Lower (but sufficient for high-recall candidate generation) |
Scalability to Large Corpora | Poor (linear cost with corpus size for full re-ranking) | Excellent (sub-linear via ANN search over pre-indexed vectors) |
Implementations and Frameworks
Cross-encoders are computationally intensive but highly accurate models used for reranking in two-stage retrieval systems. This section details the key libraries, models, and practical considerations for implementing cross-encoder reranking.
Common Pre-Trained Models
Several pre-trained cross-encoder models are available, each optimized for different tasks and datasets. Selection depends on the domain and the nature of the query-document pairs.
- cross-encoder/ms-marco-MiniLM-L-6-v2: A compact model fine-tuned on the MS MARCO passage ranking dataset, ideal for general web-style question-answering and retrieval.
- cross-encoder/nli-deberta-v3-base: Fine-tuned for Natural Language Inference (NLI), excellent for tasks requiring deep semantic understanding of entailment and contradiction, useful for fact-checking RAG.
- cross-encoder/stsb-roberta-large: Fine-tuned on Semantic Textual Similarity benchmarks, suitable for tasks where query and document are semantically parallel (e.g., paraphrase detection).
- cross-encoder/quora-roberta-large: Trained on Quora duplicate question data, effective for identifying near-duplicate or highly similar text pairs.
Integration in Two-Stage RAG
In a Retrieve-and-Rerank pipeline, the cross-encoder acts as the second, precision-focused stage. The standard workflow is:
- First-Stage Retrieval: A fast, recall-oriented method (e.g., BM25 or a dual-encoder) fetches a large candidate set (e.g., 100-1000 documents).
- Pair Formation: The user query is paired with each candidate document text.
- Cross-Encoder Scoring: The model processes each
[CLS] query [SEP] document [SEP]pair to produce a single relevance score. - Re-ranking: Candidates are sorted by the cross-encoder score, and the top-k (e.g., 5-10) are passed to the LLM for answer generation. This architecture optimally balances system latency (fast first stage) with answer precision (accurate second stage).
Computational Cost & Optimization
The primary drawback of cross-encoders is their O(n) inference cost relative to the number of candidates, as each query-document pair must be processed independently. Key strategies to manage this cost include:
- Candidate Set Pruning: Limit the first-stage retrieval to a manageable number of candidates (e.g., 50-100).
- Hardware Acceleration: Deploy models on GPUs with batch inference to score multiple pairs in parallel.
- Model Distillation: Use smaller, distilled versions of large cross-encoders (e.g., MiniLM) that retain most performance with significantly lower latency.
- Caching: Cache scores for frequent or repeated query-document pairs where applicable.
- Asynchronous Processing: For user-facing applications, the reranking step can sometimes be run asynchronously after an initial fast response is generated.
Fine-Tuning for Domain Adaptation
While pre-trained models are powerful, maximum reranking performance is achieved by fine-tuning a cross-encoder on domain-specific labeled data. This process involves:
- Data Collection: Creating a dataset of
(query, relevant_document, irrelevant_document)triplets or(query, document, relevance_score)pairs. - Loss Function: Typically using a cross-entropy loss for classification (relevant/irrelevant) or a MSE loss for regression on relevance scores.
- Training: The model learns to attend to domain-specific terminology, phrasing, and relevance signals. Even a few hundred high-quality labeled examples can yield significant improvements over a generic model. This makes cross-encoders a compelling choice for enterprises with proprietary data where off-the-shelf models may underperform.
Cross-Encoder vs. ColBERT
ColBERT represents a middle-ground architecture between a dual-encoder and a cross-encoder. It's crucial to understand the trade-offs:
- Cross-Encoder: Full, deep interaction between query and document tokens. Highest accuracy, but slowest (processes each pair jointly).
- ColBERT (Late Interaction): Encodes queries and documents independently into fine-grained embeddings. Relevance is computed via a sum-of-maximum similarities operation. Offers better accuracy than dual-encoders and is more efficient than cross-encoders for re-ranking, as document embeddings can be pre-computed and indexed.
- Use Case Decision: Use a cross-encoder when precision is paramount and candidate sets are small (<100). Use ColBERT when you need near-cross-encoder quality but must re-rank larger candidate sets or have stricter latency budgets.
Frequently Asked Questions
A cross-encoder is a high-precision neural model used to score the relevance of a query-document pair. Unlike efficient dual encoders, it processes both inputs together, offering superior accuracy at a higher computational cost, making it ideal for the reranking stage in retrieval systems.
A cross-encoder is a neural network model, typically based on a transformer architecture like BERT, that takes a query and a document as a single, concatenated input to produce a direct relevance score. It works by applying self-attention across the entire combined input sequence, allowing every token in the query to directly interact with every token in the document. This deep, joint processing enables the model to capture complex semantic relationships and nuanced relevance signals that are missed by models that encode inputs separately. The output is typically a single scalar score or a probability indicating the likelihood that the document is relevant to the query. This design sacrifices the pre-computation and indexing efficiency of dual encoders for significantly higher ranking accuracy.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Cross-encoders are a key component within a broader retrieval and ranking ecosystem. Understanding these related concepts is essential for designing performant RAG and search systems.
Dual Encoder (Bi-Encoder)
A neural network architecture where a query and a document are encoded independently into fixed-dimensional vector embeddings. Relevance is scored via a simple similarity function (e.g., cosine, dot product) between the two vectors.
- Key Advantage: Enables pre-computation of document embeddings and efficient ANN search, making it suitable for first-stage retrieval.
- Trade-off: Less expressive than a cross-encoder, as the query and document never interact during encoding, which can limit the model's ability to capture complex semantic relationships.
- Example: Dense Passage Retrieval (DPR) and models like
all-MiniLM-L6-v2are classic dual encoders used for semantic search.
Two-Stage Retrieval (Retrieve-and-Rerank)
A production architecture that separates the retrieval pipeline into distinct phases to balance recall and precision.
- Stage 1 (Retrieval): A fast, recall-oriented model (e.g., BM25 or a dual encoder) fetches a large candidate set (e.g., 100-1000 documents) from a massive corpus.
- Stage 2 (Reranking): A slow, precision-oriented model (typically a cross-encoder) reorders and scores the smaller candidate set to produce the final, high-precision ranked list.
- Rationale: This hybrid approach is computationally optimal, as the expensive cross-encoder is only applied to a tiny fraction of the total document collection.
Late Interaction
A model design, exemplified by ColBERT, that strikes a middle ground between dual encoders and cross-encoders.
- Mechanism: The query and document are encoded separately into fine-grained, contextualized token-level embeddings (not a single vector). The relevance score is computed via a sum-of-maximum similarity operation across all query-document token pairs.
- Advantage: Allows for some token-level interaction after encoding (late interaction), capturing more nuance than a dual encoder while still enabling efficient pre-computation of document token embeddings.
- Use Case: Can be used as a standalone retriever or as a sophisticated reranker, offering a favorable accuracy/efficiency trade-off.
Learned Retrieval
An umbrella term for retrieval systems where the ranking function is trained end-to-end on relevance labels, as opposed to using hand-crafted algorithms like BM25.
- Paradigm Shift: Moves from heuristic scoring to data-driven, model-based scoring.
- Spectrum: Encompasses dense retrievers (dual encoders), late interaction models (ColBERT), and rerankers (cross-encoders).
- Training Data: Typically requires large datasets of (query, relevant document, irrelevant document) triplets.
- Goal: To learn a scoring function that directly optimizes for human judgments of relevance, leading to more nuanced and effective retrieval.
Reciprocal Rank Fusion (RRF)
A robust, score-agnostic technique for fusing multiple ranked lists, commonly used in hybrid retrieval systems.
- Problem: The relevance scores from different retrievers (e.g., BM25 and a vector search) are on incompatible scales and distributions, making simple weighted averaging problematic.
- Solution: RRF uses only the rank positions from each list. The fused score for a document is the sum of
1 / (k + rank)from each list it appears in, wherekis a constant (typically 60). - Benefit: Provides a simple, effective way to combine results from heterogeneous retrievers (sparse, dense, etc.) without requiring score normalization or calibration.
BERT (Bidirectional Encoder Representations from Transformers)
The foundational transformer architecture upon which most modern cross-encoders are built.
- Core Innovation: A transformer encoder model pre-trained using Masked Language Modeling (MLM) and Next Sentence Prediction (NSP), enabling deep bidirectional context understanding.
- Cross-Encoder Usage: Standard BERT models (e.g.,
bert-base-uncased) can be adapted for reranking by feeding the concatenated[CLS] query [SEP] document [SEP]sequence and fine-tuning the[CLS]token's output for binary classification (relevant/irrelevant). - Specialized Variants: Models like MonoT5 and RankT5 reformulate ranking as a sequence-to-sequence text generation task, often achieving state-of-the-art reranking performance.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us