Lesson 1 · Minutes 0-10

RAG Chatbot: Scope

Problem

Ask how many documents first and you have started the wrong problem. The question that belongs at the front of these ten minutes is who may read what, because the answer reaches every box you have not drawn yet. After it come the sums that are unusual here, calls you rent and money per answer, and the minutes end on the API.

Six Questions, Permissions First

Each of these changes the drawing, so each comes with what it moves and the answer agreed here.

  1. May every employee read every document? A no means retrieval has to know who is asking, and that is the hardest part of this design. Agreed: no. Each source keeps its own permissions, and an answer may never draw on what the asker cannot open.
  2. How many documents, how large, and how many people ask? This sizes the index and the bill. Agreed: 1 million documents of about 16 KB of text, and 60,000 employees asking 3 questions each on a working day.
  3. How soon must a changed or deleted document show in answers? This picks a scheduled rebuild or a stream of changes. Agreed: within 15 minutes.
  4. What should it do when the documents do not say? Saying so needs a path for not found, and a way to measure it. Agreed: every claim cites a source, and otherwise the reply is "I can't find that".
  5. How long may an answer take, and what may it cost? This turns the model call into a budget. Agreed: first words within 2 seconds. Assume about 5 seconds for the whole answer and about a cent per answer, every model call included.
  6. Does it only answer, or does it act, and does it follow up? Acting makes it an agent, a different design that Agentic AI from Scratch covers. Agreed: it only answers, and each question stands alone.

The first answer is one you cannot act on yet, so say what you are doing with it. Retrieval works on chunks, short passages cut from each document, and the line goes: "Permissions are the hardest part here, so I'm parking them by name. For the first design, treat every chunk as readable, and I'll come back to it first."

Requirements, With the Model as a Rented Service

An employee asks in words and gets a streamed answer that links its sources. When the documents do not cover the question, they hear "I can't find that". They can give feedback on any answer they received.

Four things are non-functional. No answer draws on a document the asker cannot read. A change or delete shows within 15 minutes. First words arrive within 2 seconds. And the bill is one somebody has agreed to.

Name the exclusions aloud: actions, conversation memory, training a model, and which model is best. The model is a rented service with a time, a price and a ceiling, and the design treats it as exactly that. Its values here are your assumptions, because such numbers move every few months, and the interviewer can change any of them.

Open Calls and Money Decide

The request rate comes first because the interviewer expects it, and then you drop it. Sixty thousand people at 3 questions each is 180,000 a day. Over 86,400 seconds that is about 2 a second, an average nobody sees. Assume a fifth of the day's questions arrive in the hour after nine. That is 36,000 in 3,600 seconds, or 10 a second, this problem's own peak. Ten a second decides nothing for the application tier.

Now hold each of those for the model. At 10 a second, with each call open about 5 seconds, about 50 are open at once. The limit here is a rented service, not a machine of yours, and the nine o'clock probe in Scaling It is about this number.

The bill comes from the same count. A hundred and eighty thousand answers at a cent is $1,800 a working day. Assume 20 working days, and that is $36,000 a month, which is why a saved model call is worth designing for. In the room it can come out as: "Ten a second is nothing for my servers. It's also 50 calls open on someone else's service and $1,800 a day, so those are the two numbers I'll design against."

The question load, and what each number decides
Reads3 questions each, a fifth in the hour after nine
About 2 a second, 10 in the hour after nine. Decides nothing.
Model callsassumed 5 seconds an answer
About 50 open at once, 100 in the first minutes at twice the rate. One provider quota of an assumed 100 open calls. The provider's limit decides.
Bandwidth out10 KB of text to the model per question
About 100 KB a second at peak. Decides nothing.

The corpus takes a few more steps. One million documents at 16 KB is 16 GB of text, which decides nothing. Assume chunks of about 2 KB. That is 8 a document, and 8 million in all. Each chunk gets an embedding: a vector of 1,536 numbers, produced by a model so that passages with similar meaning land near each other. Each vector takes 6 KB, so the whole index is 48 GB.

Assume the index lives in memory. A mid-size memory node holds about 100 GB, and assume you run it at half its limit, 50 GB. So one index fits on one node, just. There are no partitions yet, and the text stays out of the index. The 48 counts the vectors alone, so the index's own structure comes out of the half you held back, and 8 million chunks is this node's ceiling.

