AI Interviews · Question

Explain how you pick chunk size and when you use structure-aware chunking, how you choose k, and when retrieval is the wrong tool for the problem.

Domain deep dive question reported at Applied-AI loops (no single company) (2026). Sources, confidence and an answer card.

Researched · updated

eng-007 AI Engineer RAG & retrieval quality Domain deep dive Low confidence
On this page

What they’re really asking

If you only remember one thing, say this in the first minute: “Chunk size follows the questions and the document’s structure: about a paragraph for fact lookups, a whole section for procedures, tables kept whole, and never longer than the embedding model can read. I split on headings and put the heading path on every chunk. For k, the number of chunks I send, I start from a token budget, cap it in code, then plot recall and answer quality against k on a labelled set. And I skip retrieval when the documents fit in the prompt, when the question is about all documents at once, or when it needs live data.”

The rest of this page explains each part of that answer.

This is three knobs and one judgment call. The interviewer wants a value for each knob, a reason tied to the documents and the questions, and a way to measure it.

Some background first. In a retrieval system for a large language model (LLM, such as Claude or GPT), you cut documents into passages called chunks, search them, and hand the best few to the model, which writes the answer. The model reads text in tokens (pieces of words, about ¾ of a word each), and you pay for every token you send. That makes these knobs different from search knobs you may have tuned before:

  1. Chunk size changes what the search can find. A chunk that is too big blurs its meaning; one that is too small loses its context.
  2. k changes both cost and correctness. More chunks cost more and, past a point, distract the model.
  3. Sometimes search is the wrong tool entirely, and saying so is the strongest answer.

The source is a 2026 applied-AI prep guide whose example questions are its own, not candidate reports. It calls “Fixed 512-token windows” “the lazy default and they cut sentences in half”, says “Bigger k buys recall and burns context budget and latency”, and calls knowing when retrieval is the wrong tool “The strongest signal in this round”. It does not list rejection criteria (techinterview.orgsecondary).

Clarify first

  • What questions dominate? Single facts, procedures, comparisons, or counts across all documents?
  • What structure do the documents have? Headings, tables, code, or short records like tickets?
  • Which embedding model, and what is its input limit?
  • What context budget and latency target per question?

Answer

Words you need first

  • Embedding: a list of numbers a small model computes from text, so that passages with similar meaning get similar numbers. Search by embeddings finds paraphrases. Each embedding model reads only a fixed number of tokens and silently drops the rest.
  • k: how many chunks you put in the prompt.
  • recall@k: the share of test questions where the chunk holding the answer is among the top k. It answers “did the model get to see the evidence?”
  • Labelled set (or eval set): 50–200 questions with the correct answer and where it lives, written by someone who knows the documents.

Chunk size: follow the questions and the structure

  • Fact lookups want paragraph-sized chunks, roughly 200–400 tokens, so one relevant sentence isn’t diluted. An embedding describes the whole chunk; one useful sentence inside 1,500 tokens of other text scores lower than it should.
  • Procedures and explanations want the whole section, so a step list isn’t cut in half.
  • Short records (tickets, FAQ entries) want one record per chunk.
  • Tables stay whole, with the headers repeated if you must split rows.
  • Never exceed the embedder’s window. The small open model all-MiniLM-L6-v2 embeds at most 256 word pieces (its own tokens). So the rag lab’s 512-token chunks are mostly cut short before embedding, with no error.

Structure-aware chunking means splitting on the document’s own headings, keeping tables intact, and putting the title and heading path at the top of each chunk so it stands alone. Use it whenever the documents have structure. Fixed windows are a baseline to beat, not a design.

Measure it. Sweep two or three chunking strategies on the labelled set and compare recall@k. Compare them on the same questions, looking at per-question differences, not two separate averages; this is a paired test, and it spots smaller differences.

Follow one question through it

Take an employee handbook (an invented example) and the question “What is the notice period for contractors?” The answer is one sentence in a section titled “Contractors > Ending a contract”.

