download

Design a chatbot that answers from company docs. Walk me through it.

System design~15 minReviewed 1 Nov 2026Free · No sign-in

Question

An online shop has 3,000 help articles and policies: returns, delivery, warranty. Each is about 1,200 tokens long, and about 50 change every week. Some pages are for support agents only.

The shop wants one chatbot for customers and agents. It must answer from these pages, not from the model's memory.

  1. What runs before any question arrives?
  2. A customer asks: "Can I return shoes after 40 days?" Walk through every step until the answer appears.
  3. How do you keep the bot from making things up?
Show hints (3)
  1. "DO THE SIZE FIRST"

    Multiply 3,000 articles by 1,200 tokens. Can you send all that with every question? If not, what do you send?

  2. "TWO PATHS"

    Some work happens when a document changes, some when a user asks. Split the design into those two paths.

  3. "WHO MAY READ IT"

    A customer must never get an agent-only page. Where does that rule go: in the prompt, or in the search itself?

Show checked explanation

Use retrieval-augmented generation (RAG). An indexing path splits each page into chunks, embeds them and stores them with metadata. A query path filters by who is asking, finds the best few chunks and has the model answer only from them, with citations. If nothing relevant is found, the bot says so and offers a human.

The sizes and token counts were recomputed in CPython 3.12. Checked by an editor other than the author.

Walkthrough

3,000 articles of 1,200 tokens is 3.6 million tokens, far too much to send with every question. So you send only the few pieces that answer it. RAG has two paths.

The indexing path runs when a page changes.

stepwhat it does
parseturn pages and PDFs into clean text, keep the headings
chunksplit along sections into pieces of about 400 tokens
embedturn each chunk into a vector
storesave the vector, the text and metadata: page id, title, link, date, audience

3.6 million tokens in 400-token chunks is about 9,000 chunks, a small index. Index the same chunks for keyword search too, so exact terms like error codes still match. When a page changes, delete its old chunks by page id and add the new ones.

The query path for "Can I return shoes after 40 days?":

  1. Check who is asking. Customers search public chunks only, agents internal ones too. Put this filter inside the search query.
  2. Use the chat history to turn a follow-up like "And sale items?" into a full question.
  3. Search with vectors and keywords together, and take the top 20 chunks.
  4. Rerank those 20 with a slower, more accurate model. Keep the best 5, about 2,000 tokens.
  5. Build the prompt: the rules, the 5 chunks with their ids, the question.
  6. Generate an answer that cites chunk ids, and show the links to the pages.

Against made-up answers. Tell the model to answer only from the chunks, or to say they don't contain the answer. Check that every cited id was in the prompt. If even the best chunk scores low, skip the model: say "I couldn't find this" and offer a human. Wrong answers get rarer, not impossible, so measure them.

Common mistakes

  • Hiding agent-only pages with a line in the prompt. A prompt is not access control. Filter by audience in the search, so those chunks never reach the model.
  • Indexing once and never again. With 50 changes a week, old chunks pile up next to new ones, and the bot can quote both versions.
  • Answering even when retrieval found nothing useful. The model then fills the gap from memory, which is what the shop wanted to avoid.

Follow-up questions

  • "Why not fine-tune the model on the help pages instead?" Every change would need a new training run, and 50 pages change each week. The tuned model also can't cite the page or hide agent-only pages from customers. With RAG you re-index one page.
  • "How would you know the bot is good enough to launch?" Build a set of real questions, each labelled with the page that answers it. Score retrieval and answers separately, and rerun the set after every change.

What a strong answer covers

Sizes the data, then splits the design into an indexing path and a query path. Filters by permission inside the search, keeps the index fresh, cites sources, refuses when retrieval is weak and tests on real questions.

Open in interactive practice deck →

Original OfferVibe question. Topic idea from System Design with AI Interview Guide (Rohit Bhardwaj, 2026); text, examples and code are our own.
© 2026 OfferVibe · Text CC BY-NC-SA 4.0 · code MITFree to share and adapt with credit, not for commercial use. Code samples are free for any use.