# Cross-encoder

> Canonical: https://skillalmanac.com/glossary/cross-encoder | Last verified: 2026-11-24 | Index status: not offered to search engines

A cross-encoder is a model that reads a query and a candidate text together as one input and outputs a single relevance score for the pair. It is usually run on a short list to reorder it.

Also called: cross encoder, cross-encoders, cross encoder reranker, CrossEncoder.

## In plain language

Suppose you ask a librarian for books about growing tomatoes in cold climates. A fast helper pulls forty books by skimming titles. A cross-encoder is the careful reader who then takes your question and each book's description side by side and decides how well each one fits. Reading the question and the text together catches details a quick skim misses. The cost is time: the careful reader has to look at every pair afresh, so it is not practical for searching millions of items directly. It is used on the short list. It can still misjudge a pair, and it ranks what the first step found, not what was missed.

## Technical definition

A cross-encoder scores a pair of inputs, such as a query and a candidate passage. The Sentence Transformers documentation says it "Calculates a similarity score given pairs of inputs", and that it is often slower than a bi-encoder because it computes per pair instead of per text. The usual pattern is retrieve and re-rank: a bi-encoder or keyword search fetches the top candidates, then the cross-encoder scores each (query, hit) pair. Nogueira and Cho (arXiv 1901.04085) adapted BERT for passage re-ranking in this way.

## How it shows up when you use agents

You may not call a cross-encoder yourself in Claude Code, Codex or Cursor. It appears inside retrieval pipelines that an agent or an MCP server relies on: a search step returns candidates, and a cross-encoder reorders them before the best few are placed in the prompt. The step is called [reranking](/glossary/reranking). In a [retrieval-augmented generation](/glossary/retrieval-augmented-generation) system, it is one way to improve what reaches the model's [context window](/glossary/context-window).

What breaks when it is misunderstood: people try to use a cross-encoder as the first search over a whole collection. The Sentence Transformers documentation notes that cross-encoders do not scale well to large datasets, so they are used on a short list. Another failure is expecting it to find missing documents. It reorders what the first step returned, so if the right passage was never retrieved, the re-ranker cannot recover it.

A next action: log the top retrieved passages for a failing question. If the right passage is in the list but low, re-ranking can help. If it is absent, fix [chunking](/glossary/chunking) or the first search. Re-ranking also adds a model call per candidate, so check the latency and cost it adds, and remember it needs pairs of query and text rather than single texts.

## Common confusions

- **Cross-encoder versus bi-encoder.** A bi-encoder embeds each text separately, so embeddings can be stored and compared quickly. A cross-encoder reads the pair together and produces a score, not an embedding.
- **Cross-encoder versus reranking.** Reranking is the job. A cross-encoder is one kind of model that does it.
- **Myth.** A cross-encoder replaces the vector search. In the pattern the documentation describes, a bi-encoder retrieves first and the cross-encoder re-ranks the hits.
- **Cross-encoder versus embedding model.** The cross-encoder scores relevance for one pair. You cannot compare its output with other texts later, because there is no stored vector.

## Worked examples in this catalogue

### [What Is RAG? Retrieval-Augmented Generation Explained](https://skillalmanac.com/learn/what-is-rag)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The guide describes indexing documents and querying them, and advises logging the top retrieved chunks for each failing question to check whether the right passage reached the prompt.

Why it exercises the concept: A cross-encoder sits between retrieval and the prompt. The guide's habit of inspecting the retrieved list shows you where such a re-ranking step would act.

### [rag-chunking-planner](https://skillalmanac.com/skills/skill-almanac/rag-chunking-planner)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Your documents chunked by three strategies, with defects and offline recall reported for each, so chunk settings are chosen with numbers.

Why it exercises the concept: A re-ranker can reorder only what the first search returns. Measuring recall of that first step tells you whether re-ranking is the right fix.

### [library-docs-lookup](https://skillalmanac.com/skills/skill-almanac/library-docs-lookup)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: An answer to a library question drawn from the installed package's own files, with file and line cited.

Why it exercises the concept: It is retrieval for a coding agent. It shows a setting where a candidate list is produced first and could then be ordered by a finer relevance score.

## Related terms

- [Reranking](https://skillalmanac.com/glossary/reranking.md)
- [Embedding](https://skillalmanac.com/glossary/embedding.md)
- [Semantic search](https://skillalmanac.com/glossary/semantic-search.md)
- [Retrieval-augmented generation (RAG)](https://skillalmanac.com/glossary/retrieval-augmented-generation.md)
- [BERT](https://skillalmanac.com/glossary/bert.md)
- [Transformer](https://skillalmanac.com/glossary/transformer.md)

## Sources

- [Cross-Encoder usage](https://www.sbert.net/docs/cross_encoder/usage/usage.html), Sentence Transformers (accessed 2026-11-24)
- [Cross-Encoders: applications](https://www.sbert.net/examples/cross_encoder/applications/README.html), Sentence Transformers (accessed 2026-11-24)
- [Passage Re-ranking with BERT](https://arxiv.org/abs/1901.04085), arXiv (Nogueira and Cho) (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
