KatInterview

Build a RAG-powered enterprise document search platform

Machine LearningModel answer
HardModel answerMachine Learningragsearchml-systems

Last updated

Design the end-to-end architecture for a production retrieval-augmented generation system serving internal knowledge search at scale.

You're tasked with building a machine learning system that lets employees search through their organization's internal knowledge base and receive generated answers grounded in retrieved documents.

System requirements:

  • Document collection: 5 million documents averaging 2 KB each, sourced from PDFs, web pages, and support tickets
  • Update latency: New or modified content must become searchable within 5 minutes
  • Query load: Handle 300 queries per second
  • Multi-tenancy: Support multiple organizations with document-level access control lists (ACLs)
  • Performance targets: 95th percentile end-to-end latency under 1.2 seconds, cost per query under $0.002

What you need to design:

  1. Document processing pipeline: How will you parse heterogeneous formats, extract metadata, handle duplicates, split documents into chunks, generate embeddings, and support versioning with incremental updates?

  2. Search and retrieval layer: Explain your indexing strategy, including sparse and dense retrieval methods, how you'll enforce tenant boundaries and ACLs, query preprocessing, candidate selection, and reranking.

  3. Answer generation: Describe prompt engineering, how you'll ground answers in retrieved content with citations, handle streaming responses, and support multiple languages.

  4. Safety and correctness: What mechanisms will you use to reduce hallucinations, enforce citation accuracy, handle sensitive content, prevent prompt injection, and ensure ACL compliance throughout the pipeline?

  5. Measurement and observability: Define offline evaluation metrics, online experimentation approaches, feedback collection, and monitoring dashboards for latency, cost, quality drift, and ingestion health.

  6. Production architecture: Break down the system into services, explain scaling strategies for each component, model hosting and batching decisions, caching layers, vector database selection, and failure handling.

  7. Capacity planning: Estimate per-stage latency and cost, calculate embedding storage requirements, index memory footprint, and compute capacity needed to meet the SLOs.

Walk through your design decisions, justify trade-offs, and show how you'd validate that the system meets requirements.

Hints

Hint 1

Start by calculating corpus scale: total text volume, number of chunks after splitting, daily query volume, and budget per component.

Hint 2

Consider running keyword-based and embedding-based retrieval in parallel, then merging results before reranking.

Hint 3

ACL enforcement needs defense in depth: filter at retrieval time and revalidate right before generation to catch revocations.