Design an AI Support Assistant (RAG)
Answer customers' questions from the company's own help articles and past tickets. Each answer names its sources and stays within a time and cost budget.
Like a new support agent with an excellent librarian. Before answering, the librarian fetches the few most relevant pages. The agent then answers only from them, and says where the answer came from.
Where this analogy stops working: A person notices when a page is out of date or does not answer the question. The model may not, so the system needs citations, checks and a hand-off to a person.
- Clients
- Chat widget
- Help documents
- Entry
- Gateway
- Services
- Assistant service
- Indexer
- Retriever
- Reranker
- Guardrails
- Data, outside
- Vector index
- Language model
- Logs and evaluation
1. Requirements and scope
- Answer questions in a chat widget using help articles, product docs and resolved tickets.
- Cite the sources of each answer. When unsure, say so and hand the chat to a person.
- Keep each business customer to its own documents, so no customer sees another's files.
- Stream each answer as it is written, a few words at a time.
- First words within about 2 s, and the full answer within about 10 s.
- A cost per answer within budget. Model tokens are the main cost.
- Quality measured all the time: is each answer backed by its sources, and was the question resolved?
- New or changed articles searchable within minutes.
2. Back-of-the-envelope numbers
3. API
4. Data model and storage
CHUNK(id, doc_id, text, embedding, tenant_id, updated_at) · CONVERSATION(id, user_id, started_at) · MESSAGE(id, conversation_id, role, text, sources[], feedback)
5. The design, in three versions
Version 1: Ask the model directly
Send the customer's question straight to a language model.
AI Support Assistant (RAG): Version 1: Ask the model directly Version 1 of 3
The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.
One request, step by step
Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.
- The order of the steps
- A request or its reply
The parts: switch one off
1. Clients
2. Services
3. Data, outside
The steps in words0 of 3 steps shown
Chat widget to Assistant service
A customer asks "How do I reset my password?"
Assistant service to Language model
It sends the question to the model with no extra text.
Assistant service to Chat widget
The answer goes back. It may be made up.
Write path, read path and failures
Each path follows one request through the final design (version 3), one hop at a time.
Write pathA help article changes
- Help center
- Re-index worker
- Embedding model
- Search index
Help center to Re-index worker
An edited article sends a change event.
Re-index worker to Embedding model
The worker cuts the article into passages and gets a vector for each one.
Re-index worker to Search index
It replaces the article's old passages with the new ones, along with who may see them.
Read pathAnswer a question
- Customer chat
- Gateway
- Retriever
- Reranker
- Language model
- Guardrails
Customer chat to Gateway
A customer asks a question. The gateway checks who they are and how many tokens they have left today.
Gateway to Retriever
The retriever runs a keyword search and a vector search, limited to articles this customer may see.
Retriever to Reranker
A reranker reads the top 50 passages with the question and keeps the best few.
Reranker to Language model
The prompt holds the question and those passages. The model starts writing the answer.
Language model to Guardrails
Guardrails check the answer, for example for personal data or claims no passage supports.
Guardrails to Customer chat
The answer streams to the customer, with links to the articles it used.
What breaks, and what happens then
The main model is slow or down
- What users see
- No first words within the 2-second goal.
- What the design does
- After a time limit, the gateway sends the request to a fallback model.
The search finds nothing useful
- What users see
- The model may make up an answer.
- What the design does
- If the best passage scores below a set level, the assistant says it does not know and offers a human agent.
An article contains text that gives the model orders
- What users see
- The model may follow it. This is called prompt injection.
- What the design does
- Passages go into the prompt as quoted material, the model has no tools that change accounts, and guardrails check what comes out.
One customer sends a flood of questions
- What users see
- Model costs rise for everyone.
- What the design does
- Rate limits and token quotas per customer at the gateway.
6. Deep dives
7. Follow-up questions
- How do you stop one customer seeing another customer's documents? (Filter by tenant inside the search query, not after the answer is written, and test it.)
- Costs doubled last month. What do you check? (Tokens per answer, cache hit rate, passages per prompt, which model answers which questions, and abuse.)
What it costs
Model calls are the bill, and input tokens are most of it. Send fewer and shorter chunks, cache answers to repeated questions, and use a smaller model for easy ones. The search index is cheap next to that.
Another way to design it
For a small set of help articles, plain keyword search with one model call can be enough. There is no vector index to build or keep fresh. It misses questions that use different words from the article.
8. How answers are judged
A passing answer at Mid level. A complete design with numbers: about 20 questions a second at peak, each needing an embedding, a search and a model call. It explains retrieval-augmented generation and goes deep on one part, such as citations.
| What is judged | Junior | Mid | Senior | Staff |
|---|---|---|---|---|
| BreadthHow much of the system does the answer cover? | Names the core parts: clients, servers, a database and a cache. | Covers the whole main flow, from the request to the stored data and back. | Builds a complete design without being led through it. | Covers the system, the systems around it and who owns each part. |
| DepthHow far does it go into the hard parts? | Explains what each part does and why it is there. | Goes deep on one part, such as the database or the cache. | Goes deep on the two or three riskiest parts. | Goes deepest where the risk is largest, and explains why the risk is there. |
| DrivingWho leads the conversation? | Follows the interviewer, step by step. | Moves forward alone, with an occasional nudge. | Leads the conversation from start to finish. | Changes the problem when the question asked is not the right one. |
| Trade-offsAre choices compared and justified? | Names more than one option. | Says why one option was picked over another. | Compares options in detail, with what each one costs. | Ties each choice to cost, speed and risk for the business. |
| Unclear questionsWhat happens when the question is vague? | Answers the questions that are asked. | Asks questions to make the problem clear. | Sets the scope and says what is left out. | Questions the assumptions behind the problem itself. |
| ScopeWhat does it consider beyond the normal path? | Covers the normal path, when everything works. | Adds what happens when a part fails. | Adds growth: what breaks at ten times the load, and the fix. | Adds abuse, cost and the daily work of running the system. |
Requirements and scope
Before I design, I want to check the scope. Answers must cite sources and hand off to a person when the model is unsure, and each business customer must only see its own documents. Do users need every article searchable at once, or is the newest set enough for now? I will assume first words appear within about 2 seconds.
Customers type a question into the chat widget, and I send it straight to the model for an answer. Since language models are trained on a huge amount of text already, that should cover most product questions.
Shows: Unclear questionsThe difference: A model trained on general text was never trained on this company's own documents, so it can only guess plausible answers. Retrieving real passages first grounds the answer instead.
Estimates
200,000 questions a day is about 2.3 a second on average, rising to the stated 20 at peak. Each needs one embedding, one search and one model call, so peak needs 20 a second of model capacity, not the average. The index is about 40 gigabytes for 5 million chunks, plus about 365 gigabytes a year of conversation logs.
500,000 documents at about 6 kilobytes a vector is about 3 gigabytes for the index, so a single small server holds it comfortably.
Shows: DepthThe difference: The index is built from chunks, not whole documents, and there are about 5 million of those. That is closer to 40 gigabytes, not 3.
Core design
Documents are chunked and embedded offline into a vector index. Retrieval mixes vector and keyword search, filtered to this customer's documents, then a reranker picks the best passages, together taking roughly 100 milliseconds. Streaming then shows first words as soon as the model's first token arrives, roughly 0.3 to 2 seconds later, well before the full answer finishes.
I would retrieve the best matching passages across every customer's documents, then filter out any that are not this customer's before they reach the model.
Shows: DepthThe difference: Passages from another customer already reached retrieval and could still slip into the prompt before the filter runs. Filtering inside the retrieval query is what stops that.
Deep dive
The hard part is knowing whether the system is actually working, since a model can sound confident while it guesses wrong. I would keep a fixed set of real questions with known answers, and run it on every prompt, model or index change. I would track groundedness, whether each claim traces to a cited passage, and the hand-off rate.
I would watch the thumbs up and thumbs down feedback users leave on each answer. If that stays mostly positive, I would treat the system as working well.
Shows: DepthThe difference: Live feedback alone will not catch a regression from a prompt or index change before users see wrong answers. A fixed test set run on every change catches it first.
Failures and trade-offs
If the model is slow or down, I would time out and fall back to a smaller, faster model, or hand off to a person. Since tokens are the main cost, I would cap tokens per customer with a daily quota. I would also alert if cost per answer climbs above the budget.
If the model is slow, I would let the request wait. A right answer that takes longer beats a fast wrong one.
Shows: Trade-offsThe difference: A customer waiting indefinitely for one slow request still costs a connection and tokens, with no answer meanwhile. A timeout with a fallback model or hand-off keeps the product responsive.
We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.
10. Check your design with your own AI
Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.
The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.
See the prompt
You are a system design interviewer. Review my design for the interview problem below. Problem: Design an AI Support Assistant (RAG) Answer customers' questions from the company's own help articles and past tickets. Each answer names its sources and stays within a time and cost budget. What users must be able to do: - Answer questions in a chat widget using help articles, product docs and resolved tickets. - Cite the sources of each answer. When unsure, say so and hand the chat to a person. - Keep each business customer to its own documents, so no customer sees another's files. - Stream each answer as it is written, a few words at a time. How well it must work: - First words within about 2 s, and the full answer within about 10 s. - A cost per answer within budget. Model tokens are the main cost. - Quality measured all the time: is each answer backed by its sources, and was the question resolved? - New or changed articles searchable within minutes. Numbers to assume: - 200,000 questions a day, peaks of about 20 per second. - 500,000 documents split into about 5 million chunks. Judge my design at the Mid level. A passing answer at this level: A complete design with numbers: about 20 questions a second at peak, each needing an embedding, a search and a model call. It explains retrieval-augmented generation and goes deep on one part, such as citations. For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each: 1. Requirements and scope 2. Estimates 3. Core design 4. Deep dive 5. Failures and trade-offs Then ask me the two follow-up questions an interviewer would ask next. Do not write a full model answer for me. My design: [Describe your parts, how one request moves through them, and why you chose each one.]