Page 1 of 8~112 min topic

Re-ranking lab

Frame the hybrid retrieve-and-rerank experiment

Ship a falsifiable slice of **hybrid BM25+vector retrieve then cross-encoder rerank for error-code FAQs** — success is query 'connection reset while uploading' ranks doc:e-conn-reset #1 after rerank, not a polished screenshot.

~14 min this pageExperiment brief

1Try it yourself

Decision drill

Re-rank retrieval lab

Pick keyword, vector, or hybrid+re-rank for each query — then merge top hits.

Retrieval fit70%

1/3Find ticket SKU-8842 in support docs.

2Learn the idea

Read

Name the operable slice

This lab builds hybrid BM25+vector retrieve then cross-encoder rerank for error-code FAQs. The human in the loop is support agent asking about E_CONN_RESET wording variants. Scope is intentionally narrower than “make AI reliable”: you will prove one oracle — query 'connection reset while uploading' ranks doc:e-conn-reset #1 after rerank — and one invariant — top-1 after rerank must beat BM25-only nDCG@5 on gold; latency budget ≤ 120ms for rerank. Record non-goals in your notes so a later change cannot silently expand authority. The incident mnemonic for the chapter is RERANK-FLAT-55; design as if that ticket is already written and you are filling evidence.

Read

Write the acceptance contract

Turn the oracle into a table: input fixture, expected observable, prohibited side effect, owner, latency/cost ceiling. Separate model taste from software correctness — transport, auth, parsing, and termination must be deterministic even when generated text varies. Primary metric family: nDCG@5 and rerank_ms p95. Averages without a denominator or revision label do not gate release. Fake external dependencies in unit tests; live calls wait until fakes pass.

Read

Implementation artifact

PIPELINE = ["bm25", "vector", "rrf_fuse", "cross_encoder_top10"]

Read

Freeze the first red test

Before implementation, encode a failing check that would have caught reranker scores all candidates near 0.5 — order equals retrieve order. That failure is the pedagogical north star for later pages: contracts reject it, happy path never performs it, validation asserts it, failure-handling contains it, observability detects it, security-ops prevents privilege tricks around it, and mastery replays it in a drill. Endpoint under study: POST /v1/search/rerank.

Read

Stage depth

Capacity note for planners: estimate peak demand on POST /v1/search/rerank and the cost ceiling for a failed retry storm. Write the abort conditions — unbounded spend, cross-tenant leakage, or inability to roll back — before you enjoy the first green test. Prefer synthetic fixtures shaped like production over anonymized production dumps you cannot share in class. When you are tempted to widen scope, re-read the oracle (query 'connection reset while uploading' ranks doc:e-conn-reset #1 after rerank) and cut features that do not serve it. The teaching outcome is judgment under constraints: support agent asking about E_CONN_RESET wording variants gets a trustworthy control, not a kitchen-sink framework. Keep the language of release decisions: promote, hold, or roll back — never “see if it gets better.”

Read

Field notes for `re-ranking-lab` / `lab-goal`

Decide what will live in version control on day one: fixtures, contract markdown, and a failing test name. Write the cost ceiling as a hard number with currency and period. If the lab involves clusters, name the non-prod context you will use and forbid prod kubecontexts in scripts. Capture the baseline metric once before changing code so later gains are comparative. Refuse tools that hide the request path behind magic macros until the oracle is green on fakes. Your README section for this page should be five lines or fewer and still falsifiable. In this chapter the product is hybrid BM25+vector retrieve then cross-encoder rerank for error-code FAQs, the human stakeholder is support agent asking about E_CONN_RESET wording variants, and the incident id you design against is RERANK-FLAT-55. Re-state the oracle in your notes — query 'connection reset while uploading' ranks doc:e-conn-reset #1 after rerank — and keep the invariant visible: top-1 after rerank must beat BM25-only nDCG@5 on gold; latency budget ≤ 120ms for rerank. Track nDCG@5 and rerank_ms p95 as the scoreboard. Surface under change control: POST /v1/search/rerank. If you only have forty minutes, finish the fixture for reranker scores all candidates near 0.5 — order equals retrieve order before polishing UI. Promotion language stays ternary: promote, hold, or roll back based on evidence, not hope.

Go deeper

Before you start

Why this matters

Write the single done-definition a reviewer would accept for Re-ranking lab (RERANK-FLAT-55). Include the numeric gate hidden in this oracle: query 'connection reset while uploading' ranks doc:e-conn-reset #1 after rerank. Then name the fake success you refuse: a demo that ignores reranker scores all candidates near 0.5 — order equals retrieve order. Keep the sentence beside your editor; every later page should make this sentence easier to prove.

Check your understanding

Page assessment

Answer from memory. Completion is saved from this evidence, not from opening the next page.

1. Is the oracle (query 'connection reset while uploading' ranks doc:e-conn-reset #1 after rerank) falsifiable from a fixture?
2. Is the invariant (top-1 after rerank must beat BM25-only nDCG@5 on gold; latency budget ≤ 120ms for rerank) stated without hand-waving?
3. Does the contract name RERANK-FLAT-55 as a risk you design against?

All responses are required.