KatInterview

Designing a grounded document Q&A platform with citations and access control

System DesignModel answer
MediumModel answerSystem Designragretrievalsystem-design

Last updated

Design an enterprise RAG system over millions of private documents: hybrid retrieval, reranking, cited generation, strict tenant/ACL isolation, and a 60-second freshness budget.

Scenario

A knowledge-heavy organization (think a law practice or a financial research desk) wants an internal assistant that answers questions in plain language over its whole document corpus. Documents arrive in many formats — digital PDFs, Word files, scanned images — and users expect synthesized answers where each factual statement points back to the exact place it came from.

Design the system end to end. Walk through ingestion, storage, retrieval, generation, and observability, and be ready to justify your numbers.

Functional requirements

  • Ingest heterogeneous documents (PDF, DOCX, scanned pages) with parsing, OCR where needed, metadata extraction, and chunking.
  • Retrieve passages that match both meaning and exact wording — legal citations, defined terms, party names, section numbers.
  • Answer with a concise synthesis where every claim is tied to a citation at page/paragraph granularity.
  • Isolate tenants and enforce document-level permissions so a user can never surface content they aren't entitled to see.

Non-functional requirements

  • Latency: P95 first token under 2.5 s with streamed responses.
  • Scale: ~10M documents at ~5 pages each (roughly 50M chunks); ~10K document updates per day.
  • Throughput: 100 QPS at peak; up to 50 concurrent ingestion workers.
  • Freshness: newly added or edited documents become searchable within 60 s.
  • Integrity: zero cross-tenant leakage; no unsupported claims in answers.

What to cover

  1. Ingestion and indexing pipeline (parsing, OCR, chunking, embeddings, metadata).
  2. Storage choices and schemas for vectors, keyword indexes, document blobs, and relational metadata.
  3. Hybrid retrieval, rank fusion, cross-encoder reranking, and where to apply ACL filters (pre vs. post).
  4. Prompt construction, context budgeting, citation verification, guardrails, and streaming.
  5. Evaluation and monitoring — separating retrieval quality from generation quality, plus latency and drift.

Hints

Hint 1

Do the back-of-envelope math first: vectors, text, index size, and QPS per stage tell you how to shard and what dominates latency.

Hint 2

Ask yourself what happens if you search first and filter unauthorized hits afterward — recall can collapse when a user can see only a tiny slice of the corpus.

Hint 3

Small chunks embed precisely but lose context; think about indexing small units while handing the model larger parent sections.