An Interactive Field Guide

How RAG actually finds the answer

Retrieval-augmented generation, explained the way a pop-up book would do it — every idea on this page is a thing you can pull, drag, and break.

Nawa · Full-stack AI engineer ≈ 9 min 5 interactive exhibits

Every language model has a peculiar kind of amnesia. It has read half the internet, yet it has never seen your refund policy, your product docs, or the email your support team sent last Tuesday. Ask it about those and it does the one thing it's trained to do: produce a plausible-sounding answer anyway.

Retrieval-augmented generation — RAG — is the standard cure. Before the model answers, a search system fetches the few paragraphs of your data that matter, and staples them into the prompt. The model stops guessing and starts reading.

To make this concrete, this whole essay runs on a toy knowledge base: the internal docs of an imaginary company, Peak Bean Coffee Co. — four documents, twenty-five paragraphs. Let's watch what happens without RAG first.

Exhibit A · One question, two machines

A customer asks something only Peak Bean's policy can answer. Press both buttons.

Customer“Can I return my espresso machine after 40 days?”

Bare model · no retrieval
Same model + RAG
Observe The bare model invented a 60-day policy that doesn't exist — fluent, confident, wrong. The RAG answer is duller and hedged, but every claim points at a real paragraph. That's the whole trade: charisma for citations. The rest of this essay is about how those citations get found.

§1First, the library gets sliced

Search engines don't retrieve whole documents — a 30-page PDF would drown the model. So every document is cut into chunks: bite-sized passages that live or die on their own. Chunk size is the first knob every RAG engineer turns, and it's a genuine trade-off, not a formality.

Exhibit B · The slicer
Before you drag — if chunks get tiny, what breaks?

Below is Peak Bean's refund policy. Drag the slider to re-slice it. Watch the highlighted fact.

chunks · avg chars

Observe At tiny sizes the key sentence — “a full refund within 30 days of delivery” — gets split across two chunks, and no single search hit contains the whole rule. At huge sizes one chunk carries three unrelated policies, so its meaning blurs. Production systems usually land between 200–800 tokens with overlap, precisely to dodge both failure modes.
Toy note: real chunkers split on tokens, sentences, or document structure — not raw characters. The trade-off is identical.

§2Meaning becomes geometry

Here's the beautiful part. Each chunk is fed through an embedding model, which converts its meaning into a list of numbers — a coordinate. Chunks about similar things land near each other, regardless of the words they use. Your question gets converted into the same space, and “search” collapses into something almost childish: find the nearest dots.

Below is Peak Bean's entire knowledge base as a map. It's a toy 2-D version of a real embedding space, but the behavior is honest.

Exhibit C · The meaning map
The phrase “money back” appears in zero Peak Bean documents. If you ask “where's my money back?”, what does the search find?

Pick a question (or type your own), then drag the ✦ star around the map and watch retrieval react.

Observe “Where's my money back?” lands squarely in the refund cluster — no shared keywords required. That's the entire reason embeddings beat keyword search: they match what you mean, not what you typed. Now try dragging the star into empty space between clusters and watch the retrieval get confused — ambiguity is geometric, too.
view this map as a table
#chunkdocumentsimilarity
Toy note: this map is a hand-made 2-D space with a ~70-word vocabulary. Production embeddings live in ~1,536 dimensions and compare by cosine similarity — but “nearest dots win” is exactly how it works.

§3Choosing how much to grab

Nearest-first gives us a ranking. But how many chunks do we actually hand to the model? That number is called k, and it's the second knob. Too few and the answer is missing its evidence. Too many and the good passage drowns in noise — while every extra chunk burns context-window budget.

Exhibit D · The claw machine
Crank k to the max — does the final answer get better?

This ranking is live-linked to Exhibit C — whatever you asked up there is ranked down here. Step k up and down.

3
chunks retrieved — top-k of 25

Pick a question in Exhibit C first — this ranking needs a query. ☝︎

context window
0 / 170 tokens
Observe Around k = 3 the tray holds exactly the evidence the question needs. By k = 8 you're paying for brewing tips in a billing question — the budget meter runs hot and the model has to ignore most of what you fetched. Retrieval quality isn't “more”; it's precision at the top of the list.

§4The staple gun

The last step is almost anticlimactic. The retrieved chunks are pasted into the prompt above the user's question, with one instruction: answer from these passages only. The model doesn't “learn” your data — it just reads what retrieval put in front of it, that one time. Flip it off and watch what the model falls back on.

Exhibit E · Grounded vs. vibes

The prompt below is assembled live from your Exhibit C question and Exhibit D's k. Flip the switch.

system: answer ONLY from the passages below. cite them.
⟨ no passages retrieved yet — visit Exhibit C ⟩
user: —
Model output✓ grounded
Waiting for a question…
The point Same model, same question. The only difference is what was on its desk when it answered. RAG isn't magic — it's a librarian with excellent aim, working for a very well-read amnesiac.

§5Where it quietly breaks

Everything above also explains the classic RAG failures — you've already caused all three of them on this page:

🪞

The convincing distractor

“Delayed parcels qualify for a shipping-fee refund” sits between two clusters — it's about refunds and shipping. Ask a money question and it sneaks into the top-k, half-relevant, wholly misleading.

→ you saw it drift in Exhibit C
✂️

The severed fact

When chunking split “full refund within 30 days,” no retrievable passage contained the rule. The model can only read what survives the slicer.

→ you did this in Exhibit B
🧭

The out-of-vocabulary query

Ask about something the embedding model barely understands and your query lands in no-man's-land — retrieval returns the nearest wrong things with full confidence.

→ type gibberish in Exhibit C

§6What to keep

  1. RAG = slice → embed → nearest-k → staple into the prompt. Four steps, two knobs.
  2. Embeddings match meaning, not keywords — that's the superpower and the failure mode.
  3. Chunk size and k are trade-offs you tune with evals, not constants you copy from a tutorial.
  4. A grounded answer is only as good as what retrieval put on the desk — measure retrieval first when RAG misbehaves.

If you can drag a star around a map, you now understand the architecture behind most production AI assistants. The rest is engineering: real embedding models, vector indexes, rerankers, and evals — the parts I build for a living.

N

Nawa — full-stack AI engineer. I build RAG pipelines, agents, and AI products for clients. This essay is also a prototype: I'm exploring blogs you can operate instead of merely read. If this format taught you something a wall of text wouldn't have — tell me.

Colophon — Every simulation on this page is a deliberately simplified toy: a hand-drawn 2-D “embedding space”, character-based chunking, scripted model answers. Real systems embed in ~1,536 dimensions, compare by cosine similarity, and search with approximate-nearest-neighbor indexes. The simplifications were chosen to keep the behavior honest while making it graspable. Built with agent assistance; every interaction hand-verified.