ChunkingWhat the search seesWhat to say in the interview
Fixed 512-token windowsThe sentence sits in a window that starts mid-way through “Employees > Benefits” and has no heading. The embedder reads only the first 256 word pieces, and the sentence is past them.”The chunk is about benefits, as far as the embedder knows. Search can’t find it by meaning.”
Split on headings, ~300 tokensOne chunk: “Employee Handbook > Contractors > Ending a contract”, then the section text.”The heading path carries ‘contractors’ and ‘ending’, so both keyword and meaning search find it.”

Then k. The retrieved-text budget is 4,000 tokens and chunks are about 400 tokens, so start at k = 10. The contractor chunk ranks 3rd, so recall@10 is fine. If the eval showed it at 14th, raising k to 15 would add five mostly irrelevant chunks to every question. The better fix is a reranker (a slower model that rereads the top 20–50 together with the question and reorders them).

Choosing k: start from a budget, then let the data move it

k = the smaller of a hard cap and (budget ÷ tokens per chunk). Then:

  1. Plot recall@k for k = 1 to 20 on the labelled set. Where the curve flattens is the most a bigger k can buy.
  2. Plot answer correctness against k on a sample. Recall rising while correctness falls means distractors: cut k or rerank.
  3. Keep the hard cap in code. The rag lab’s server caps top_k at 20.

Remember the noise. At recall 0.8 on 200 questions, the 95% confidence interval is about ±5.5 points, so small differences between k values are noise. Say it like this: “With 200 questions each recall number wobbles by about five points, so I’d treat a smaller gap as noise unless a paired test on the same questions clears it.”

The arithmetic behind the numbers (for a Staff-level follow-up)
  • k = min(k_max, floor(budget ÷ chunk_tokens)): budget 4,000, chunks of 400 → k = 10, under the cap of 20.
  • 95% half-width for a proportion: 1.96 × √(p × (1 − p) ÷ n) = 1.96 × √(0.8 × 0.2 ÷ 200) = 1.96 × √(0.16 ÷ 200) ≈ ±5.5 points.

When retrieval is the wrong tool

  • The documents fit in the prompt: one document under about 200,000 tokens, sent whole with prompt caching (the provider keeps the processed start of your prompt for a few minutes, so repeats are cheap).
  • Aggregate questions over all documents (“how many contracts expire this quarter?”): extract fields into a table at ingestion and use SQL. Search returns k passages, not all of them.
  • Live data (order status, today’s on-call): call the system of record as a tool.
  • Summarise everything: map-reduce (summarise each section, then combine).
  • Style or behaviour problems, not missing facts: search won’t fix them; that’s prompting or fine-tuning.

Senior vs Staff

Chunks, k and when to skip retrieval

Senior

  • Gives values with reasons per question type, respects the embedder limit, and caps k.

Staff

  • Turns each knob into an experiment with a stated sample size, and routes question types to retrieval, SQL, tools or long context.

Small-team version

You make these calls alone, so make them cheap to revisit. Keep chunking parameters in config. Store the chunker version on each chunk. Keep a 100-question labelled set and a script that prints recall@k for k = 1–20.

What a sweep costs. An afternoon and little money. Three chunkers over the walkthrough’s assumed 600,000-chunk corpus re-embed about 3 × 240M tokens, about $14 at $0.02 per 1M (text-embedding-3-small, fetched 2026-10-11).

Buy, don’t host. Use a hosted embedding API for this. Host the embedder yourself only if the data can’t leave your network.

Skip it entirely for a single handbook or contract: use long context with caching.

Pitfalls

  • One chunk size for every document type. Facts, procedures and tables want different sizes.
  • Chunks longer than the embedder reads. The tail is dropped without an error, so search can’t find it.
  • Raising k to fix a bad ranking. It adds distractors to every question; rerank instead.
  • Answering an aggregate question with top-k retrieval. Search returns a sample, so counts and totals come out wrong.

Go deeper

Family

Design a RAG system end to end and justify every knob

Answer questions over private documents, with sources: when to skip retrieval, how to parse and chunk, hybrid search, reranking, choosing how many passages to send, citations and refusals, and how to measure each choice.

Other questions in this family