Learning / Agentic Operations / Lesson 0009
RAG Build & Break
Retrieval quality caps answer quality — so this lesson makes you watch it cap.
1 · The pipeline, minimally
RAG is: chunk a corpus → retrieve the relevant chunks for a question → inject them into context → answer from them (Lesson 0002). Build the smallest honest version — no vector DB required for the lesson; keyword/overlap scoring makes the failure modes just as visible and keeps the mechanism in view.
- Corpus: one longish document with distinct facts in different sections — a fake product FAQ or policy doc, ~2–3k words, where answers depend on specific passages.
- Chunk: split into passages; start with a sane strategy (by paragraph, or ~200 words with ~40-word overlap).
- Retrieve: score chunks against the question (keyword overlap is fine), take the top k (start k=3).
- Answer: inject the top-k chunks into the prompt with the instruction "Answer only from the passages below; if they don't contain the answer, say so." Cite which chunk each claim came from.
2 · Break the chunking — the lab
Now degrade chunking on purpose and re-run the same five questions. Each degradation is a real production mistake:
| Chunking | Correct (n/5) | Failure you saw |
|---|---|---|
| Sane (baseline) | ||
| Too small (~20 words, no overlap) | ||
| Too large (whole doc = 1 chunk) | ||
| Zero overlap on sentence boundaries | ||
| Split mid-fact (fixed 100-char, ignore words) |
Predicted failures to watch for: too small severs a fact from its context ("the limit is 50" — 50 what?); too large reintroduces context rot (Lab A, Lesson 0006) and buries the answer; zero overlap drops facts that straddle a boundary; mid-fact splits retrieve half a number.
3 · One knob that isn't chunking
Hold chunking sane and vary k (how many chunks you inject): try k=1, 3, 8, 20. Note the tradeoff — too few misses the answer (recall), too many reintroduces distraction and cost (Lab A again). There's a sweet spot, and it's task-specific.
Self-grade
- Pipeline works — chunk → retrieve → grounded answer with citations, and an honest "not covered"
- Grounding collapse shown — ≥2 chunking degradations lowered accuracy, each with a named mechanism
- k tradeoff found — a middle k beats both extremes, explained
- Debug reflex stated — you said retrieval, not the model, is the first suspect for a grounded agent's wrong answers
Next
Lesson 0010 — episodic memory: the agent recalls a past run and changes its plan; then the M2 readiness check.