RAG Chatbot: Deep Dives and Curveballs
Fifteen minutes remain, and the interviewer may leave their order to you. If so, take permissions first: a leak cannot be taken back, and a slightly worse answer can. After that come the honest index and how you would know anything improved, then four curveballs, then how a mid-level, senior and staff answer differ.
Where the Permission Check Lives
You drew a filter and a live check in Scaling It, and parked what a narrow filter does to the search. Pick that up by laying out the three places a check can live. Filtering during the search, with groups on each chunk, means five results are five usable answers. It costs a copy that lags, and a graph search that wanders when the filter matches few chunks. A vector index is usually a graph: each chunk links to its near neighbours, and the search walks those links toward the question. Under a narrow filter, most links lead to chunks it must skip. So it slows, or stops with too few.
Checking after the search, against the source, is always current, and an asker who can read little gets fewer than five. One index per group is isolation you can point at, and a document in six groups is six copies.
The choice is the filter, plus a final check of the five. Store groups, never lists of people, or one reorganisation rewrites millions of chunks. A document shared only with named people then fails the filter, a miss and not a leak, until its source gives it a group. Answer a narrow filter by comparing its few chunks directly and skipping the graph. Give the rule and its exception together: "I'd filter during the search and check the final five against the source. If a source must be provably apart, as with a merger's deal room, it gets its own index."
Filtering during the search keeps only chunks the asker may read, so five results are five usable answers, using a copy that can lag. Use it when most questions need full results and the lag has a stated bound.
Checking after the search asks the source about each result, so it is always current and may leave too few. Use it when the corpus is small or permissions change by the minute, and as the last step before the prompt in any case.
Now name what else holds the text, each with its bound. The answer cache does, behind the live check and keyed by version, and an entry goes after an assumed day. The answer records do, so only the team running the system may read them, and assume they are kept for 90 days. And the model providers see it: the answer model five chunks on every call, a rented re-ranker all 50 before the live check, and the embedding model every chunk at ingestion. What they may keep is a contract question for whoever signs that contract.
Keeping the Index Honest
Start with how a document becomes chunks. Fixed windows are simple and cut clauses in half. Splitting along headings, up to 2 KB, keeps a rule whole and costs a parser per format. The choice is structure, unless the evaluation set shows no gain on a source such as chat logs. How chunking goes wrong is taken up in Agentic AI from Scratch, in Why Retrieval Fails.
A delete has to meet its promise everywhere an answer can draw on. Within 15 minutes it writes the next version number with no chunks behind it, which closes the document at once, and only then reaches both indexes and the chunk store. That order means a late question cannot publish what is being deleted. The cache follows through its key, because those chunks never come back to form it. The nightly comparison catches a lost event, and the live check holds the line until it does.
The stream keeps the index fresh, and one kind of change still needs everything rebuilt: one that touches every chunk, such as a new chunking rule or a new embedding model. Vectors from two models cannot be compared. So the whole index is rebuilt beside the old, 8,000 seconds at the assumed rate, while the stream writes each change to both. It is scored on the evaluation set and swapped together with the question's embedding call. If the score falls, the old index is still there to stay on.
Knowing Whether It Got Better
Keyword search finds exact names and codes, vector search finds the same thing in other words, and the lists merge by rank because their scores are not comparable. The evaluation set checks that choice. It scores retrieval, meaning the right document is in the top five, and the answer, meaning correct, cited, or rightly declined. Only the second says the system works, since retrieval can be perfect and the answer still wrong.
Questions come from the answer records and from document owners. Each runs as an asker who may read its document, and past the cache, or the run scores old answers. Assume 30 of the 300 have no answer in the documents, to test "I can't find that". A run costs about $3 at a cent an answer, so it runs on every change to chunking, ranking, prompt or model. Building the set in full is Agentic AI from Scratch, Chapter 9.
Curveballs
"The model makes something up. How do you detect it, and how do you measure it?" Those are two jobs. Per answer, every citation must be an ID that was in the prompt, a quoted passage must exist in that chunk, and an answer with no citation becomes "I can't find that". The words are already on the screen when the stream ends, so a failed check closes it with the status withdrawn and the client replaces the text. Words vanishing looks odd, and that is the price of streaming before checking. Only an answer that passes enters the cache.
In aggregate, count unsupported claims on the evaluation set and on a daily sample of live answers, read by the team allowed to read the records. No check proves truth, and you say so: a citation check proves that a citation exists. Why models do this is Working with LLMs from Zero, Chapter 3.
"A document contains instructions addressed to your assistant." Anyone who can edit a page can write those, and no prompt wording fixes it, so limit what obeying can do. The assistant has no tools. The filter keeps it to what the asker could already read. Links and images in answers are limited to the cited sources, so nothing leaves through one. What remains is a wrong answer, and its citation may not even name the page responsible. If actions ever arrive, the problem changes, and Agentic AI from Scratch takes it up in Chapter 12.
"Add a new source of two million documents." Arithmetic first. At 8 chunks a document that is 16 million more chunks. At 6 KB each that is 96 GB, and 144 GB in all. At 50 GB a partition that is 3 partitions, and with a replica each, 6 nodes. Hash by document ID, so one document's new version, cleanup and permission rewrites each touch one partition. The flip stays one row in the chunk store. A question has no partition key, so it asks all three and waits for the slowest, as Chapter 3's Range, Hash and Directory says of any read not by the key. The keyword index splits the same way. The chunk store grows to 48 GB of text, well inside one node at an assumed 2 TB, and stays one store.
The backfill is 16,000 seconds at the assumed rate, about four and a half hours. It runs on its own low-priority queue, so the 15-minute stream never waits behind it, the separation Chapter 6's Backpressure and Load Shedding asks for. These sizes hold at 3 million documents and the same 60,000 employees, whose questions do not change. A source with no permission mapping is not indexed, whatever its size.
"The model provider is down." Show the retrieved passages with links and say the answer is unavailable, because retrieval is still yours. Stop the calls with a breaker while that lasts, as in Chapter 6's Failure Across Many Services. A second provider covers the answer if the evaluation set passes on it first, and it brings a second contract about what may be kept. It does not cover the question's embedding, since vectors from another model mean nothing in this index, so keyword search alone carries that outage.
How Each Level Answers
At mid level, the answer gets as far as the working pipeline, chunk to prompt to answer, with sound arithmetic on the index. It comes to permissions when the leak probe arrives, and first reaches for a filter on the results. It offers better retrieval as a list of techniques until asked how they would be measured.
A senior answer asks about permissions first and parks them by name. It says 50 open calls and $1,800 a day without being asked. It raises deletion and the staleness of copied permissions before the probes, brings the evaluation set before any claim of improvement, and puts the cache behind the live check so it cannot reopen the leak.
A staff answer asks what a wrong answer costs: a misquoted HR policy is a legal problem, a misquoted wiki page an annoyance, and that sets how often the design declines. It raises what the provider may keep, and who owns the evaluation set once the team moves on. It plans the embedding upgrade with a rollback. And it asks whether $36,000 a month is worth what it saves, and proposes how that would be measured.
- Touring chunking settings when the interviewer wanted the permission model.
- Answering the injected instructions with a better system prompt, the leak probe's mistake again.
- Failing over the embedding model like the answer model, then searching vectors that mean nothing.
- Claiming that a citation check proves truth, when it proves that a citation exists.
- Permissions taken first when the order is left open, with the reason.
- A bound given for each place stale or forbidden text can live.
- The two-million-document arithmetic done before any change is named.
- What is detected per answer kept apart from what is measured in aggregate.
Knowledge Check
The interviewer says the model sometimes makes things up. What is the strongest move?
- Tell the model in its prompt never to state anything it cannot support
- Have a second model read every answer and declare each claim to be true
- Check each citation per answer, and count unsupported claims on a set
- Lower the model's temperature, so answers stay close to the retrieved text
A page in the corpus holds instructions addressed to your assistant. What actually limits the damage?
- A stronger system prompt that tells the model to disregard such text
- A scan at ingestion that strips sentences written as instructions
- No tools, the asker's own filter, links and images from cited sources only
- A separate model that reads every chunk for tampering before the prompt
Two million more documents arrive. At 50 GB a partition, with one replica each, how many index nodes do you need?
- Four: 96 GB of new vectors is two partitions, each on two nodes
- Three: 144 GB of vectors is three partitions, and copies share nodes
- Six: 144 GB of vectors is three partitions, each on two nodes
- Two: 144 GB of vectors fits one pair of nodes if run near full
The model provider is down. What do you do, and what does a second provider leave uncovered?
- Fail both models over to the second provider, and keep the vector index
- Show passages with links, and fail over the answer model, never the embedding
- Serve only what the answer cache holds, and refuse every other question
- Queue every question at the gateway, and answer them when it comes back
You got correct