Slides · GenAI system design
Coding, project defense and mock rounds
1 / 22
Coding, project defense and mock rounds
Write rank fusion by hand, defend a project with honest numbers, and turn all the drills into a three-round mock plan.
Concept
A design can be rehearsed. A defense cannot be faked.
- Every follow-up asks for a detail only the person who did the work would know.
- A made-up number is the easiest thing to catch: the next question is “how did you measure it?”
- A small function such as rank fusion tests whether you understand an idea well enough to write it, not just name it.
Three things you will be able to do:
- Defend a project with real numbers, and name what failed and what you would change.
- Fuse two ranked lists by hand and say what the fused order does and does not guarantee.
- Plan three mock rounds, each with its drills, interviewer behaviour and pass signal.
Provenance. The drills here are generated practice. No slide claims that any company asks them.
Concept
Mental model: a witness statement
- A witness is believed for what they can show, and for separating what they saw from what they assume.
- One claim that collapses under questioning makes the room doubt the rest.
- So label every claim about your project before you say it: measured, estimated or unknown.
- Then each follow-up is easy, because you already know which label applies.
Diagram
Label the claim first
Worked example
Drill E worked: labelling three claims
An example project, made up for practice (the numbers are illustrative, not a real system).
| Claim | Label | How to say it |
|---|---|---|
| “recall@5 was 0.84” | Measured, with limits | “On a golden set of 50 questions I wrote from the indexed documents. It is small and written by me, so it is probably optimistic.” |
| “About 1.6 cents per query” | Estimate | “Assuming 4,000 input and 250 output tokens at a hypothetical $3 and $15 per million: $0.012+$0.00375=$0.01575.” |
| “Cost at peak traffic” | Unknown | “I only estimated the average. I have not measured peak, where retries or longer prompts could raise it. I would log tokens per request over a busy week.” |
The third row is the strongest answer to a question you cannot back up: it separates what you estimated from what you never measured, and names the method.
Process
Answering “what went wrong?”
Use the same five beats every time, with a real failure:
- Symptom. What users or metrics showed.
- How you found the cause. The measurement or experiment, not a hunch.
- Root cause. The stage and the reason.
- Change. What you did, and how you know it worked.
- Still open. What you would change next, or what you did not fix.
A trivial example dodges the part worth probing: how you diagnose. Outside causes (a vendor outage) are fair, if you add what your design did about them.
Concept
Why fuse ranks, not scores?
- Two retrievers, for example keyword and vector search, do not score on a common scale, so mixing raw scores needs calibration or tuned weights.
- Their ranks can be compared. Reciprocal rank fusion (RRF) uses only the rank each list gives a document.
- An Elastic Search Labs article describes combining lexical and vector result lists with RRF, and says it needs no score calibration or normalization.
- Cormack, Clarke and Büttcher (SIGIR 2009) introduced RRF as a simple method for combining rankings from several systems.
Sources[1] Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods[2] Elasticsearch hybrid search
Math
The formula
score(d)=L∑k+rankL(d)1| Symbol | Meaning |
|---|---|
| d | One document |
| L | One input ranked list |
| rankL(d) | Position of d in list L, starting at 1 |
| k | A constant; 60 in the original paper |
- Add one term per list the document appears in, then sort by the total, best first.
- In the paper, k=60 came from a pilot investigation and was left unchanged in later validation. The pilot suggested 60 was near-optimal, though the paper adds that the exact choice was not critical.
- The reciprocal shape is what keeps lower-ranked documents from vanishing, as an exponential decay would let them. The constant k limits how much a single system can gain by placing a document very high.
- The paper defines each ranking over all documents. Code usually adds a term only for lists where the document appears, which is the version used here.
Source[1] Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods
Code
Drill D: writing it, and testing the edge cases
Python
from fractions import Fraction
def rrf(ranked_lists, k=60):
scores, best = {}, {}
for lst in ranked_lists:
seen = set()
for rank, doc in enumerate(lst, start=1):
if doc in seen: # count a document once per list
continue
seen.add(doc)
scores[doc] = scores.get(doc, 0) + Fraction(1, k + rank)
best[doc] = min(best.get(doc, rank), rank)
# ties: higher score, then better best-rank, then id
order = sorted(scores, key=lambda d: (-scores[d], best[d], d))
return [(d, float(scores[d])) for d in order]Fractionkeeps ties exact. With three or more lists, floating-point sums can differ in the last digits depending on the order of addition (for example 611+611+621 versus 611+621+611), which would split a true tie.- The
seenguard stops a document repeated inside one list from collecting extra credit. - The tie rule is explicit, so the output is the same every run.
Test results (run in Python 3):
| Test | Result |
|---|---|
| Worked example gives J, L, K, N, M | pass |
| J and L tie exactly | pass |
| One input list keeps its order | pass |
| Empty input, and a list of empty lists, return nothing | pass |
| A document repeated three times in one list scores 611 | pass |
Without the seen guard, a repeated document outranks a clean one | pass (the bug is real) |
Worked example
Worked by hand
Lists [J, K, L, M] and [L, N, J], k=60.
| Document | List 1 rank | List 2 rank | Score |
|---|---|---|---|
| J | 1 | 3 | 611+631=0.0323 |
| L | 3 | 1 | 631+611=0.0323 |
| K | 2 | not listed | 621=0.0161 |
| N | not listed | 2 | 621=0.0161 |
| M | 4 | not listed | 641=0.0156 |
- J and L tie exactly, and so do K and N. RRF does not say who goes first, so you must choose a rule.
- With the rule “better best-rank, then id” the fused order is J, L, K, N, M.
- Documents in both lists come first here, but only because both lists gave them good ranks.
Source[1] Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods
Math
What the fused order does not guarantee
A document ranked a in one list only beats a document ranked r in both lists when:
| Symbol | Meaning |
|---|---|
| a | Rank of the single-list document |
| r | Rank of the document that appears at the same position in both lists |
Check with a=3: the threshold is r=66.
| r | Both-lists score 60+r2 | Single-list score 631 | Winner |
|---|---|---|---|
| 65 | 1252=0.0160 | 0.01587 | Both lists |
| 66 | 1262=0.01587 | 0.01587 | Exact tie |
| 67 | 1272=0.01575 | 0.01587 | Single list |
So agreement helps, but it is not a rule. A strong rank in one list can beat weak agreement.
Source[1] Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods
Code
Drill D, continued: recall@k and MRR
Python
def recall_at_k(ranked, gold, k):
if not gold:
raise ValueError("gold must be non-empty")
return len(set(ranked[:k]) & set(gold)) / len(gold)
def mrr(runs): # runs: list of (ranked_list, gold_set)
if not runs:
raise ValueError("runs must be non-empty")
total = 0.0
for ranked, gold in runs:
rr = 0.0
for i, doc in enumerate(ranked, start=1):
if doc in gold:
rr = 1 / i
break
total += rr
return total / len(runs)- Reciprocal rank is 1 divided by the position of the first relevant result, and 0 if there is none. MRR averages it over queries.
- It looks only at the first relevant result, so extra relevant results are ignored.
- Tests that passed: recall@3 of
[a,b,c,d]against gold{c,z}is 0.5; MRR over three queries with first hits at rank 3, rank 1 and none is 331+1+0. - Be ready to say what each metric ignores; that is a natural follow-up.
Source[3] Mean reciprocal rank
Compare
The three-round mock plan
| Round | Format | Focus | Pass signal |
|---|---|---|---|
| 1 | 30-minute question session | Drills A and B | Correct answers with trade-offs, no hints |
| 2 | 45-minute design | One Drill C prompt you have not seen | You drive the structure, raise failure modes unprompted, recompute on a constraint change |
| 3 | 45-minute project defense plus coding | Drills D and E | Honest numbers, two follow-ups handled |
Drills A to C are in the previous lesson; D (coding), E (project defense) and F (behavioural stories) are in this one. Drill F, the behavioural stories, can be woven into any round.
Process
How the interviewer behaves
- Asks one question at a time.
- Picks follow-ups from what you actually said, not from a script.
- Does not teach during the mock. A hint would cover up the very stall you are trying to see.
- Stops at the time box.
- Afterwards, you score with the rubric from the previous lesson, then review.
A partner or the course mentor can play this role. A mock is a simulation of an interview, not a prediction of any real one.
Diagram
One cycle through the plan
Worked example
Worked: which round next?
Match the evidence to the round, not to your preference.
| Situation | Next round | Why |
|---|---|---|
| Rapid-fire answers are correct but you needed hints on two | Repeat Round 1 | The pass signal says no hints |
| Round 1 passed, but in your last design you raised failure modes only when asked | Repeat Round 2 | The pass signal needs failure modes raised unprompted |
| Design is fine, but you could not say how you measured recall | Round 3 | The defense tests whether each number has a source |
Round 3 is also the place to run the by-hand RRF check and one Drill F story under time.
Diagram
Cheat sheet: fix the earliest broken stage
Say aloud: “I would measure first, then add complexity for a named failure.”
Check yourself
Check: fuse three lists
Fuse [T, U, V], [V, X, U, W] and [T, X] with k=60. Give the order and the scores to five decimal places.
Answer
T=611+611=0.03279. V=631+611=0.03227. X=621+621=0.03226. U=621+631=0.03200. W=641=0.015625 (0.01563 to five places). Order: T, V, X, U, W. V and X differ by less than 0.00001, so keep enough digits before you decide.
Check yourself
Check: does agreement win?
Document M is ranked 4th in one list only. Document N is ranked 75th in both lists. Which is ahead, and how good must N’s rank be, in both lists, to overtake M?
Answer
M=641=0.015625. N=1352=0.01481. M is ahead. With a=4 the rule r>60+2a gives r>68, so N overtakes M only at rank 67 or better in both lists (1272=0.01575); at rank 68 they tie, since 1282=641.
Check yourself
Check: a measured number with limits
You say “recall@5 was 0.9” and the interviewer asks what the set contained. The 30 questions were taken from the same data you used to tune the chunk size and prompt. How do you label and present the claim?
Answer
It is a measured claim, but the set overlaps with what you tuned on, so it cannot show how the system behaves on new questions. Say so, then hold out a fresh set: add real user questions from logs, include questions the corpus cannot answer, and report recall on slices.
Summary
Summary
- Label every project claim before you say it: measured, estimated or unknown. Keep targets and results apart.
- A failure story has five beats: symptom, how you found the cause, root cause, change, what is still open.
- RRF adds k+rank1 per list and sorts by the total; k=60 comes from the original paper. Exact ties need an explicit rule.
- Agreement between lists helps, but a document at rank a in one list beats one at rank r in both when r>60+2a.
- The plan is three rounds: questions (A, B), an unseen design (C), then defense and coding (D, E). The interviewer asks and does not teach.
References
References & Sources
Gordon V. Cormack, Charles L. A. Clarke, Stefan Büttcher2009SIGIR 2009Paper
https://cormack.uwaterloo.ca/cormacksigir09-rrf.pdf
Used for RRF sums 1/(k + rank) over rankings; k = 60 was fixed in a pilot investigation, was near-optimal but not critical, and the constant limits the effect of high rankings from outlier systems.
Elasticsearch hybrid search (opens in a new tab)
Valentin Crettaz2025Article
https://www.elastic.co/search-labs/blog/hybrid-search-elasticsearch
Used for Elasticsearch's rrf retriever combines lexical and vector result lists by rank, and the article says RRF needs no score calibration or normalization.
Mean reciprocal rank (opens in a new tab)
Wikipedia2026Article
https://en.wikipedia.org/wiki/Mean_reciprocal_rank
Used for Reciprocal rank is 1 over the position of the first relevant result (0 if none); MRR averages it over queries and ignores later relevant results.
Keys: ← → move, Home End first and last, F full screen.