Query-Document Pair Scoring is the core inference mechanism of a Cross-Encoder re-ranker, wherein a query string and a candidate document are concatenated into a single input sequence—typically separated by a [SEP] token—and passed through a transformer model. Unlike Bi-Encoder architectures that encode queries and documents independently, this joint processing enables full token-level interaction via self-attention, allowing the model to capture nuanced semantic relationships, exact lexical matches, and term importance weighting that isolated vector representations miss.
Glossary
Query-Document Pair Scoring

What is Query-Document Pair Scoring?
The fundamental computational operation in Cross-Encoder re-ranking where a query and a candidate passage are concatenated into a single input sequence and processed through a transformer to generate a joint relevance representation.
The output of this joint encoding is a single relevance score, often derived from the [CLS] token representation passed through a linear classification head. This fine-grained full-attention scoring produces substantially higher precision than dot-product similarity but incurs significant computational cost, as every query-document pair must be processed from scratch. Consequently, pair scoring is deployed exclusively in cascade ranking architectures, where it re-ranks only the top-k candidates retrieved by a lightweight first-stage Bi-Encoder or lexical retriever like BM25.
Key Characteristics of Query-Document Pair Scoring
The fundamental operation in Cross-Encoder re-ranking where a query and a candidate passage are concatenated into a single input sequence and passed through a transformer to generate a joint relevance representation.
Joint Input Encoding
The query and document are concatenated into a single sequence using a separator token (e.g., [SEP]), allowing the transformer's self-attention mechanism to model token-level interactions across both strings simultaneously. This contrasts with Bi-Encoders, which encode each input independently.
Full Self-Attention Interaction
Every token in the query attends to every token in the document, and vice versa. This enables rich cross-sentence semantic matching, capturing nuanced relationships like:
- Exact lexical overlap (keyword matching)
- Paraphrastic equivalence (semantic similarity)
- Contextual disambiguation (resolving polysemy)
Pointwise Scoring Paradigm
The model outputs a single relevance score for the pair, typically derived from the [CLS] token's final hidden state passed through a linear classification head. This is a pointwise approach—each query-document pair is scored independently, unlike pairwise methods that compare two documents directly.
Computational Cost Profile
Scoring is quadratically expensive with respect to combined sequence length due to the self-attention mechanism. A typical Cross-Encoder inference costs 10-100x more FLOPs than a Bi-Encoder dot product. This makes it unsuitable for first-stage retrieval over millions of documents, but ideal for re-ranking a top-k candidate set (typically k=100-1000).
Training with Hard Negatives
Effective training requires hard negative mining—selecting negative documents that the first-stage retriever ranked highly but are actually irrelevant. This forces the Cross-Encoder to learn fine-grained discriminative boundaries. Without hard negatives, the model only learns to separate trivially irrelevant documents from relevant ones.
Score Calibration
Raw logit outputs are often miscalibrated—they don't reflect true empirical relevance probabilities. Techniques like Platt scaling or temperature scaling are applied post-training to adjust scores so that a score of 0.8 reliably indicates an 80% chance of relevance, enabling consistent thresholding across queries.
Frequently Asked Questions
Clear, technical answers to the most common questions about how Cross-Encoders evaluate the relevance between a search query and a candidate passage.
Query-Document Pair Scoring is the fundamental operation in Cross-Encoder re-ranking where a query string and a candidate passage are concatenated into a single input sequence and passed through a transformer to generate a joint relevance representation. Unlike Bi-Encoders that encode queries and documents independently, this mechanism processes the pair simultaneously through full self-attention, allowing every query token to attend to every document token. The model typically uses a special [CLS] token or a linear projection head on top of the final hidden state to output a single scalar relevance score. This token-level interaction captures rich semantic relationships, exact lexical matches, and subtle contextual signals that independent encoding architectures miss, making it the gold standard for precision in modern retrieval pipelines.
Query-Document Pair Scoring vs. Related Scoring Paradigms
A feature-level comparison of the core Cross-Encoder joint scoring paradigm against Bi-Encoder dot-product scoring and Late Interaction MaxSim scoring.
| Feature | Query-Document Pair Scoring (Cross-Encoder) | Bi-Encoder Dot-Product Scoring | Late Interaction MaxSim Scoring |
|---|---|---|---|
Interaction Type | Full self-attention across all query and document tokens simultaneously | No direct token interaction; final pooled embeddings compared via cosine similarity | Token-level interaction delayed until final MaxSim computation |
Token-Level Granularity | |||
Exact Match Signal Capture | |||
Pre-Computable Document Representations | |||
Inference Latency (per candidate) | 10-50 ms | < 1 ms | 2-5 ms |
Typical Retrieval Stage | Final re-ranking of top-k candidates | First-stage retrieval over millions of documents | Second-stage re-ranking of top-k candidates |
Relevance Precision | Highest; fine-grained semantic and lexical alignment | Moderate; captures topical similarity but misses exact phrasing | High; balances token-level matching with computational efficiency |
Scalability to Millions of Documents |
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
Explore the core mechanisms, training strategies, and evaluation metrics that define the Cross-Encoder re-ranking pipeline. These concepts are essential for search engineers optimizing the precision-latency trade-off in modern retrieval systems.
Full-Attention Scoring
The defining mechanism of a Cross-Encoder where the query and candidate document are concatenated into a single input sequence. Every token in the query attends to every token in the document simultaneously via the transformer's self-attention layers. This enables rich token-level interaction, capturing exact match signals, lexical overlap, and deep semantic alignment that Bi-Encoders miss. The joint representation is then pooled (often via the [CLS] token) to produce a fine-grained relevance score.
Cascade Ranking
A multi-stage retrieval architecture that balances recall and precision. A lightweight, high-recall first-stage retriever (e.g., Bi-Encoder with ANN search) efficiently narrows the corpus from millions to hundreds of candidates. A computationally intensive Cross-Encoder then re-ranks only this top-k subset. This design optimizes the latency-relevance trade-off, applying expensive full-attention scoring only where it yields the highest marginal utility.
Hard Negative Mining
A training data curation strategy critical for discriminative re-rankers. Standard random negatives are too easy; the model must learn fine-grained boundaries. Hard negatives are documents that receive high scores from the current retriever but are irrelevant to the query. Mining these—often using the top BM25 or dense retrieval results that lack relevance—forces the Cross-Encoder to distinguish subtle semantic differences and avoid superficial keyword matches.
Knowledge Distillation for Re-Ranking
A compression technique where a computationally expensive teacher Cross-Encoder transfers its scoring distribution to a lightweight student Bi-Encoder. The student is trained to mimic the teacher's softmax probabilities or the margin between positive and negative pairs, often using KL divergence loss. This allows the student to approximate the teacher's high precision at the low latency required for first-stage retrieval, effectively distilling full-attention knowledge into a dot-product model.
NDCG (Normalized Discounted Cumulative Gain)
The standard listwise evaluation metric for re-ranking quality. NDCG measures the quality of a ranked list by discounting relevance gains logarithmically by position, heavily weighting top-ranked precision. It is normalized against the ideal ranking (IDCG) to produce a score between 0 and 1. Unlike MRR, NDCG handles graded relevance judgments (e.g., Perfect, Good, Fair), making it the primary optimization target for LambdaMART and listwise neural rankers.
Inference Latency Optimization
Techniques to reduce the computational time of Cross-Encoder scoring to meet strict real-time budgets. Key methods include:
- INT8 Quantization: Reduces model precision for faster matrix multiplication.
- ONNX Runtime: Graph-level optimizations and kernel fusion.
- Dynamic Batching: Groups re-ranking requests to maximize GPU utilization.
- Token Pruning: Removes less important tokens early in the transformer layers.

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