KatInterview

Multi-Stage Retrieval System for Document Search

Machine LearningModel answer
MediumModel answerMachine Learningretrievalrankingrag

Last updated

Design a scalable retrieval and ranking pipeline for querying 10M documents under 2s latency at 500 QPS with permission enforcement.

You're building the backend for an internal knowledge assistant that answers employee questions by searching across a large collection of company documents. The corpus contains approximately 10 million PDF and Word files covering internal policies, technical documentation, and project materials.

When an employee submits a natural language question, your system must find the most relevant passages from documents they're authorized to access, then feed those passages to a language model to generate an answer.

Constraints

  • Scale: 10 million documents in the corpus; approximately 30 content segments per document on average
  • Performance: p95 latency under 2 seconds from query submission to first response token; support 500 queries per second sustained load
  • Security: Enforce document-level permissions—users may only see results from documents their role permits them to access

What You Need to Design

Build out the complete pipeline architecture, covering:

  1. Document processing: How do you ingest, parse, segment, and index millions of documents for fast retrieval?

  2. Query execution: How do you balance retrieval speed against result quality? Consider whether a single-stage or multi-stage approach makes sense.

  3. Permission enforcement: How do you integrate authorization checks without adding prohibitive latency or returning empty result sets for users with limited access?

  4. Quality measurement: What metrics tell you whether the retrieval stage is working well versus whether the answer generation is accurate?

Describe the key components, their responsibilities, and how they interact. You may sketch a diagram or provide a written flow.

Hints

Hint 1

Break your 2-second budget across all stages—query processing, retrieval, ranking, and generation each need their share

Hint 2

Filtering unauthorized results after retrieval can leave you with too few passages; think about where permission checks happen in the index itself

Hint 3

Keyword search and semantic search each have strengths; combining them in parallel often beats either alone