Yashotantra Academy logo
level 1
Curious · 0 XP
streak
0d
perfect
0
badges
0

100 XP to Apprentice

Retrieval · easy

6. Reranking with cross-encoders

Retrieve broadly, then reorder precisely.

1 min read3 questionsup to 50 XPtopic 6/12

Read in another language

AI translates the explanation and quiz text while preserving code and answer scoring.

Embedding search is a bi-encoder: query and document are encoded separately, so scoring is fast but coarse. A cross-encoder reranker feeds the query and each candidate together through a model that scores true relevance — far more accurate, far more expensive.

The standard shape: retrieve top 50-100 candidates (hybrid), rerank to the top 5-8, then generate.

python
pairs = [(query, c.text) for c in candidates]
scores = reranker.predict(pairs)                 # cross-encoder
top = [c for _, c in sorted(zip(scores, candidates), reverse=True)[:6]]

Why this pays off: - Precision at small k is what the generator actually consumes. - Fewer, better chunks reduce prompt cost *and* the lost-in-the-middle effect. - Rerankers are also where you can inject business signals (freshness, authority, product version).

Gotcha: reranking latency scales with candidate count. Cap candidates, batch the scoring, and cache reranks for repeated queries.

How to study this topic

  1. 1. Read the explanation once end to end, skipping the code.
  2. 2. Re-read the code snippets and say out loud what each line does.
  3. 3. Answer the quiz without scrolling back — that is the real check.
  4. 4. Read every explanation, even for the answers you got right.

Scoring

  • · Up to 30 XP from quiz accuracy.
  • · +15 XP for a perfect first attempt.
  • · +5 XP while a 3-day streak is running.
  • · 75% or higher marks the topic complete.

Check your understanding

  1. 1. How does a cross-encoder reranker differ from embedding search?

  2. 2. What is the usual candidate flow in a reranked pipeline?

  3. 3. What is the cost of reranking?

Badges

First light
Pass your first topic
Sharp shooter
3 perfect first-try quizzes
On a roll
Study 3 days in a row
Week warrior
Study 7 days in a row
Grinder
Earn 500 XP
Deep diver
Earn 1500 XP