In this post
What this post covers
- 1. How do you choose top-k?
- 2. Vectors, BM25, or both?
- 3. When is a reranker worth it?
- 4. What chunk size do you use?
- 5. How do you stop the system answering when the docs don’t cover it?
- 6. How do you know a change didn’t make retrieval worse?
- 7. How do you prevent one tenant seeing another’s data?
- 8. Should you cache answers?
- Caveats
- Code
- Rule of thumb
How this was tested
Python 3.12.16, standard library only, own BM25 (k1=1.5, b=0.75) on the FastAPI English docs (154 files, 1,517 heading-aware chunks over 200 characters), 300 heading queries and 200 eight-token queries, seed 0. The top-k table is new in this post. Every other number is quoted from the linked post on this site that produced it. No LLM, embedding model or reranker was run for the new table.
What do interviewers ask about RAG system design, and what is an answer that holds up? Below are eight questions with short answers. Each answer rests on a measurement, either the new top-k experiment in this post or an earlier experiment on this site. I did not collect real interview transcripts, so the question list is my judgment of what comes up, not a survey.
If you need the basics first, start with the guide part on retrieval.
1. How do you choose top-k?
I ran BM25 over 1,517 heading-aware chunks of the FastAPI docs and measured how often the source chunk appeared in the top k. Two query styles: 300 heading queries, and 200 queries built from 8 random tokens of a chunk. The last column is the mean prompt context that k chunks add for the heading queries.
| k | recall, heading queries | recall, 8-token queries | context added (chars) |
|---|---|---|---|
| 1 | 0.707 | 0.950 | 699 |
| 3 | 0.843 | 0.985 | 2,213 |
| 5 | 0.910 | 0.995 | 3,763 |
| 10 | 0.963 | 0.995 | 8,133 |
| 20 | 0.977 | 0.995 | 16,745 |
| 50 | 0.997 | 1.000 | 44,251 |
Going from k=1 to k=5 added 0.203 recall. From 5 to 10 added 0.053, from 10 to 20 added 0.014, and from 20 to 50 added 0.020. Context grew 2.16x from 5 to 10, 4.45x from 5 to 20, and 11.8x from 5 to 50.
Answer: pick k where the recall curve flattens, and say you read it off a curve. Here that is about 5 to 10. Past that you pay for tokens and add distractors for little recall. Caveat: this is lexical retrieval on one corpus, and the queries are generated from the chunks themselves, so the absolute recall is optimistic.
2. Vectors, BM25, or both?
Both, with a weight. In the hybrid search test, BM25 beat vectors by 49 MRR points on exact identifiers (0.772 vs 0.279), vectors beat BM25 by 24 points on paraphrases (0.768 vs 0.566), and an 80% BM25 weight in rank fusion stayed within 9 points of the best on every query type.
3. When is a reranker worth it?
When queries are descriptive, not exact. In the reranker test, a cross-encoder over the top 20 candidates raised heading-query MRR from 0.710 to 0.889, did nothing on identifiers (0.679 to 0.677), and cost a median 1,706 ms per query on one CPU thread.
4. What chunk size do you use?
Say that the cut matters more than the size. In the chunk size sweep, fixed-size chunks fell from 0.58 to 0.16 hit@1 as size grew from 200 to 2,000 characters, while heading-aware chunks fell only from 0.88 to 0.76.
5. How do you stop the system answering when the docs don’t cover it?
A score threshold. In the refusal test, a cosine threshold of 0.40 refused 24 of 30 unanswerable questions and answered 29 of 30 answerable ones. Near-domain questions are the leftovers.
6. How do you know a change didn’t make retrieval worse?
A golden set in CI, gated on more than one metric. In the golden-set harness, 30 questions caught 3 of 4 injected regressions, and a hit@1-only gate would have missed one that cut hit@5 from 0.933 to 0.800.
7. How do you prevent one tenant seeing another’s data?
Filter at retrieval, not in the prompt. In the multi-tenant test, no filter and prompt-only rules both leaked on 1,800 of 1,800 queries; per-tenant partitions leaked on none.
8. Should you cache answers?
Exact-match first. In the caching simulation, exact-match hit 78.9% with no wrong answers, while a 0.95 semantic threshold hit 86.2% and served the wrong answer on 2.46% of queries (corrected 2 Dec 2026; the first run said 15.96% because release-note version headings were counted as intents).
Caveats
- The top-k table is BM25 only, on one documentation corpus. Dense retrieval or longer chunks will shift the curve.
- Heading queries are easier than real user questions because they reuse the chunk’s own words.
- Answers 2 to 8 are quoted from earlier posts; each has its own caveats on its page.
- “Recall” here means the exact source chunk appeared, so a different chunk that also answers the question counts as a miss.
Code
The script is in the Experiment files box. The core is a 20-line BM25 over an inverted index, then recall is counted at each k.
Rule of thumb
In an interview, give the number, the condition it holds under, and what would change it. “Top-5 to 10, because recall flattens there on my corpus, and I would re-measure on yours” beats a bare “use 5”.
Experiment files
Get the free RAG production checklist
25 checks to run before real users see your RAG feature: exact-match misses, invented citations, prompt injection through documents, quality that slips after a prompt change. Confirm your email and the PDF comes with the welcome email, plus each new experiment.