KatInterview

Design a Document Q&A Service with Retrieval-Augmented Generation

Machine LearningModel answer
HardModel answerMachine LearningRAGLLMvector-search

Last updated

Architect a production RAG system that lets employees query a large internal document corpus and get cited, access-controlled answers within two seconds.

Scenario

Your team is building an internal knowledge assistant for a large organization. Employees need to search across hundreds of thousands of internal documents — policies, technical guides, meeting notes, and reports — and get concise AI-generated answers that cite the exact source. Unlike a general-purpose chatbot, this system must respect who is allowed to read what, stay fresh as documents change, and never fabricate references.

What You Are Designing

A query-and-answer service backed by a large document corpus. The system ingests uploaded files (PDF and Markdown), indexes them for retrieval, and at query time fetches relevant passages to ground an LLM response.

Scale and Constraints

  • Corpus: 500,000 documents today, growing by roughly 5,000 per day. Expect around 30 chunks per document, so about 15 million indexed chunks.
  • Traffic: Approximately 50 queries per second at peak.
  • Latency: A complete answer (or the first streamed token) must arrive within 2 seconds.
  • Freshness: An edit to any document must be reflected in search results within 1 hour.
  • Access control: Users may only receive content from documents they are authorized to read. Revoking access must take effect within minutes, not hours.
  • Safety: The system must not leak PII from documents, and it must not let the model answer from unauthorized content even under adversarial prompting.

What Is Expected

Walk through your design covering:

  1. Ingestion pipeline — how documents are parsed, split into chunks, and embedded.
  2. Storage layer — what goes in the vector index, what goes in a relational store, and why.
  3. Retrieval logic — how hybrid search, access filtering, and re-ranking work together.
  4. Grounding and citation accuracy — how you prevent the model from hallucinating or fabricating references.
  5. Observability — which metrics tell you the pipeline is healthy and the answers are good.

Justify your choices, call out trade-offs, and flag what you would confirm with stakeholders before locking in an approach.

Hints

Hint 1

Start by sizing the problem: how many chunks exist, how large are the vectors, and how does that shape your storage and latency budget? Allocate milliseconds to each stage before picking components.

Hint 2

Access control must be enforced inside the vector search query — as a pre-filter, not a post-filter. Post-filtering can silently return too few results and leaks information through score distributions and timing.

Hint 3

Hallucination and citation drift are retrieval problems as much as generation problems. Think about what you can check automatically after the model responds, and when you should refuse to generate at all.