KatInterview

Design an End-to-End RAG System for a Large Document Corpus

Machine LearningModel answer
HardModel answerMachine LearningRAGLLMvector-search

Last updated

Design a production RAG pipeline that ingests millions of documents, retrieves grounded context, and generates cited answers with low latency at scale.

Scenario

Your company maintains an internal knowledge base of roughly 10 million documents — a mix of PDFs and Markdown files — stored in cloud object storage. Employees need to ask natural language questions and get concise, accurate answers that point back to the exact source documents.

You are asked to design the full production system, from the moment a document lands in storage to the moment a cited answer reaches the user.

Functional Requirements

  1. Ingestion: The system must detect and process new or updated documents automatically.
  2. Retrieval: Given a natural language query, the system must surface the most relevant document passages.
  3. Generation: An LLM must produce an answer grounded in the retrieved passages and include verifiable citations.
  4. Resilience: The system must handle component failures and high-latency conditions without silent degradation.

Non-Functional Requirements

DimensionTarget
Corpus size10 million documents
Retrieval latencyp95 under 200 ms
End-to-end latencyUnder 3 seconds, first token under 1 second
HallucinationsMinimized through grounding and post-generation checks

What You Are Expected to Cover

  1. Architecture overview: Describe the flow from document storage through ingestion, retrieval, and generation to the final response.
  2. Ingestion pipeline: Explain how you parse, chunk, and embed documents, and which vector store you would choose and why.
  3. Retrieval strategy: Explain how you combine retrieval methods, and how you rerank results before passing them to the LLM.
  4. Grounding and orchestration: Explain how you construct the prompt, enforce citation, and validate the output.
  5. Evaluation: Define how you would measure retrieval quality and generation accuracy in both offline and online settings.

Discuss trade-offs and failure modes at each stage. There is no single correct answer, but your choices should be justified with numbers and concrete reasoning.

Hints

Hint 1

Start from scale estimates before drawing any boxes — how many chunks do you actually have, how big are the vectors, and what does that imply for storage and indexing?

Hint 2

Dense retrieval alone fails on exact tokens like product codes and CLI flags. Think about what complementary retrieval method covers that gap, and how you combine the two ranked lists.

Hint 3

Getting relevant chunks into the top-100 is a recall problem; getting the right 5–8 into the LLM prompt is a precision problem. These call for different solutions at different points in the pipeline.