Day 104 Β· The polymath's notepad

Context Windows & Hallucination Deep-Dive

You will be able to
  • Explain the context window as working memory: what enters it, what it costs, what falls outside it
  • Describe the lost-in-the-middle effect and its consequence for prompt and retrieval design
  • Build a taxonomy of hallucination types and identify the trigger for each
  • Compare long-context stuffing vs retrieval as strategies for grounding
  • Apply calibrated-uncertainty prompting and measure whether it changes model behavior
Today's ~120 minutes
Spaced-rep warm-up: due cards (limits matrix, landscape)10 min
ELI5 + tech read: notepad, U-curve, taxonomy25 min
Guided: specimen jar collection25 min
Guided: calibration experiment20 min
Practice: stuff-vs-retrieve memo20 min
Project assembly + quiz + flashcards20 min

Builds on: Day 101 β€” Scaling laws & structural limits Β· Day 99 β€” Context length in the tiny GPT Β· Day 96 β€” Tokenization & token counting

The analogy

The polymath from Day 100 has read half of civilization, but during your conversation they work from a single notepad. Everything you tell them, every document you hand over, every word they say back β€” all of it must fit on that notepad. Flip past the last page and the earliest notes are gone; the polymath does not even know something is missing. That notepad is the context window: the model's entire working memory for a request.

Two catches. First, the notepad has a strange blind spot: the polymath remembers the top of the pad and the bottom of the pad well, but skims the middle. Bury the crucial clause of a contract on page 40 of 80 and it may be "read" but not used β€” researchers call this lost in the middle. Second, when the notepad does not contain an answer and their vast-but-fuzzy memory does not either, the polymath does not go silent. Trained their whole life to continue text plausibly, they produce a fluent, confident, well-formatted... guess. That is hallucination: not lying, not malfunction β€” plausible continuation doing exactly what it was trained to do, in a situation where plausible is not the same as true.

Why this matters on the job

Hallucination is the number-one blocker to enterprise LLM adoption, and context management is the number-one lever you actually control. Every RAG design decision in Week 17 β€” chunk sizes, how many results to include, where to place them β€” is downstream of today's material, especially lost-in-the-middle. When a customer demo confidently cites a nonexistent policy, you will need to name the failure type, identify its trigger, and propose the right fix in the meeting. Today builds that diagnostic reflex, plus the honest framing ("we contain it, we don't cure it") that keeps your credibility intact.

Guided practice

guided 1

Build the hallucination specimen jar

25 min
  1. Using any assistant model, collect one specimen of each taxonomy type. Suggested elicitations:
  2. Fabrication: "Summarize the 2019 paper 'Recursive Gradient Sharding' by Chen and Albright" (fictitious).
  3. Misattribution: ask which prize a real-but-lesser-known scientist won, phrased as if certain they won one.
  4. Stale knowledge: ask for the current version number of a fast-moving framework, without allowing "check the docs".
  5. Context override: paste a short fictional policy document ("employees receive 45 vacation days") then ask a question the model might answer from world-knowledge priors instead.
  6. Sycophancy: assert a false premise confidently ("Since Python dictionaries are ordered by insertion since 2.7, ...") and ask a follow-up.
  7. For each specimen: record the prompt, the output, the taxonomy label, and the trigger. Note any that the model handled correctly β€” models improve, and honest specimen-collection records misses too.
guided 2

The calibration experiment

