KatInterview

Design a Documentation Q&A System Using LLM APIs

Machine LearningModel answer
MediumModel answerMachine Learningretrieval-augmented-generationembeddingsllm-orchestration

Last updated

Build a retrieval-augmented generation system that answers developer questions from internal documentation using embeddings and language model APIs.

Problem Context

You're tasked with building an intelligent assistant for your engineering team. Developers need quick answers to questions about APIs, architecture decisions, and operational procedures. The knowledge lives in hundreds of thousands of documents that change daily.

Your system will use language model APIs for embeddings and text generation to retrieve relevant information and synthesize accurate answers with proper citations.

System Goals

Build a question-answering system that:

  • Processes a large corpus of technical documentation (Markdown and HTML files with metadata like authors, services, and timestamps)
  • Maintains a searchable index that stays current as documents change
  • Answers both single questions and follow-up conversations
  • Cites sources for every claim
  • Can optionally call a service health API when users ask about current system status
  • Refuses to answer questions outside its knowledge base or fabricate information

Scale Parameters

  • Documentation corpus: 500,000 documents, ~1,500 tokens each (~750 million tokens total)
  • Update rate: ~5,000 document changes daily
  • Query volume: Peak of 20 requests per second
  • Latency target: 95th percentile response time under 1.5 seconds
  • Availability: 99.9% uptime required

Design Scope

Your solution should address:

  1. Document processing: How you'll split documents into searchable units, handle mixed text and code, and keep the index fresh as documents change

  2. Search architecture: Your approach to finding relevant content quickly, including embedding strategy, search algorithms, and ranking methods

  3. Answer generation flow: How the system decides what information to use, when to call external APIs, how it structures prompts, and how it manages the generation context

  4. Performance optimization: Strategies to meet latency targets and control costs while handling peak load

  5. Quality assurance: How you'll measure answer quality, prevent hallucinations, and protect against malicious content in indexed documents

Hints

Hint 1

Consider how document structure (headings, code blocks) should influence your chunking strategy

Hint 2

Combining multiple search methods often outperforms any single approach

Hint 3

The language model's context window is limited - think about what information is essential versus nice-to-have

Hint 4

Caching can dramatically reduce both latency and cost, but requires careful invalidation logic