Book Deep Read · Generative AI System Design Interview · Ch 6

Retrieval-Augmented Generation: you think you are topping up the model's knowledge — you are giving it a checkable evidence trail

Generative AI System Design Interview · Ch 6 · Ali Aminian, Hao Sheng & Alex Xu · 2024

中文 →

What is this chapter about?

You ask your company's AI assistant how much you can expense for a hotel, and it answers fast and fluently — but that rule changed last month. How could it possibly know? This chapter is about the machinery that makes a machine look things up first and only then speak.

A strange thing first

Someone who doesn't know the answer usually says so. This kind of machine doesn't. It answers anyway, and the made-up answer sounds exactly as smooth as a true one. Worse, you can't ask where it got that. It can't tell you either — everything it knows is smeared across trillions of words it once read, and it cannot point at any particular sentence.

Why the old ways don't work

Two obvious routes both fail. One is to teach it all over again: fold the new documents into its textbooks and have it reread them. That's reprinting a whole dictionary to change one phone number — expensive, slow, and the documents change again next week. The other is to spread everything on the desk: haul in the entire filing room. The desk is only so big; and even when it just about fits, finding one sentence in a roomful of paper is hard, and whatever sits in the middle of the pile is the most likely to be skipped.

How it actually works

The trick that works is to hire a librarian, and split the job in two.

Step one happens on quiet days: build the card catalogue. Cut every document into cards ahead of time, then file them by meaning — cards about the same thing sit together even when the wording is completely different ("accommodation policy" and "hotel spending cap" land in the same drawer). None of this happens while anyone is waiting.

Step two happens the moment you ask: the librarian grabs the hundred most similar cards, skims them down to the five that really bear on your question, and hands those five to the person who answers, along with your question. That person has nothing but the five cards, and exactly one rule: answer only from what is written on them, and mark which card each sentence came from. When no card fits, the correct answer is "it's not in the files."

What you gain, and what it costs

Three benefits arrive immediately: a document edited today takes effect today, with no retraining; every answer can be traced back to the original text and checked; and files this person isn't allowed to see get blocked at the card-grabbing step. The cost is a single sentence, but a hard one: the whole thing is capped by that card-grabbing step — pick the wrong cards and the more fluent the answer, the worse it is, because it is wrong in a way that reads like truth.

Remember this one line

What it produces is not just an answer, but an answer plus where it came from. You think this is about topping up what the machine knows; really it converts "speaking from memory" into "reading off the page" — and from then on, every sentence has somewhere you can go and check.

Want the mechanisms, the notation and the diagrams? → Switch to the deep read