liveBook · Manning

Reranking

As explained in AI-Powered Search

A reranker is a search component that reorders an initially retrieved or ranked set of results using additional relevance information.

A search for “mountain hike” can quickly find plausible pages, yet put the most useful page below weaker matches. Reranking makes a second pass over retrieved candidates, scoring and reordering them with additional relevance information. The first pass keeps retrieval fast; the second can spend more work on a smaller result set. Pipeline results can also be combined before this final pass. section 13.8 section 10.1.2 section 7.1

Choose the second-pass signal to match the ranking problem:

  • Use a learning-to-rank model when multiple features should inform relevance. A fast function such as BM25 can produce candidates; the model then reranks a top subset, preferably inside the search engine when supported. section 10.1.2
  • Use a cross-encoder when query–document pairs merit closer examination. Retrieve with a bi-encoder or lexical search, score each candidate paired with the query, then sort by score. section 13.8
  • Use a personalization vector to reorder product results by similarity to a weighted combination of the query and relevant past interactions. Filter interactions by query-related clusters to guard against unrelated preferences. section 9.4.3
  • Use full-precision embeddings to rerank an over-requested set from a compressed or approximate vector index. Compare recall, search time, and index size rather than assuming the cheaper first pass is accurate enough. section 13.7.1 section 13.7.5

Rerank a small search window

For “mountain hike,” retrieve 50 title results, pair the query with each title, score the pairs with a cross-encoder, and display the top 10 after sorting. A listed result about mountain exposure scores 0.578 after reranking. The implementation needs only the candidate documents and their new scores for this final ordering step. section 13.8

Listing 13.28 Reranking search results with a cross-encoder
from sentence_transformers import CrossEncoder
cross_encoder = \  #1
  CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")  #1

query = "mountain hike"
search_results = semantic_search_with_engine(  #2
  embeddings_collection, query, limit=50)  #2
pairs_to_score = [[query, doc["title"]]  #3
                  for doc in search_results]  #3
cross_scores = cross_encoder.predict(pairs_to_score,  #4
                 activation_fct=torch.nn.Sigmoid())  #5
reranked_results = rerank(search_results, cross_scores) #6
display_results(query, reranked_results[:10])

The Python listing shows candidate retrieval, query–title pair construction, cross-encoder scoring, and the final rerank call. section 13.8

Reranking changes order, not which documents the first pass admitted. In lexical-first hybrid search, lexical matching alone selects documents while vector scores determine their order; a broader OR match gives that second pass more candidates than a restrictive AND match. Wider windows and more expensive scoring can improve results but add work. Reranking can also order question-answering predictions by reader confidence rather than document relevance. Evaluate the effect in its intended context: an Int8 search example raised recall from 0.9289 to 1.0 after full-precision reranking, while a more aggressively optimized combination reached 0.7244 after reranking. section 15.5.2 section 14.5.3 section 13.7.1 section 13.7.5

How AI-Powered Search covers it

How deep it goes
Works through candidate selection, second-pass scoring, Python implementations, and speed–recall trade-offs; model training is treated separately.
Examples
Uses “mountain hike” cross-encoder scores, “microwave” product personalization, and quantized-index recall comparisons.
What it assumes
Builds on an initial retrieved result set and query–document scoring; demonstrates use of a pretrained cross-encoder without requiring fine-tuning.
What you can do after
Build it from scratch by retrieving candidates, scoring them with a chosen second-pass signal, sorting them, and checking relevance or recall against cost.
How it connects
Connects BM25, learning to rank, dense vector search, quantization, personalization, cross-encoders, and hybrid search.

Also explained in

Compare how 3 books explain reranking →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.