Retrieval (RAG)

Retrieval-augmented generation gives a model an open book: chunk documents, embed them, retrieve whatever's most relevant to the question, and hand it to the model as ground truth. The model trusts a retrieved chunk exactly as much as its own system prompt — which is to say, completely.

Learn

Chunk → embed → retrieve → answer

A document gets sliced into chunks before it's embedded, because a whole manual is too big to search well and too big to fit in context. Where you slice matters: cut through the middle of the one sentence that answers the question, and no chunk contains the whole answer anymore.

Build

Chunk it without cutting the answer in half

Mission A · chunk size

This policy document is being split into fixed-size chunks. Question: "How many days to return an opened item?" The answer lives in one sentence. Pick a chunk size so that sentence lands whole inside a single chunk.

drag the slider…
Break

Peel the document

You just learned that where text gets cut changes what a retriever can see. Now look at a document where something was deliberately hidden from you but not from the parser that will feed it straight to the model.

Mission B · the document nobody read fully

This support PDF was just added to the knowledge base. Drag the slider to peel back what a human skimming it would never see — but a PDF-to-text parser reads every layer.

peel the document to find what's hidden…

What just happened: the hidden instruction was invisible to the person who approved the document for the knowledge base, and completely visible to the parser that fed it to the model. Nobody poisoned the model — they poisoned what it reads.

Defend

Why this works, and the fix

Why it works: a retrieved chunk is just more tokens in the context window (see the previous level) — there is no "this came from an untrusted document" marker once it's in the sequence. Anyone who can get a document into the knowledge base — a support ticket, a shared drive, a public wiki page — gets a vote in what the model says next, often via text invisible to a human reviewer (white-on-white text, 0.5pt font, off-page placement, or hidden PDF layers and metadata).

The fix: render documents the way a human would see them before ingesting (strip invisible/off-canvas text), scan retrieved chunks for instruction-like language before they reach the model, and never let retrieved content issue instructions — treat it as a quotation to read, not a command to follow.