Lesson 2 · Minutes 10-20

RAG Chatbot: First Design

Problem

Permissions stay parked, and the design that fills minutes ten to twenty treats every document as open to every employee. Under that one condition, very little has to happen. A question passes through two models and one index on its way to an answer, and once a week a job rebuilds what it searches.

This lesson sends one question down that path and one document through that job, says why a team would ship it, and ends on the conditions it rests on. Then come the interviewer's four pushes, which are the quiz.

Two Models, One Index, One Small Store

The app servers keep no state and sit behind a load balancer, the shape from Chapter 2's Stateless Services, Many Copies. The embedding model, the same one that built the index, turns the question into a vector. One vector index returns the IDs of the five chunks nearest to it. Their text comes from a small relational store, because 16 GB more in the index would push it past the 50 you allowed.

The server builds a prompt from the five, each labelled with its ID, plus the question. It tells the model to answer only from them, to cite the IDs, and to say when they fall short. Writing that prompt well is Working with LLMs from Zero's subject. The answer streams back, and the server turns each cited ID into a link.

The index has one replica, because losing its only node would stop every answer for the two hours a rebuild takes. If a node dies, searches go to the survivor while a new node copies its 48 GB, which takes about a minute and a half at half of a 10-gigabit link. The chunk store keeps a replica too, because a search with no text behind it answers nothing.

The first design
Employeeasks in words Load balancerany server App serversstateless Modelstreams the answer Embed modelbuilt the index Vector index8 million, one replica Chunk storetext, 16 GB Sourcesthe documents Weekly jobchunk, embed, swap top 5 prompt answer swap readwrite

One Question, One Document

An employee asks how long parental leave is. The server embeds those words, and the index hands back five IDs. The store hands back about 10 KB of text. The model gets the prompt, and assume the first words reach the screen about a second later, with the rest over about 5 seconds. The citations follow, the status closes the stream, and the server writes the answer record. If the five chunks do not cover the question, the model declines and the status is not found.

Now the policy itself. On Sunday night the weekly job reads it from its source along with everything else, splits it into chunks of 2 KB and sends them through the embedding model. At 1,000 chunks a second the corpus takes a little over two hours. The job writes the text to the store under new IDs and builds a new index on spare nodes beside the old. Then it swaps the two, and the old index and its rows go. A job that fails partway changes nothing, because the old index is still the one in use.

Why a Team Would Ship This

Hold it against what was agreed, on documents open to everyone. A streamed answer carries real citations, and a question the chunks do not cover can be declined. A million documents fit one node at half its limit. A stateless tier carries 50 open calls that mostly wait, and a waiting call costs a server very little.

A team ships exactly this as a pilot on an open handbook, and people use it. Describe it that way, as a pilot, because the limits that follow belong to the pilot's conditions and are not a flaw in your thinking.

The Conditions It Rests On

Four limits remain, and you fix none of them yet. Every chunk counts as readable by everyone, which is the part you parked. The index lags its sources by up to a week, and a deleted document goes on answering for all of that week. "Nearest" means similar, not correct, so a close neighbour can be the wrong policy. And every answer pays the model's full time and price, at nine o'clock included.

Hand over the conditions before you are pushed, with the size where the design stops fitting. About ten seconds is enough: "This is correct while every document in the index is open to every employee and a week-old answer is acceptable, and it fits one node up to about 8 million chunks. HR's folder breaks the first condition today, so permissions are what I'd change first."

Interview Pitfalls
  • Drawing an agent loop or a tool layer nobody asked for. The interviewer asks what each box is for, and the answer is a product name.
  • Hiding the permission gap and hoping. Parked by name it is a plan; found by the interviewer, it is a miss.
  • Leaving ingestion off the board, so the design answers from an index nobody filled.
  • Offering this as a toy "just to get started", when it is what a team ships as a pilot.
What Interviewers Listen For
  • One question and one document walked end to end, with no box skipped.
  • The reason the text stays out of the index, given with the 48 and the 50.
  • The conditions the design rests on, volunteered with the number where it stops fitting.

Knowledge Check

"An engineer asks about pay bands, and the answer quotes an HR document that engineer has no right to open. How do you fix it?"

  • "Tell the model in its system prompt never to reveal documents above the asker's level."
  • "Search only chunks the asker's groups may read, so the prompt never holds this document."
  • "Scan each finished answer and block it whenever it quotes a restricted HR document."
  • "Keep every HR document out of the index, so that nothing so sensitive is ever retrieved."

"HR changed the parental-leave policy yesterday, and the assistant still quotes the old one. Why, and what do you do about it?"

  • "Run the rebuild every night, so the index is never more than one day behind the source."
  • "Append the new version's chunks as soon as it is saved, and leave the rest of the index."
  • "Put each document's date in the prompt and ask the model to trust the newest chunk."
  • "Send each change through a queue, re-embed what changed, and retire the old version."

"A manager in Germany asks about parental leave and is handed France's policy. Retrieval did what you built it to do. What do you change?"

  • "Put the country on each chunk, add keyword search beside vectors, and re-rank the merge."
  • "Move to a larger embedding model, whose extra dimensions can separate the two countries."
  • "Pass fifty chunks in place of five, so that Germany's policy is somewhere in the prompt."
  • "Tell the model to answer only for the asker's country, whatever the chunks happen to say."

"Each answer takes about five seconds and costs about a cent, and at nine o'clock the whole company asks at once. Where does that leave you?"

  • "Add application servers, until the morning peak has enough machines to run all of it."
  • "Cache every answer by the question's wording for a day, so that repeats skip the model."
  • "Stream the words, cap the model calls behind a short queue, and cache by the chunks used."
  • "Route every question to the cheapest model, so that the bill and the wait both come down."

You got correct