﻿# Cross-encoders let a query and document interact before scoring

A cross-encoder jointly processes a query and document so their tokens interact before scoring. Understand pair attention, reranking cost and differences from a dual encoder.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/crossencoder-joint-pair-attention/
Language: en

A cross-encoder receives a query and document together and produces a score from their joint representation. Its defining property is interaction before the final comparison. This makes it different from a dual encoder that compares separately produced vectors, and explains why cross-encoders are commonly used on a selected candidate set.

## Build a joint pair representation

The pair is serialized according to the model’s tokenizer and architecture, with the appropriate boundary markers and masks. Within a typical bidirectional encoder setup, permitted query and document positions can attend across the pair. Hidden document states can therefore change when the query changes, even if the document text stays fixed. The scoring head then consumes the model’s designated representation. Exact pooling and head details belong to the checkpoint; the broad cross-encoder label does not specify every possible relevance objective or output scale.

## Interaction can resolve query-dependent distinctions

Imagine a document stating that a server supports a device but not a particular driver. A query about device availability and a query about driver compatibility need different relevance judgments over the same text. Joint encoding can represent query-dependent token relationships before the score is computed. This describes capacity, not a promise that the trained model handles negation correctly. A deliberately contrasting fixture can test the behavior. The useful distinction from a dual encoder is where interaction occurs, rather than an assumption that one architecture always wins every retrieval task.

## Precomputation has a different limit

A separately encoded document vector can be reused across many queries in a dual-encoder index. In a joint cross-encoder, the document’s intermediate states generally depend on the current query, so a universal cached vector does not replace the full pair computation. This motivates a pipeline that first retrieves candidates cheaply and then scores a smaller set jointly. The candidate stage still bounds recall: a relevant document absent from that set cannot be promoted by the reranker. Evaluate candidate selection and reranking separately before attributing an end-to-end failure.

## Verify input boundaries and score interpretation

A small test should show the serialized pair, truncation policy, eligible attention positions and raw scoring output. Truncation can remove precisely the passage needed to judge relevance. A scalar logit or ranking score is not automatically a calibrated relevance probability, even when a sigmoid is available. Preserve the training objective and documented interpretation of the head. This produces a concrete reranking contract and lets the reader distinguish pair-format errors, missing evidence, candidate omissions and genuine model mistakes rather than folding every issue into the word accuracy.

## Primary research and implementation references

- [BERT: Pre-training of Deep Bidirectional Transformers](https://arxiv.org/abs/1810.04805).

- [Dense Passage Retrieval for Open-Domain Question Answering](https://arxiv.org/abs/2004.04906).

- [Sentence-BERT: Sentence Embeddings Using Siamese BERT-Networks](https://arxiv.org/abs/1908.10084).

## Related engineering context

[Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [A GPU inference benchmark you can trust](/journal/inference-benchmark-method/).
