Loading…
Glossary term
Re-ordering retrieved results with a more precise model to put the best ones first.
First-stage retrieval is fast but rough. A reranker, a more precise model, takes the top candidates, reads the query and each passage together, and re-scores them so the best come first.
It is slower per item, so it is applied only to a short list.
Rerank with a cross-encoder
from sentence_transformers import CrossEncoder
ce = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
scores = ce.predict([(query, doc) for doc in candidates])
best_first = [d for _, d in sorted(zip(scores, candidates), reverse=True)]Reranking often gives a large quality boost to RAG and search for modest cost.