Design a RAG Chatbot for Company Documents (Enterprise AI Search)
System design for an enterprise RAG chatbot over company documents: connectors, permission-aware retrieval, hybrid search, citations, evals, freshness.
The question: design a chatbot that answers employees' questions from company documents: wikis, policies, tickets, shared drives and chat archives. Answers must be accurate, cite their sources, respect who can see which document, and stay current as documents change. This is the most frequently asked AI engineering design question, and it tests RAG end to end: ingestion, retrieval, permissions, generation, evaluation and operations.
1. Clarify requirements
| Question | Answer |
|---|---|
| Users? | 20,000 employees; ~100K questions per day, peaking at ~10 per second |
| Sources? | Wiki, Google Drive / SharePoint-style drives, ticketing system, HR policies; ~5M documents |
| Permissions? | Users may only see answers from documents they can access in the source system |
| Freshness? | Changes searchable within 15 minutes; permission revocations even faster |
| Quality bar? | Grounded answers with citations; say "I don't know" rather than guess |
| Latency? | First token under 2 s |
2. Define evaluation first
- A golden set of ~300 real questions with the documents that answer them and key facts, across departments, including questions with no answer in the corpus and questions about restricted documents.
- Metrics: retrieval recall@10, faithfulness (claims supported by cited chunks), correctness against key facts, refusal accuracy on unanswerable questions, and zero leaks on permission tests.
- See LLM evaluation.
3. Architecture
4. Ingestion
- Connectors per source pull content and permissions, using webhooks for change notifications plus periodic reconciliation crawls (webhooks get missed).
- Parsing and chunking: layout-aware parsing, structural chunks with title and section path prepended; see chunking strategies and document ingestion pipeline.
- Incremental updates: re-chunk only changed documents; upsert new chunks and delete old ones by document version.
- Queue-based workers so spikes (a whole drive shared at once) are absorbed; see message queues.
Corpus : 5M docs × ~8 chunks = 40M chunks
Vectors : 40M × 1,024 dims × 4 B ≈ 164 GB (float32) → ~41 GB as int8
Initial load: 40M chunks ÷ ~2,000 chunks/s embedding throughput ≈ 5.5 hours
Daily churn : ~1% of docs change → 400K chunks/day re-embedded, trivial
Keyword idx : BM25 over the same chunks in a search engine5. Retrieval that respects permissions
The non-negotiable requirement. Each chunk stores the document's ACL (users and groups allowed). At query time, resolve the user's groups and apply them as a filter inside both searches, so restricted content never reaches the model or the prompt.
- Never retrieve first and filter afterwards in the prompt ("only use documents the user may see"): the model would see the restricted text.
- Group membership is cached with a short TTL; revocations from the identity provider invalidate it immediately.
- Permission changes in a source re-tag affected chunks quickly (they're metadata updates, no re-embedding).
- Very large ACLs (documents shared with thousands of groups) are expensive to filter; index by group, or partition the index by top-level group.
6. Retrieval and generation
- Rewrite follow-up questions into standalone queries using chat history.
- Hybrid search: BM25 for names, error codes and acronyms; vectors for paraphrases; fused with RRF; cross-encoder rerank to the best 6-8 chunks.
- Prompt: answer only from the provided sources, cite each claim with a source id, and say when the sources don't answer the question.
- Render citations as links to the source document (title, section, last updated).
- Optional grounding check on the answer before display for high-stakes areas (HR, legal).
7. Serving, latency and cost
Peak : 10 questions/s
Latency plan : rewrite 300 ms (small model) | retrieval 80 ms | rerank 80 ms
| first token ~700 ms → first text in ~1.2 s, then streaming
Tokens/query : ~600 system + 2,500 retrieved + 400 history + 300 output
Cost/day : 100K × (3.5K in + 300 out) at illustrative mid-model prices
≈ 350M input + 30M output tokens/day → a few hundred dollars/day
Levers : prefix caching for the system prompt, smaller model for rewriting,
fewer but better chunks after reranking8. Security
- Documents are untrusted: a page can contain injected instructions. The chatbot has no write tools, and output links are restricted to internal domains. See prompt injection.
- Logs and traces contain sensitive content: redact, restrict access, and apply retention.
- Audit who asked what and which documents were used, for compliance.
9. Operations
- Monitor ingestion lag per connector, failed parses, index freshness and permission-sync lag.
- Quality: thumbs-down rate, "I don't know" rate, sampled faithfulness scores; review negative feedback weekly and add cases to the golden set.
- Re-embedding on embedding model changes builds a new index in the background and switches atomically.
- See LLMOps.
Follow-up questions to expect
- *The answer is wrong but the document exists. Debug it.* Walk the stages: ingested? parsed? permission filter? chunk boundary? retrieval recall? reranked away? ignored by the model? See advanced RAG.
- *How do you answer "summarise all incidents this quarter"?* That's corpus-wide: use a structured query over ticket metadata or precomputed summaries, not top-k retrieval.
- *How do you stop answers from stale documents?* Prefer recent versions in ranking, show last-updated dates, and flag documents past a review date.
Where it’s used
Employees ask questions across wikis, drives and tickets with permission-aware answers.
Public-facing variant with simpler permissions but stricter tone and escalation rules.
Answers from product docs and past tickets, with citations agents can verify.
In an interview
- Define a golden set with unanswerable and permission test cases first.
- Design ingestion with connectors, incremental updates and permission sync.
- Filter by ACL inside retrieval, never in the prompt.
- Use hybrid search, reranking and cited answers, and debug failures stage by stage.
Frequently asked questions
How do you design a RAG chatbot for company documents?
Ingest documents and permissions through connectors, parse and chunk them, index with keyword and vector search, retrieve with the user's permissions as a filter, rerank, generate answers with citations, and evaluate retrieval and faithfulness separately.
How do you enforce document permissions in RAG?
Store each document's access list on its chunks and apply the user's groups as a filter inside retrieval, so restricted content never reaches the model or the prompt.
Further reading
- Retrieval-Augmented Generation for Knowledge-Intensive NLP TasksLewis et al., NeurIPS 2020
- RAGAS: Automated Evaluation of Retrieval Augmented GenerationEs et al., 2023