Inferensys

Glossary

Query-Document Pair Scoring

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.
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.
JOINT RELEVANCE ESTIMATION

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.

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.

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.

MECHANICS

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.

01

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.

02

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)
03

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.

04

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).

10-100x
Cost vs. Bi-Encoder
05

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.

06

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.

QUERY-DOCUMENT PAIR SCORING

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.

SCORING MECHANISM COMPARISON

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.

FeatureQuery-Document Pair Scoring (Cross-Encoder)Bi-Encoder Dot-Product ScoringLate 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

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.