Slides · GenAI system design

Coding, project defense and mock rounds

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:

  1. Defend a project with real numbers, and name what failed and what you would change.
  2. Fuse two ranked lists by hand and say what the fused order does and does not guarantee.
  3. 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

Diagram: Start from a claim and ask whether you measured it.

yes

no

yes

no

A claim

Measured?

Measured:
number, method, data

Can you estimate?

Estimate:
show arithmetic

Unknown:
plan to measure

Diagram summary: Start from a claim and ask whether you measured it. If yes, state the number with its method and data. If no, estimate it from known numbers and show the arithmetic, or say it is unknown and name the measurement you would add.

Worked example

Drill E worked: labelling three claims

An example project, made up for practice (the numbers are illustrative, not a real system).

ClaimLabelHow 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\$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:

  1. Symptom. What users or metrics showed.
  2. How you found the cause. The measurement or experiment, not a hunch.
  3. Root cause. The stage and the reason.
  4. Change. What you did, and how you know it worked.
  5. 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.

Sources1 Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods2 Elasticsearch hybrid search

Math

The formula

score(d)=∑L1k+rankL(d)\mathrm{score}(d) = \sum_{L} \frac{1}{k + \mathrm{rank}_L(d)}
SymbolMeaning
ddOne document
LLOne input ranked list
rankL(d)\mathrm{rank}_L(d)Position of dd in list LL, starting at 1
kkA 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=60k = 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 kk 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.

Source1 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]
  • Fraction keeps ties exact. With three or more lists, floating-point sums can differ in the last digits depending on the order of addition (for example 161+161+162\tfrac{1}{61} + \tfrac{1}{61} + \tfrac{1}{62} versus 161+162+161\tfrac{1}{61} + \tfrac{1}{62} + \tfrac{1}{61}), which would split a true tie.
  • The seen guard 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):

TestResult
Worked example gives J, L, K, N, Mpass
J and L tie exactlypass
One input list keeps its orderpass
Empty input, and a list of empty lists, return nothingpass
A document repeated three times in one list scores 161\tfrac{1}{61}pass
Without the seen guard, a repeated document outranks a clean onepass (the bug is real)

Worked example

Worked by hand

Lists [J, K, L, M] and [L, N, J], k=60k = 60.

DocumentList 1 rankList 2 rankScore
J13161+163=0.0323\dfrac{1}{61} + \dfrac{1}{63} = 0.0323
L31163+161=0.0323\dfrac{1}{63} + \dfrac{1}{61} = 0.0323
K2not listed162=0.0161\dfrac{1}{62} = 0.0161
Nnot listed2162=0.0161\dfrac{1}{62} = 0.0161
M4not listed164=0.0156\dfrac{1}{64} = 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.

Source1 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:

160+a>260+rwhich simplifies tor>60+2a\frac{1}{60 + a} > \frac{2}{60 + r} \qquad \text{which simplifies to} \qquad r > 60 + 2a
SymbolMeaning
aaRank of the single-list document
rrRank of the document that appears at the same position in both lists

Check with a=3a = 3: the threshold is r=66r = 66.

rrBoth-lists score 260+r\dfrac{2}{60 + r}Single-list score 163\dfrac{1}{63}Winner
652125=0.0160\dfrac{2}{125} = 0.01600.01587Both lists
662126=0.01587\dfrac{2}{126} = 0.015870.01587Exact tie
672127=0.01575\dfrac{2}{127} = 0.015750.01587Single list

So agreement helps, but it is not a rule. A strong rank in one list can beat weak agreement.

Source1 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 13+1+03\dfrac{\frac{1}{3} + 1 + 0}{3}.
  • Be ready to say what each metric ignores; that is a natural follow-up.

Source3 Mean reciprocal rank

Compare

The three-round mock plan

RoundFormatFocusPass signal
130-minute question sessionDrills A and BCorrect answers with trade-offs, no hints
245-minute designOne Drill C prompt you have not seenYou drive the structure, raise failure modes unprompted, recompute on a constraint change
345-minute project defense plus codingDrills D and EHonest 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

  1. Asks one question at a time.
  2. Picks follow-ups from what you actually said, not from a script.
  3. Does not teach during the mock. A hint would cover up the very stall you are trying to see.
  4. Stops at the time box.
  5. 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

Diagram: The plan moves down from short questions to an unseen design to a project defense with coding.

Round 1
Questions

Score, review

Round 2
Unseen design

Score, review

Round 3
Defense + coding

Score, review

Diagram summary: The plan moves down from short questions to an unseen design to a project defense with coding. Each round is followed by a scoring and review step against the rubric before the next round starts, and after Round 3 as well.

Worked example

Worked: which round next?

Match the evidence to the round, not to your preference.

SituationNext roundWhy
Rapid-fire answers are correct but you needed hints on twoRepeat Round 1The pass signal says no hints
Round 1 passed, but in your last design you raised failure modes only when askedRepeat Round 2The pass signal needs failure modes raised unprompted
Design is fine, but you could not say how you measured recallRound 3The 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

Diagram: When answers are bad, work down the pipeline in order and fix the earliest broken stage first: ingestion, retrieval recall, ranking...

Bad answer

1 Ingestion

2 Retrieval recall

3 Ranking precision

4 Context assembly

5 Generation

Diagram summary: When answers are bad, work down the pipeline in order and fix the earliest broken stage first: ingestion, retrieval recall, ranking precision, context assembly, then generation. A later stage cannot repair an earlier failure.

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=60k = 60. Give the order and the scores to five decimal places.

Answer

T=161+161=0.03279T = \dfrac{1}{61} + \dfrac{1}{61} = 0.03279. V=163+161=0.03227V = \dfrac{1}{63} + \dfrac{1}{61} = 0.03227. X=162+162=0.03226X = \dfrac{1}{62} + \dfrac{1}{62} = 0.03226. U=162+163=0.03200U = \dfrac{1}{62} + \dfrac{1}{63} = 0.03200. W=164=0.015625W = \dfrac{1}{64} = 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=164=0.015625M = \dfrac{1}{64} = 0.015625. N=2135=0.01481N = \dfrac{2}{135} = 0.01481. M is ahead. With a=4a = 4 the rule r>60+2ar > 60 + 2a gives r>68r > 68, so N overtakes M only at rank 67 or better in both lists (2127=0.01575\dfrac{2}{127} = 0.01575); at rank 68 they tie, since 2128=164\dfrac{2}{128} = \dfrac{1}{64}.

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 1k+rank\dfrac{1}{k + \mathrm{rank}} per list and sorts by the total; k=60k = 60 comes from the original paper. Exact ties need an explicit rule.
  • Agreement between lists helps, but a document at rank aa in one list beats one at rank rr in both when r>60+2ar > 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

  1. Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods (opens in a new tab)

    Gordon V. Cormack, Charles L. A. Clarke, Stefan Büttcher2009SIGIR 2009Paper

    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.

  2. Mean reciprocal rank (opens in a new tab)

    Wikipedia2026Article

    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.