KatInterview

Building a Multi-Tenant RAG System for Secure Document Search

Machine LearningModel answer
HardModel answerMachine Learningragmlopsinformation-retrieval

Last updated

Architect a question-answering pipeline over confidential documents with strict access controls, verifiable citations, version handling, and hallucination prevention.

Context

You're designing a question-answering system for an enterprise document repository containing sensitive materials like contracts, regulatory filings, and internal communications. Users submit natural language queries and receive answers with precise source citations showing exactly where information was found (document name, section, page, and coordinates).

The system must enforce strict security boundaries—users only access documents they're authorized to see, and data from different organizations never mix. Documents are frequently updated with new versions (like contract amendments replacing original terms), and the system needs to track which version is current. When the evidence is unclear or contradictory, the system should decline to answer rather than fabricate information.

Your Task

Design the complete machine learning system architecture covering:

Core Capabilities:

  • Accept documents in multiple formats (PDFs, Word files, scanned images), extract their structure, and prepare them for search
  • Answer questions using retrieved context while providing exact citations with page numbers and text coordinates
  • Enforce access controls so users only see results from documents they're permitted to access
  • Handle document versions correctly, applying amendments that override older clauses
  • Recognize when retrieved evidence is insufficient or conflicting, and abstain from answering

System Constraints:

  • Scale: 500 million searchable text segments across 1,000 separate organizations; the largest single organization has 50 million segments
  • Performance: 95th percentile end-to-end query time under 2.5 seconds, with retrieval completing in 300ms and answer generation starting within 800ms
  • Data freshness: New documents or permission changes must be searchable within 60 seconds
  • Accuracy requirements: Absolutely no cross-organization data leakage; hallucination rate (unsupported claims) below 1%

What to Address

Your design should cover:

  1. Architecture overview: How documents flow from upload through indexing to query serving
  2. Retrieval strategy: How you find relevant passages at scale while respecting access permissions
  3. Citation mechanism: How you ensure every answer sentence maps to actual source text
  4. Version management: How you handle documents that supersede or amend earlier versions
  5. Security model: How you prevent unauthorized access and prompt injection attacks hidden in documents
  6. Evaluation approach: How you measure retrieval quality, answer accuracy, and citation correctness

Discuss concrete technology choices, data models, and tradeoffs between approaches.

Hints

Hint 1

Consider how access control filtering interacts with approximate nearest neighbor search—post-filtering can leak information and hurt recall

Hint 2

Document amendments create temporal relationships between versions; you need both structural parsing to detect references and a resolution layer at query time

Hint 3

Citations must be verified programmatically against retrieved sources before returning to users; relying solely on the language model produces hallucinations