A cross-encoder is a neural re-ranking model that processes a query and a candidate document simultaneously as a single concatenated input sequence. Unlike a bi-encoder, which encodes queries and documents independently into fixed vectors for fast similarity comparison, a cross-encoder applies full cross-attention between every query token and every document token across all transformer layers. This deep token-level interaction allows the model to capture subtle semantic relationships, exact phrase matches, and complex linguistic dependencies that independent encoding architectures miss, producing a highly accurate relevance score at the cost of significant computational latency.
Glossary
Cross-Encoder

What is a Cross-Encoder?
A cross-encoder is a neural architecture that processes a query-document pair jointly through full self-attention to generate a fine-grained relevance score, used for precise re-ranking.
In a two-stage retrieval pipeline, cross-encoders serve as the precision-focused second stage, re-ranking a small set of top candidates retrieved by a fast bi-encoder or BM25 lexical search. Because the joint encoding operation must be performed for every query-document pair at inference time, cross-encoders are computationally prohibitive for full-corpus search but excel at refining the top 50–200 candidates. Architecturally, a cross-encoder typically appends a linear classification head to a pre-trained transformer like BERT, outputting a single logit that represents relevance probability after temperature scaling or sigmoid activation.
Cross-Encoder vs. Bi-Encoder vs. Poly-Encoder
A structural comparison of the three primary neural architectures used for query-document relevance scoring, highlighting the trade-offs between computational cost and interaction depth.
| Feature | Cross-Encoder | Bi-Encoder | Poly-Encoder |
|---|---|---|---|
Interaction Mechanism | Full cross-attention between query and document tokens from the input layer | No direct interaction; query and document are encoded independently | Query attends to document tokens via a small set of learned context vectors |
Scoring Method | Joint classification head on concatenated pair | Cosine similarity or dot product between pooled vectors | Final attention-weighted aggregation of document embeddings |
Computational Cost | High; O(n*m) per pair | Low; O(n+m) per item, pre-computable | Medium; O(m*k) where k << n |
Inference Speed | Slow; cannot pre-compute document representations | Fast; document embeddings can be indexed offline | Moderate; document embeddings pre-computable, query encoding is heavier |
Re-ranking Suitability | |||
Retrieval Suitability | |||
Token-Level Granularity | |||
Typical Use Case | Final-stage re-ranking of top-k candidates | First-stage dense retrieval over millions of documents | Mid-stage candidate refinement or low-latency re-ranking |
Key Characteristics of Cross-Encoders
Cross-encoders define the state-of-the-art for relevance scoring by processing query-document pairs jointly through full self-attention, enabling fine-grained semantic matching at the cost of computational latency.
Full Self-Attention Interaction
Unlike bi-encoders that encode queries and documents in isolation, cross-encoders concatenate the query and document into a single input sequence. This allows every token in the query to attend to every token in the document through the transformer's self-attention layers. The result is a rich, token-level interaction that captures subtle semantic relationships, negations, and dependencies that independent encoding misses. This mechanism is the primary reason cross-encoders achieve superior accuracy on relevance benchmarks.
Joint Input Processing
The input format is typically structured as [CLS] query [SEP] document [SEP]. The model processes this entire sequence simultaneously through multiple transformer layers. The final hidden state of the [CLS] token is fed into a linear classification head to produce a single relevance score between 0 and 1. This joint processing means the model cannot pre-compute document representations; every query-document pair requires a full forward pass, making it computationally expensive for large-scale retrieval but ideal for precise re-ranking of top candidates.
Two-Stage Retrieval Cascade
Cross-encoders are almost never used for initial retrieval over millions of documents due to their O(N) inference cost. The standard architecture is a two-stage cascade:
- Stage 1 (Retriever): A fast bi-encoder or BM25 fetches the top-K candidates (e.g., K=100 or 1000).
- Stage 2 (Re-ranker): A cross-encoder scores each candidate pair and re-orders the list by relevance. This combines the speed of approximate nearest neighbor search with the precision of deep interaction, optimizing the latency-accuracy trade-off for production systems.
Training with Hard Negatives
To maximize discriminative power, cross-encoders are trained with carefully selected hard negatives—documents that are topically similar to the query but ultimately irrelevant. Standard training uses binary cross-entropy loss on positive and negative pairs. Advanced strategies include:
- Mining negatives from the top results of a bi-encoder retriever.
- Using Knowledge Distillation where a cross-encoder teacher scores pairs to train a more efficient student model.
- Incorporating graded relevance labels for nuanced scoring beyond binary relevance.
Inference Latency Profile
A single cross-encoder forward pass on a query-document pair typically takes 10-50 milliseconds on GPU, compared to < 1 millisecond for a pre-computed bi-encoder dot product. When re-ranking a candidate set of 100 documents, total latency can range from 1 to 5 seconds without optimization. Mitigation strategies include:
- Batching multiple pairs into a single GPU inference call.
- Model distillation into smaller architectures like MiniLM.
- Early exiting where low-confidence pairs are pruned after intermediate transformer layers.
Score Calibration with Temperature Scaling
Raw logit outputs from the classification head can be poorly calibrated, producing overconfident scores. Temperature Scaling applies a learned parameter T to the softmax function: softmax(logits / T). A T > 1 softens the probability distribution, improving the reliability of the relevance score. This is critical when cross-encoder scores are fused with other signals (e.g., BM25 scores or freshness boosts) in a final ranking formula, ensuring the scores represent true posterior probabilities.
Frequently Asked Questions
Explore the mechanics, trade-offs, and implementation details of cross-encoder architectures for precise relevance scoring in two-stage retrieval pipelines.
A cross-encoder is a neural architecture that processes a query-document pair jointly through full cross-attention to generate a fine-grained relevance score. Unlike bi-encoders that encode queries and documents independently, a cross-encoder concatenates the query and document text into a single input sequence—typically formatted as [CLS] query [SEP] document [SEP]—and passes it through a transformer model like BERT. Every token in the query attends to every token in the document across all layers, enabling deep token-level interaction. The final [CLS] representation is fed into a linear classification head that outputs a single scalar relevance score. This joint processing captures nuanced semantic relationships, exact term matching, and complex linguistic dependencies that independent encoding misses. The trade-off is computational cost: scoring a single query-document pair requires a full transformer forward pass, making cross-encoders impractical for large-scale retrieval but ideal for re-ranking a small set of pre-retrieved candidates.
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
Core concepts for understanding how cross-encoders fit into modern retrieval pipelines and how they are optimized for precise relevance scoring.
Two-Stage Retrieval
The cascade architecture where cross-encoders operate as the re-ranking stage. A fast retriever (bi-encoder or BM25) selects top-K candidates from millions of documents, then the cross-encoder performs joint query-document attention on this reduced set.
- Stage 1: High recall, low precision, sub-10ms latency
- Stage 2: Low recall, high precision, 50-200ms per pair
- Typical K values range from 100 to 1000 candidates
Cross-Attention Mechanism
The defining architectural feature that distinguishes cross-encoders from bi-encoders. Every token in the query attends to every token in the document through full self-attention across the concatenated sequence.
- Enables fine-grained token-level interaction
- Captures exact phrase matching and negation
- Computationally expensive: O(n²) where n = query + document length
Knowledge Distillation
The primary method for transferring cross-encoder precision to faster bi-encoders. A cross-encoder serves as the teacher model, generating soft relevance labels on query-document pairs. A bi-encoder student is trained to mimic this distribution.
- Student learns to approximate deep interaction signals
- Retains sub-linear retrieval speed at inference
- Margin-MSE and KL divergence are common distillation losses
Hard Negative Mining
A training strategy critical for cross-encoder discriminative power. Negatives that receive high scores from a bi-encoder but are actually irrelevant are fed to the cross-encoder during training.
- Forces the model to learn fine-grained distinctions
- Prevents the re-ranker from simply trusting the retriever
- Top-ranked negatives from dense retrieval are the most informative
Score Normalization
Cross-encoder raw logits are unbounded and miscalibrated. Min-max scaling or temperature scaling transforms scores to a [0,1] range before fusion with other signals.
- Enables meaningful combination with BM25 scores
- Prevents cross-encoder scores from dominating fused rankings
- Platt scaling fits a logistic calibration layer on held-out data
LLM-as-a-Judge
An emerging alternative to cross-encoders where a large language model is prompted to evaluate relevance. The LLM receives the query and document and outputs a judgment with reasoning.
- More flexible: handles complex relevance criteria
- Higher latency and cost than cross-encoders
- Used for evaluation gold labels and offline auditing

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