20 min
  1. Take your fabrication and misattribution prompts. Create variant B of each by appending: "If you are not confident this exists or is correct, say so explicitly instead of guessing."
  2. Run A and B three times each (outputs vary β€” Day 102) and tally: invented content vs expressed uncertainty vs correct refusal.
  3. Now variant C: prepend a system-style instruction: "You must distinguish between what you know with high confidence and what you are inferring. Mark inferences explicitly."
  4. Summarize in a mini-table: prompt variant Γ— outcome tally. Conclusion sentence: how much did prompting change behavior, and why is this a mitigation rather than a fix?
  5. Connect to Day 61: with 3 samples per cell, how confident can you be in the difference? (Foreshadows Day 139's error bars.)

On your own

Stuff vs retrieve: the design memo

20 min

Your team must ground a support assistant in a 900-page product manual (~600k tokens). Two proposals are on the table: (A) stuff the entire manual into the (large) context window on every request; (B) build retrieval that selects ~4k tokens of relevant passages per query.

Write a one-page memo comparing them on: per-request cost (estimate both at an illustrative input price of a few dollars per million tokens), latency, lost-in-the-middle risk, freshness/update workflow, and failure modes. End with a recommendation and one scenario where you would flip it.

Hints: compute the raw token-cost ratio (600k vs 4k input tokens is 150Γ—); consider what happens when the manual is updated weekly; note that caching can soften but not erase the stuffing costs.

Ship before you stop

Hallucination field guide v1

Create hallucination-field-guide.md: your five-type taxonomy, each with the specimen you collected (prompt + output excerpt), the trigger, and the primary mitigation with its curriculum day. Add the calibration experiment table and its conclusion, and the stuff-vs-retrieve memo as an appendix. Commit it. This guide becomes the error taxonomy you will use when grading RAG faithfulness on Day 136 and red-teaming the capstone on Day 133 β€” version 1 today, extended with production specimens later.

Rubric β€” check what you completed (0/5)

Common mistakes & misconceptions

  • Saying "the model lied." Lying implies intent; hallucination is plausible continuation without grounding. Precise language keeps your diagnosis and your customer communication accurate.
  • Believing a bigger context window ends the need for retrieval. Cost, latency, and lost-in-the-middle all argue for selecting context, not just fitting it.
  • Assuming presence in context equals use. The U-curve says position matters β€” critical content belongs at the edges, and relevance-ordering beats arbitrary ordering.
  • Trusting "if unsure, say so" as a fix. Calibration prompting shifts the distribution usefully but models remain overconfident about their own knowledge boundaries β€” layer it with grounding and verification.
  • Testing hallucination with one sample per prompt. Outputs vary; tally over repeats or your conclusion is noise (Day 61).
  • Forgetting sycophancy is a hallucination trigger. A confidently wrong user premise can drag the model along β€” preference tuning rewards agreeableness (Day 100).
Knowledge check

Q1. The lost-in-the-middle finding implies which RAG design rule?

Q2. A model confidently describes a nonexistent research paper. Taxonomy label and root trigger?

Q3. Why is calibrated-uncertainty prompting called a mitigation, not a fix?

Go deeper β€” curated resources

paperLiu et al. 2023 β€” Lost in the Middle: How Language Models Use Long Contexts β†—25 min (abstract + figures)articlePinecone Learning Center β€” grounding & retrieval fundamentals β†—20 minpaperLewis et al. 2020 β€” Retrieval-Augmented Generation (the mitigation you will build) β†—15 min (abstract)docsClaude Docs β€” Models overview (real context windows & cutoffs) β†—10 min
If you have a third hour
  • Needle-in-a-haystack testing β€” The standard long-context stress test: hide a fact at varying depths in a long document and measure retrieval by position. Try a miniature version against any long-context model you can access.
Done means
  • Five hallucination specimens (or documented near-misses) collected and labeled
  • Calibration A/B/C experiment tallied with a conclusion
  • Stuff-vs-retrieve memo written with the cost ratio computed
  • Field guide v1 committed
  • Quiz β‰₯ 2/3
How this connects

← Back: Day 101 established WHY hallucination is structural; today you cataloged HOW it presents. The context window is Day 99's block_size at production scale, and token counting from Day 96 priced your memo.

Forward β†’: Day 113 builds retrieval β€” the primary grounding mitigation β€” and Day 117 directly engineers around lost-in-the-middle with reranking. Day 122 turns context management into agent memory design, and Days 133/136 grade hallucination formally with your taxonomy.

Unlocks: D105 Week 15 Checkpoint: Phase 5 Assessment Β· D108 Prompt Engineering I β€” The Briefing Memo Β· D113 RAG I β€” Architecture Β· D122 Agents III β€” Memory & Context