KatInterview

Build a Document QA System with Grounded LLM Responses

Machine LearningModel answer
MediumModel answerMachine Learningraginformation-retrievalllm

Last updated

Design an end-to-end system that answers user questions by retrieving relevant passages from a large corpus and generating responses with citations.

You're building a question-answering service where users submit natural language queries and receive answers backed by a corporate knowledge base. The system must ground its responses in actual documents rather than relying solely on what the language model learned during training.

Your responsibility covers both components:

  • The backend pipeline that processes incoming documents, creates searchable representations, and keeps the index current
  • The request handler that takes a user's question, finds relevant content, constructs an appropriate prompt, and returns an answer with source references

Describe your architecture, justify your main technical choices with their benefits and drawbacks, and explain how you'd measure whether the system works well once deployed.

Given Information

  • Knowledge base size: approximately 10 million documents totaling around 100 GB of text in various formats (HTML, Markdown, PDF), primarily English
  • Update frequency: new documents and edits arrive constantly; users should see fresh content within minutes
  • Traffic pattern: expect peaks around 300 queries per second
  • Response time: a few seconds end-to-end is acceptable (generation takes most of this time); the retrieval portion should complete in roughly 300 milliseconds
  • Every answer must reference which passages support it, and the system should explicitly decline to answer when the knowledge base lacks sufficient information
  • The language model has context limits, and token costs make it impractical to include everything in each prompt

Questions You Should Consider

  • What's the exact composition of the knowledge base—volume, file types, languages—and how often does it change?
  • What are your targets for speed, throughput, and cost per query?
  • How strictly must answers cite sources, and what should happen when no documents match?
  • Do different users have permission to see different documents?
  • Are queries independent or part of conversations where follow-up questions need context?
  • Will you use hosted model APIs or run your own inference infrastructure for embeddings and generation?

Hints

Hint 1

Separate your architecture into two independent pipelines: one that runs continuously to process documents, and one that handles real-time user requests with strict latency requirements.

Hint 2

Retrieval based only on semantic similarity often misses exact matches like error codes or product names; consider combining multiple search strategies.

Hint 3

The model needs clear instructions about when it should refuse to answer, and you may need a separate verification step to ensure responses actually match the provided context.