Notes

Cross-Encoder

Ask a model whether a question and a passage belong together and there are two ways to let it look. It can read each text separately and compare the two summaries, or it can read both at once, side by side. A cross-encoder is the second arrangement.

Both texts, one forward pass
The pair is concatenated into a single input, separated by a special token, and passed through one encoder such as BERT. Self-attention then runs across the whole thing, so every token of the query can attend to every token of the document, and a small classification head on top emits a single relevance or similarity score. Neither text is ever encoded on its own.

Accuracy, and what it costs
That full interaction makes cross-encoders the accuracy ceiling on pairwise tasks — passage re-ranking, natural language inference, duplicate-question detection, semantic textual similarity. It also rules out scale. The score exists only for the pair you actually ran, so there is nothing to precompute and no index to build; ranking a million documents would mean a million forward passes.

The standard two-stage arrangement
Production systems combine the patterns. A bi-encoder retrieves a few hundred candidates from a vector index in milliseconds, then a cross-encoder re-ranks only that shortlist. The sentence-transformers library ships cross-encoders trained on MS MARCO for precisely this second stage. Skip the re-ranker and the top of the results list stays visibly weaker; apply it to the whole collection and the latency budget disappears.

A cross-encoder scores a pair of texts by feeding both into a single transformer at once, so attention runs across the pair and the model emits one relevance or similarity value. It is the most accurate option for ranking, inference and similarity tasks and the least scalable: nothing can be precomputed, so every candidate pair costs a forward pass. Standard practice is re-ranking a shortlist first retrieved by a bi-encoder.

Picture two ways of deciding whether a job application fits a job advert. You could read each one separately, jot down a summary of it, and then compare your two summaries. Or you could lay them side by side and read them together, noticing every point where they line up.

A cross-encoder is software doing the second thing with two pieces of text — a question and a possible answer, say. Because it reads them together, its judgement of the match is far more reliable. The catch is that it has to do the whole reading job again for every new pair, so it is used to double-check a short list, not to search millions of documents.