Inferensys

Glossary

Full-Attention Scoring

Full-attention scoring is the mechanism in a Cross-Encoder where every token in a query attends to every token in a candidate document simultaneously, enabling rich token-level semantic interaction that captures exact match signals and lexical overlap.
Stylish home-office setup in a modern highrise apartment, floor-to-ceiling windows showing city skyline at golden hour, a laptop displaying a beautiful semantic search interface.
CROSS-ENCODER MECHANISM

What is Full-Attention Scoring?

Full-attention scoring is the core computational mechanism within a Cross-Encoder that enables rich, token-level interaction between a query and a candidate document.

Full-attention scoring is the mechanism where every token in a query attends to every token in a candidate document simultaneously through a transformer's self-attention layers. Unlike Bi-Encoders that produce isolated vector representations, this joint encoding allows the model to compute token-level interaction weights, capturing exact match signals, lexical overlap, and fine-grained semantic alignment in a single forward pass.

This exhaustive pairwise attention generates a highly expressive joint representation, typically pooled via the [CLS] token, to produce a precise relevance score. While computationally expensive—requiring O(n*m) attention computations for a query of length n and document of length m—this mechanism provides the highest re-ranking precision, making it the standard final stage in multi-stage retrieval architectures where latency budgets permit.

MECHANISM DEEP DIVE

Key Characteristics of Full-Attention Scoring

Full-Attention Scoring is the defining computational mechanism of Cross-Encoder architectures. Unlike Bi-Encoders that compress text into isolated vectors, this process allows every token in the query to attend directly to every token in the candidate document, enabling rich, granular semantic interaction.

01

Joint Input Encoding

The query and candidate document are concatenated into a single sequence: [CLS] query [SEP] document [SEP]. This unified input is fed through the transformer simultaneously. Because the model processes both strings as one contiguous context, the self-attention mechanism can establish direct token-to-token relationships across the query-document boundary from the very first layer.

02

Token-Level Interaction Matrix

The core of full-attention scoring is the attention matrix. For a query of length m and a document of length n, the model computes an (m+n) x (m+n) attention grid. This allows the model to weigh specific alignments, such as matching the query token 'Python' against document tokens 'snake' (low weight) versus 'programming' (high weight), capturing exact match signals and lexical overlap that Bi-Encoders miss.

03

Contextualized Cross-Matching

Unlike static embedding comparisons, full-attention scoring is context-dependent. The representation of a document token shifts based on the query it is paired with. For example, the word 'bank' in a document will be contextualized differently when the query is 'financial institutions' versus 'river erosion'. This dynamic adaptation is impossible in Bi-Encoder architectures where document vectors are pre-computed and frozen.

04

Relevance Score Aggregation

After the final transformer layer, the model must produce a single scalar relevance score. The most common method uses the [CLS] token representation, which has aggregated information from the entire sequence. This vector is passed through a linear classification head to output a logit, which is then converted to a probability via a sigmoid function, representing the likelihood of relevance.

05

Computational Complexity

The expressiveness of full-attention scoring comes at a significant cost. The self-attention operation scales quadratically with the combined sequence length: O((m+n)²). This makes it computationally prohibitive to apply against millions of documents in real-time. Consequently, it is strictly reserved for a re-ranking phase, applied only to the top-k candidates (e.g., top 100) retrieved by a fast Bi-Encoder or lexical system.

06

Pairwise vs. Pointwise Scoring

Full-attention scoring can be applied in two modes:

  • Pointwise: A single query-document pair is scored independently, producing an absolute relevance probability.
  • Pairwise: Two documents are scored simultaneously against the same query to predict which is more relevant. This is exemplified by DuoBERT, which uses a [CLS] query [SEP] docA [SEP] docB [SEP] input format to learn fine-grained comparative distinctions.
RETRIEVAL ARCHITECTURE COMPARISON

Full-Attention vs. Bi-Encoder vs. Late Interaction

A technical comparison of the three primary neural ranking paradigms, contrasting their interaction mechanisms, computational profiles, and optimal deployment stages in a multi-stage retrieval pipeline.

FeatureFull-Attention (Cross-Encoder)Bi-Encoder (Dual-Tower)Late Interaction (ColBERT)

Interaction Mechanism

Every query token attends to every document token simultaneously via full self-attention

Query and document are encoded independently; interaction occurs only via final dot-product

Token-level interaction is delayed until the final MaxSim scoring step

Query-Document Coupling

Joint encoding; query and document must be processed together at inference time

Decoupled encoding; documents can be pre-indexed offline

Decoupled encoding; document token embeddings are pre-computable and indexable

Exact Match Sensitivity

Pre-Computable Document Representations

Inference Latency (per candidate)

10-50 ms

< 1 ms

1-5 ms

Typical Retrieval Stage

Final re-ranking of top-k candidates (k < 100)

First-stage retrieval over millions of documents

Second-stage re-ranking of top-k candidates (k < 1000)

Scoring Granularity

Holistic pair-level relevance score via [CLS] token

Single vector-level cosine similarity

Sum of token-level maximum cosine similarities (MaxSim)

Memory Footprint for Indexing

N/A (no pre-indexing possible)

Low: single dense vector per document

High: set of token embeddings per document

FULL-ATTENTION SCORING

Frequently Asked Questions

Clear answers to the most common questions about the Cross-Encoder's core mechanism for joint query-document processing.

Full-attention scoring is the core mechanism of a Cross-Encoder where every token in the query attends to every token in the candidate document simultaneously through the transformer's self-attention layers. Unlike a Bi-Encoder that produces independent vector representations, the Cross-Encoder concatenates the query and document into a single input sequence: [CLS] query tokens [SEP] document tokens [SEP]. The multi-head self-attention mechanism then computes pairwise attention weights between all token positions, allowing the model to capture rich token-level semantic interactions, exact match signals, and lexical overlap. The final [CLS] token representation is passed through a linear classification head to produce a fine-grained relevance score. This exhaustive token-level interaction is what gives Cross-Encoders their superior precision over dot-product Bi-Encoder scoring.

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.