Chapter Twenty-Six · Problem Twenty

RAG Chatbot

An assistant over a company's documents: text some askers may never see, an index that has to forget on time, and a model you rent by the call.

4 lessons · 45 minutes
The Question

"Design an assistant that answers employees' questions from the company's internal documents and cites its sources."

A demo of this takes an afternoon: search some documents, paste what comes back into a prompt, show the reply. The interviewer wants the version that can hold HR's folder without showing it to the wrong person, quotes this morning's policy and not last week's, and says so when the documents have no answer.

The pattern has a name, RAG, for retrieval-augmented generation: find the passages, then ask the model to answer from them. The question does not use the word, and neither should you until you have asked who may read what.

The round is pitched at senior, and it leans on three chapters. Chapter 2's Stateless Services, Many Copies and Caching at Scale give you a tier of servers that mostly wait and a cache that must not hand one asker's answer to another. Chapter 3's When One Machine Is Not Enough and Range, Hash and Directory apply once an index that every question must ask outgrows one node. Chapter 6 runs through the rest: Queues, Logs and Pub-Sub and Delivery Semantics at Scale for ingestion, Backpressure and Load Shedding and Failure Across Many Services for a provider that says no.

Three things are hard, all under the time and price of model calls. One is ingestion: chunking, embeddings and a vector index, kept fresh as documents change and are deleted. Another is retrieval quality: keyword and vector search together, re-ranking, and an evaluation set that says whether answers are right. The last is access control, because an answer may never draw on a document the asker cannot read.

This chapter is the system around the model. Prompting and the model in use belong to Working with LLMs from Zero. Embeddings and vector search from the inside, and agents, belong to Agentic AI from Scratch. Here the model is a service you rent, with a time, a price and a ceiling you assume out loud.

This is the book's last problem, so run it as a dress rehearsal: start a 45-minute timer and sketch yours first. Then mark every place on your sketch where HR's text could sit, and count them. The four lessons keep the clock: ten minutes of scope, ten for a first design, ten of probes, and fifteen for whatever the interviewer digs into.

The 45 minutes of this problem, lesson by lesson
Scopeminutes 0-10
→
First Designminutes 10-20
→
Scaling Itminutes 20-30
→
Deep Divesminutes 30-45

Lessons in This Chapter