05 · Build and rerank a shortlist
Find the current F-250 manual, then decide whether a missing answer calls for more candidates or a better order.
- Part 2
- Build the evidence layer
- Model
all-MiniLM-L6-v2 · ms-marco-MiniLM-L6-v2- Data
- Synthetic helpdesk tickets and document corpus
- Hardware
- Tesla T4 and CPU, in Google Colab
Put the right page in front of the desk
You are helping a signed-in operator at north-yard. The desk remembers that the operator is asking about fan F-250. The operator needs its maximum operating temperature. A shift handoff mentions the same fan and temperature readings. The current manual supplies the limit.

north-yard · Signed-in operator · Saved fan F-250
“What is its maximum temperature?”
Change one phrase
“What is its thermal limit?”
Same saved fan, caller and document pool.
Current F-250 manual · r3
Equipment manual for F-250 (revision r3). Maximum operating temperature: 101 C.
F-250 shift handoff
Equipment F-250. Temperature readings were handed over to the incoming shift.
The desk reads three passages. Predict whether “thermal limit” keeps the current manual in view.
Check the recorded wording change
Expected. Answer 101 °C from the current manual in both cases.
BM25. The manual moved from rank 1 to 17, so the reader asked for clarification.
MiniLM dense. The manual stayed at rank 1 and the reader gave the expected answer.
Check the two places the search can fail
Manual missing from the shortlist. Change the candidate search. Reordering the existing list cannot add a document.
Manual below the reader’s three passages. Keep the candidates and change their order, or let the reader see more.
Excerpts from two synthetic documents, shown side by side. Representative fan photo, cropped. Augapfel, CC BY 2.0.
If the manual stays on the shortlist but drops below the reader’s three passages, what would you change?
The shortlist held all the evidence. The first three passages often did not.
32 development tickets across eight equipment families, same authorised pool and reader
1Evidence seen
Mean evidence recall at 20 and tickets with all sources at three
aRanking and final outcome
Mean nDCG@10 and tickets with exact decision, value and evidence
bSearch the operator’s authorised documents
Trust the signed-in role and tenant before scoring either list. The query can identify an asset. It cannot grant access to it. Place the saved F-250 identifier in the query for a follow-up. BM25 lowercases the text and keeps a hyphenated identifier such as F-250 intact. MiniLM encodes the query, then scores it against cached, normalised vectors from the same tenant using an exhaustive dot product.
# An operator sees the document IDs registered to that tenant.
def eligible_ids(case):
if case["role"] != "operator":
return ()
return ids_by_tenant.get(case["tenant"], ())
def lexical_tokens(text):
return re.findall(r"[a-z0-9]+(?:[-_][a-z0-9]+)*", text.lower())Keyword and dense search make different mistakes. In the measured paraphrase “Please help. What’s the thermal limit, in C, of V-200?”, BM25 found the manual at rank 8 and returned clarify. MiniLM dense put it in the reader’s window and returned 87 °C. On the exact-identifier slice, all four methods passed all four tickets. Etsy reported a 10% lift in offline purchase NDCG from its custom domain text embeddings after finding off-the-shelf embeddings suboptimal for its task. That is a reason to inspect both kinds of query when borrowing a model. Etsy Engineering, company-reported.
In a wider catalogue, candidate recall still deserves its own test. DoorDash reported nearly 30% more popular-dish carousel triggers relative to its baseline after changing query and catalogue understanding as well as ranking signals. That metric counts a product surface appearing. Here, recall measures whether labelled evidence reaches a fixed shortlist. DoorDash Engineering, company-reported.
Fusion helped two-source questions; reranking helped follow-ups
Strict passes by query type, count out of the development tickets in each slice
2| Query type | BM25 | MiniLM dense | RRF | RRF + cross-encoder |
|---|---|---|---|---|
| Exact identifier | 4/4 | 4/4 | 4/4 | 4/4 |
| Paraphrase | 0/4 | 4/4 | 4/4 | 4/4 |
| Inspection date | 8/8 | 8/8 | 8/8 | 8/8 |
| Two sources | 2/8 | 0/8 | 4/8 | 4/8 |
| Follow-up | 4/8 | 6/8 | 6/8 | 8/8 |
Descriptive slice counts. Several tickets are rewordings from the same equipment family.
Merge ranks before you rescore pairs
Retrieval finds candidates; reranking orders those candidates more carefully. The reranker cannot recover a relevant document that never entered the shortlist. Measure the two stages separately.
BM25 and MiniLM assign scores on different scales. Reciprocal rank fusion (RRF) merges one-indexed positions. A passage gets a vote from each ranking it appears in. A higher position gives a larger vote.
scores = defaultdict(float)
for ranking in rankings:
for position, document_id in enumerate(ranking, start=1):
scores[document_id] += 1 / (FUSION_OFFSET + position)The offset is the notebook’s setting. It controls how quickly the contribution falls with rank. Elastic reported an average 18% relative increase in nDCG@10 over BM25 when fusing BM25 with ELSER on a BEIR subset. ELSER was a learned sparse method. The same rank rule can combine different retrievers, so measure the actual pair you intend to serve. Elastic Search Labs, company-reported.
The notebook takes the first 20 fused passages and passes each query and passage together to the cross-encoder. It checks that the list contains the same members after reranking. Holding the shortlist fixed lets you attribute any change in the first three passages to ordering.
shortlist = fused[:SHORTLIST]
pairs = [(query, documents_by_id[key]["text"]) for key in shortlist]
rescored, reranking_ms = timed(lambda: rerank(pairs, shortlist))
assert len(rescored) == len(shortlist)
assert set(rescored) == set(shortlist)For one ticket, Recall@20 divides the number of required IDs in the shortlist by the number of required IDs. Complete evidence at rank 3 requires every ID to be present. nDCG@10 gives each required passage more credit near the top, then divides by the score from ideal ordering.
For a two-source question, a ranking can earn partial recall and good early-position credit while still failing the complete-evidence check. In Microsoft’s separate BEIR benchmark, company-reported nDCG@10 on its 0–100 scale rose from 45.0 with vector retrieval to 48.4 with hybrid retrieval and 50.0 with hybrid plus semantic ranking, which rescored the first 50 results. Microsoft Engineering, Table 1.
Locate the first failure
Check the shortlist for all required IDs. Then check the reader window. If both checks pass and the answer is wrong, inspect the reader. The shared CPU reader checks the target asset and source type, extracts known fields with regular expressions, and asks for clarification when a required source cannot be read. It makes no text-generation call.
# Add values only from passages the reader can actually inspect.
for key in ranking[:ANSWER_DEPTH]:
row = documents_by_id[key]
if row["tenant"] != case["tenant"] or row["asset"] != target or row["source"] not in needs:
continue
match = FIELD_PATTERNS[row["source"]].search(row["text"])
if match:
found.setdefault(row["source"], (match.group(1), key))
if any(source not in found for source in needs):
return {"decision": "clarify", "value": "", "evidence": []}A strict pass matches the expected route, value and evidence IDs. In these fixtures the reader passed whenever it saw all required evidence, so strict passes and complete evidence at three have the same counts. The reader is a control for testing retrieval quality. A generative reader could add failures even when the right passages are present.
Every recorded failure came from the reader’s depth limit
Where each of the 32 development tickets first failed, or passed
3Strict pass · Evidence below rank 3
All four methods recorded zero shortlist misses, zero reader errors with complete evidence, and zero tickets with no relevant hits.
Now grade the F-250 wording change. Every method ranked the current manual first for the original wording and returned the correct outcome. With the new wording BM25 still found the manual, at rank 17. RRF raised it to four, just outside the reader’s window. The cross-encoder moved the same manual to two. MiniLM dense already ranked it first. The new wording is an extra probe, outside the main comparison.
One wording change pushed the F-250 manual out of the reader’s view
One-indexed rank of the current manual. A highlighted cell means it reached the reader.
4| Method | Maximum temperature | Thermal limit |
|---|---|---|
| BM25 | #1 · answer | #17 · clarify |
| MiniLM dense | #1 · answer | #1 · answer |
| RRF | #1 · answer | #4 · clarify |
| RRF + cross-encoder | #1 · answer | #2 · answer |
F250-00 · “What is its maximum temperature?” · F-250 saved · north-yard operator
- Expected
- answer · 101 · [manual-F-250-r3]
- All four methods
- answer · 101 · [manual-F-250-r3]
Current manual at rank 1 in each list.
F250-00-thermal · “What is its thermal limit?” · same scope and expected manual
- Expected
- answer · 101 · [manual-F-250-r3]
- BM25 · rank 17
- clarify · empty value · []
- MiniLM dense · rank 1
- answer · 101 · [manual-F-250-r3]
- RRF · rank 4
- clarify · empty value · []
- RRF + cross-encoder · rank 2
- answer · 101 · [manual-F-250-r3]
The same candidate remained on every shortlist. Its rank decided whether the reader could use it.
F221-01 · “Please help. For V-221, which system supports it and when was its most recent inspection?”
- Expected
- answer · 2025-06-06 | S-621 · [inventory-V-221-r3, graph-V-221-r3]
- RRF
- answer · 2025-06-06 | S-621 · [inventory-V-221-r3, graph-V-221-r3]
- RRF + cross-encoder
- clarify · empty value · []
Both methods had the graph at rank 1. Reranking moved the required inventory from rank 2 to rank 7, beyond the reader’s view.
Price the extra stage
The notebook times the lexical retrieval, query encoding and dense scoring, fusion and cross-encoder scoring around each operation. It synchronises the accelerator at the timer boundaries, excludes the warm-up query and adds the stages used by each method. The p95 is the 31st observation out of 32 when sorted by time, so use it as a description of this sample. The reranker’s token count measures the unpadded query–passage input across all its pairs after truncation.
Reranking brought p95 from 25.2 to 75.3 milliseconds
Warm search and ranking, median to nearest-rank p95. Log scale in milliseconds.
5Cross-encoder stage p95 51.4 ms. Per-query median input was 814.5 tokens across the cross-encoder pairs. These timings exclude the reader, model load and indexing.
The reranked policy fixed four tickets and broke two relative to RRF. The paired change subtracts the two pass indicators ticket by ticket, then averages those differences. When resampling for the interval, move each equipment family’s rewordings together. The incremental interval crosses zero, even though the fixed-reader score is higher. In the BEIR paper the cross-encoder improved BM25 across most evaluated sets, with ArguAna and Touché-2020 among the exceptions. Look at lost tickets alongside wins before allocating more compute. Thakur et al., paper-reported.
Fusion beat BM25. The rerank increment was inconclusive.
Paired change in percentage points. Each line joins the limits of the 95% family-bootstrap interval.
6What to keep
| Method | Recall@20 | Complete@3 | nDCG@10 | Strict pass | Median / p95 |
|---|---|---|---|---|---|
| BM25 | 100% | 18/32 | 0.773 | 18/32 | 0.55 / 0.88 ms |
| MiniLM dense | 100% | 22/32 | 0.749 | 22/32 | 14.2 / 24.6 ms |
| RRF | 100% | 26/32 | 0.856 | 26/32 | 15.0 / 25.2 ms |
| RRF + cross-encoder | 100% | 28/32 | 0.970 | 28/32 | 45.5 / 75.3 ms |
BM25 builds a lexical index and MiniLM builds a document embedding cache. RRF uses both. The cross-encoder adds per-query passage scoring. Evidence below rank three was the dominant failure for every arm.
- Check candidate coverage first. A missing document calls for a different candidate search. A document below the reader’s depth calls for an ordering or depth comparison.
- Check for regressions. Reranking rescued the F-250 wording change and hid a needed V-221 inventory row. Measure complete evidence for two-source tickets before switching.
- Keep access checks ahead of retrieval. Both lists must come from the same authorised pool. Hold the release split back for the final decision.
How it was built
| Setting | Recorded value |
|---|---|
| Cases | 32 answerable development tickets, eight equipment families, wording variants 0, 1, 3 and 4. Release split unused. |
| Candidate corpus | 96 synthetic records, 48 per tenant. Current manual, inventory and graph sources alongside maintenance notes made to share asset IDs and wording. |
| Embedding model | sentence-transformers/all-MiniLM-L6-v2 at 1110a243fdf4706b3f48f1d95db1a4f5529b4d41 |
| Cross-encoder | cross-encoder/ms-marco-MiniLM-L6-v2 at 233902d25c440f23af6f7d6e94d2946bac0bee0a |
| Cutoffs | Shortlist 20, reader depth 3, nDCG cutoff 10, RRF offset 60. Embedding batch 32, reranking batch 16, pair cap 384 tokens. No training. |
| Compare | Exact route, value and evidence. Paired bootstrap with 1,500 family draws, seed 401. |
| Hardware and software | Colab Tesla T4 for neural scoring, CPU for BM25, rank fusion and the reader. CUDA 13.0, Python 3.13.16, PyTorch 2.14.1+cu130, Transformers 4.51.3, sentence-transformers 4.1.0, rank-bm25 0.2.2. |
| Digests and raw receipts | Scorecard, development and corpus digests · Query records, rankings and corpus · Runtime |
Time and cost. The queue recorded 65.5 seconds for the notebook, including package setup. Model loading took 22.2 s, building the BM25 index took 2.59 ms and embedding the documents took 504.7 ms. Peak CUDA allocation was 213,101,568 bytes across the loaded models and scoring operations. The warm measurements above separate those setup costs from query scoring and cover local computation.
Run it yourself
Open the executed notebook beside the saved records. “Freeze the queries and permitted documents” sets up the F-250 decision and authorised search. “Retrieve, fuse and rerank” defines the shortlist. “Separate shortlist misses from ranking failures” connects the worked errors to the scorecard and costs.
- In
alternate, replace “maximum temperature” with “temperature cap”. Predict whether BM25’s manual falls below the reader window. Inspectopening_pair[].relevant_ranksandactual. - Lower
SHORTLISTwhile keepingANSWER_DEPTHfixed. Predict which method first loses a required ID. Inspectall_evidence_in_shortliston the same tickets and compare the new cutoff insettings. - Raise only
ANSWER_DEPTHfrom three to seven. Predict whether the reranked V-221 result can use the inventory at rank 7. Inspectexpected.evidence,relevant_ranksandactualforF221-01.
In Lesson 06, decide when the desk should go straight to a precise evidence source.
How is this page?
Last updated on