KatInterview

Design a Production RAG Engine with Citations and Strict Access Control

Machine LearningModel answer
HardModel answerMachine LearningRAGSystem DesignVector Search

Last updated

Design, optimize, and systematically evaluate an enterprise RAG system that processes heterogeneous documents, handles ACLs, and guarantees zero stale citations under high query throughput.

You are tasked with designing an enterprise-grade Retrieval-Augmented Generation (RAG) engine for high-reliability question answering over internal corporate document ecosystems (PDFs, Markdown, wiki pages, ticket history, and API specifications). Users submit natural-language queries via an interactive interface and expect grounded responses containing verifiable citations to source passages.

Design the end-to-end platform, detail key architectural choices for low-latency high-precision serving, and define a comprehensive evaluation framework covering every pipeline component.

Key Requirements

  1. Architecture & Pipeline split: Define the asynchronous ingestion/indexing pipeline and the synchronous real-time inference loop.
  2. Ingestion & Parsing: Explain layout-aware document extraction (handling tables, multi-column PDFs, code blocks, and change detection).
  3. Chunking Strategy: Detail structural and sliding-window strategies, contextual metadata enrichment, and parent-child document strategies.
  4. Retrieval & Indexing: Cover dense embeddings, BM25 lexical indexing, dynamic hybrid search, and Reciprocal Rank Fusion (RRF).
  5. Reranking: Discuss cross-encoder post-processing, latency trade-offs, and scoring calibration.
  6. Generation & Grounding: Construct the prompt framing, context ordering ("lost-in-the-middle" mitigation), citation generation, and hallucination guardrails (e.g., NLI checks, confidence gating).
  7. Freshness & Life Cycle: Explain mutation handling (updates, deletes, versioning) to guarantee zero post-deletion retrieval leaks.
  8. Security & Access Control: Enforce granular access control lists (ACLs) within search without exposing forbidden document metadata or existence.
  9. Evaluation Plan: Detail offline and online evaluation metrics (Hit@K, Recall@K, nDCG, Faithfulness, Citation Recall/Precision) per pipeline component, along with synthetic label bootstrapping techniques.

Constraints & Operational Bounds

  • Corpus Scale: 5 to 10 million text chunks (~500 tokens each).
  • Latency SLA: p95 $< 2.0\text{ seconds}$ to first stream token.
  • Freshness SLA: Document edits and soft-deletes reflected in retrieval within $< 3\text{ minutes}$.
  • Security: Hard tenant and document-level ACL isolation; no leak of unpermitted titles or metadata.
  • Safety: Mandatory citations; graceful abstention ("I cannot answer based on available documentation") when evidence is insufficient.

Hints

Hint 1

Establish clear system parameters up front: QPS, chunk index sizing, and GPU/CPU latency budgets for vector search vs cross-encoder reranking.

Hint 2

Address the security constraint early: push ACL filtering into the vector/lexical index execution plan rather than applying post-retrieval filters to prevent empty candidate pools.

Hint 3

For evaluation, separate component-level retrieval metrics (Hit-Rate, nDCG) from end-to-end generation quality metrics (Faithfulness, Citation Precision) and describe how to bootstrap synthetic query-chunk-answer triplets using an LLM.