Rebuilding sets the last number. Assume 1,000 chunks a second through the embedding service. Eight million takes 8,000 seconds, a little over two hours. A whole rebuild is an overnight job, and losing the only copy of the index costs two hours with no answers.

The index, from documents to one node
Text1 million documents at 16 KB
16 GB. Decides nothing.
Chunks2 KB each, assumed
8 a document, 8 million in all.
Vectors1,536 numbers, 6 KB each
48 GB. One node, at 50 of its 100.
Rebuild1,000 chunks a second, assumed
8,000 seconds, a little over two hours.

Two sums you skip aloud. Assume 1 percent of documents change on a working day: 10,000 documents, which is 80,000 chunks. Over about 100,000 seconds that is under one a second, so ingestion is hard for its deletes and permissions and never for its rate. And a 10 KB prompt at 10 a second is 100 KB a second, against 1.25 GB a second on a 10-gigabit link.

API and Entities

Two calls carry it. A POST to answers takes the question and returns a stream: the words, then the citations, each with a title, a link and a chunk ID, then a status that says how it ended, naming any source that did not reply. The asker comes from the sign-in token and never from the body, which matters the moment permissions arrive. A POST to an answer's feedback takes a thumbs up or down, and only from the person who asked.

The two calls
POST /answers                  Authorization: Bearer <sign-in token>
  {"question": "How long is parental leave?"}
  200 text/event-stream
    words      "Employees receive sixteen weeks [c-8841]"
    citations  [{"title": "Parental leave", "link": "https://hr.example/leave", "chunk": "c-8841"}]
    done       {"answer_id": "a-5521", "status": "answered", "unreachable": []}
               # or not_found, sources_only, withdrawn

POST /answers/a-5521/feedback  {"rating": "down"}
  204

There are three entities. A document has an ID, a source, a title, a link, a version and the time it was updated. A chunk has an ID, its document's ID and version, a position, its text and its vector. An answer record keeps the question, the asker, the answer, the chunks used, the model, the time and the cost. Keep that record from day one, because the bill and the evaluation set are both read from it.

Interview Pitfalls
  • Reaching for the vector database before asking who may read what, so the hardest requirement arrives as a surprise at minute 21.
  • Sizing the request rate with care and leaving the 50 open calls and the $1,800 a day unsaid. The interviewer hears a web-service estimate for a problem that is not one.
  • Asking which model to use. It is out of scope, and it spends the minutes permissions need.
  • Leaving "what if the documents do not say?" unasked, then having no reply when the interviewer asks how a made-up answer gets noticed.
What Interviewers Listen For
  • Permissions asked about before any box exists, and parked by name.
  • The model call named as the expensive thing, with a number.
  • The corpus turned into 48 GB in a few spoken steps, followed by what that decides.

Knowledge Check

The interviewer will take one question before you draw. Which answer would move this design furthest?

  • Which file formats the company's documents are stored in today
  • Whether every employee may read every document in the company
  • How many languages the documents and the employees are using
  • Whether employees reach it from a chat tool or from a web page

At peak there are 10 questions a second, and each answer holds a model call for about 5 seconds. Why does 50 open calls decide something when 10 a second does not?

  • Fifty open calls need fifty application servers, one held for each
  • Ten a second is an average, while fifty is the true peak of the day
  • Fifty open calls would fill the 10-gigabit link at the application tier
  • Ten a second fits your tier, while fifty open calls meet a limit you rent

One million documents of 16 KB, cut into 2 KB chunks, at 6 KB a vector. What do you conclude, with a node run at 50 of its 100 GB?

  • 48 GB of vectors fits one node, so the text stays out and nothing is split
  • 64 GB with the text inside the index fits one node at about half its size
  • 48 GB of vectors is past a safe limit, so the index needs two partitions
  • 16 GB of text is the corpus's real size, so the index fits many times over

You want one thing off the board before you draw. Which is safe to rule out?

  • Saying so when the documents do not cover what was asked
  • Removing a deleted document from answers within minutes
  • Filing a leave request on behalf of the person who asked
  • Linking each claim in an answer back to its own source

You got correct