core-ai
Glossary ↗Reranking
Reranking is a second-stage refinement step in a search or retrieval pipeline where an initial, broad set of candidate results — retrieved quickly and cheaply via keyword search, vector similarity search, or both — gets re-scored by a more sophisticated (and computationally expensive) model that directly compares the query against each candidate to produce a more accurate relevance ranking, before the final top results are used. The reason this two-stage approach (retrieve broadly, then rerank precisely) exists rather than just running the expensive precise model on the entire corpus directly: the precise scoring models used for reranking (typically cross-encoders, which process the query and each document together in a single pass to directly compare them) are far more accurate at judging true relevance than fast vector similarity search, but are also far too slow and expensive to run across an entire corpus of thousands or millions of documents on every query — so the practical pattern is to use fast, approximate retrieval to narrow the field from millions of documents down to, say, the top 50-100 candidates, then apply the slower, more accurate reranker only to that much smaller set. This matters directly for RAG quality in SaaS products, because initial vector retrieval alone frequently returns a "good enough but not quite right" set of results — documents that are topically related but not the single best match, or ranked in a suboptimal order — and feeding that imperfect ranking straight into an LLM's context window wastes token budget on marginally relevant content and can dilute the quality of the final generated answer. A concrete worked example: a legal-tech RAG system searching a database of 500,000 contract clauses for a query about "termination for convenience" first uses fast vector search to retrieve the top 50 semantically similar clauses in milliseconds; it then runs a cross-encoder reranking model (like Cohere's rerank API or an open-source model such as a BGE-reranker) that individually scores each of those 50 candidates against the exact query, and the pipeline keeps only the top 5 highest-scoring results to actually send to the LLM — meaningfully improving answer accuracy over using the raw vector-search order directly, because the reranker catches subtle relevance distinctions the faster initial retrieval missed. Rerankers are typically offered as a simple API call (send a query and a list of candidate texts, receive back a relevance-sorted list with scores) making them a straightforward addition to an existing RAG pipeline. Rerankers also serve a second, less obvious purpose beyond pure relevance improvement: because they score each candidate independently against the query with a dedicated relevance score (not just a similarity distance), that score can be used as a confidence signal — if even the top reranked result scores below a defined threshold, the system can conclude "nothing in the corpus actually answers this well" and trigger a graceful fallback ("I couldn't find a confident answer to that") instead of forcing the LLM to generate an answer from marginally relevant context, directly reducing hallucination risk in RAG pipelines.
Related terms