Re-ranking and Cross-Encoder
Brief
Re-ranking is a re-sorting of found fragments where the re-ranker model evaluates the pair «query + fragment» and leaves only the most relevant ones.
Why is re-ranking needed
A typical vector search returns 10–20 candidates, but the most useful fragments do not always occupy the top positions. If all candidates are sent to an LLM, token costs increase and the response becomes less accurate.
Re-ranking solves this: it takes the candidates and re-sorts them.
How Cross-Encoder works
Cross-Encoder is a model that takes a pair of texts at once:
query + fragment → relevance score
Unlike embeddings, which encode the query and document separately, Cross-Encoder sees them together. Therefore, it better understands how well a fragment answers the question.
Process flow
flowchart LR
A[Query] --> B[Vector search]
B --> C[Top-20 candidates]
C --> D[Cross-Encoder]
D --> E[Top-3 fragments]
E --> F[LLM prompt]
Popular re-rankers
- Cohere Rerank — a managed cloud service.
- bge-reranker — an open-source model from BAAI.
- Cross-Encoder from Sentence Transformers — a local option.
When to use re-ranking
- the knowledge base is large;
- answers require high accuracy;
- it is important to save LLM tokens.
For small prototypes, a basic vector search may suffice.