CodeQuest101Advanced RAGChapter Studio
Advanced RAG

8 chapters · Learn by building

RAG basics

Chapter 04 / 08

Find candidates. Then read more closely.

Inspect how a cross-encoder changes the order of a limited candidate set.

The idea, in plain words

Score the question and passage together

The first retriever quickly selects possible passages. A cross-encoder then reads the question and each candidate together to score their relevance more closely.

This lesson uses recorded real model outputs. Increasing the candidate pool gives the reranker more passages to inspect, but requires more query–passage scoring work.

1

Take only the candidate pool produced by the first retrieval stage.

2

Pair the original question with each candidate passage.

3

Read the recorded cross-encoder score for each pair.

4

Sort those candidates again and compare the source evidence.

Decision inspector

Follow the evidence.

D1Eligibility
Dense rank 1cosine 0.598
Sparse rank 2BM25 6.267
Reranked 1 → 1logit 0.947

Opened packaging is allowed, provided the item has not been used.

Opened packaging and returns · D1-s2

A pair model can use interactions between the question and passage that independent embeddings do not score directly.

Math & code

Score each (question, candidate) pair once; sorting never introduces a new passage.

candidates = retrieve(question)[:pool_size]
ranked = sort_by_cross_encoder(question, candidates)
Developer’s reasoning

Reranking cannot recover a passage absent from its candidate pool, and it can still rank incorrectly. Raw model logits are not confidence percentages.

Sources & model provenance

sentence-transformers/all-MiniLM-L6-v2 · 384D · mean pooling + L2 normalization.

cross-encoder/ms-marco-MiniLM-L6-v2 · recorded raw logits.

Rewrites, subquestions, HyDE text, and answer claims are authored teaching examples.

Encoder revision onnx-sha256:4f148ba8ae9c2c7fbee4af2b132db8d06c6a6545b47fc83bbb98c3d22b8393e6

Reranker revision 233902d25c440f23af6f7d6e94d2946bac0bee0a

Corpus SHA256 d1c21da297e88785f9a6ac434e0a58f3e10975052a48419ba511145d461f704e

Current sources only; archived documents D9 are excluded before retrieval.

Reranking · Score the question and passage together