System Design Lab
A RAG system is two pipelines — offline ingestion and an online retrieve-then-generate query path — and each force scales a different stage.
Change query rate, corpus size, chunk size, how many chunks you retrieve, the model context window, and embedding dimensions, then toggle reranking and hybrid search. The design moves from stuffing the prompt to a vector index with ANN retrieval, to chunking and reranking, to hybrid search plus caching, and finally a multi-tenant, continuously-ingesting platform.
Guided walkthrough
Reason about it one step at a time
Takeaway
Normal evolution scenarios
Click left to right for the intended demo path. Each card changes the workload inputs.
Recommended shape
Bottlenecks
Why this changes
Decision tradeoffs
Source-backed rules
These are the durable system-design claims behind the model. The exact slider thresholds are deliberately labeled as teaching assumptions.
RAG conditions generation on retrieved passages instead of memorised weights
The original RAG paper retrieves relevant passages with a dense retriever and feeds them to a seq2seq generator, separating knowledge (the index) from the parametric model.
Lewis et al., 2020 (arXiv:2005.11401)Billion-scale similarity search needs an ANN index, not brute force
FAISS provides quantised and graph-based indexes so nearest-neighbour search over very large vector sets stays fast and memory-feasible.
FAISSHNSW gives logarithmic-time approximate nearest-neighbour search
Hierarchical Navigable Small World graphs trade a tunable recall/latency knob for high-recall search that scales to large indexes, the default in most vector databases.
Malkov & Yashunin, 2016 (arXiv:1603.09320)Vector databases manage embeddings, metadata filtering, and updates
A production vector store handles index building, upserts for freshness, and metadata filters for multi-tenant isolation, beyond raw nearest-neighbour math.
pgvectorTeaching assumptions
- Average documents split into a few chunks; total vectors are documents times chunks-per-doc scaled by chunk size.
- Freshness is modeled as new/changed docs (a small daily share of the corpus) being embedded and upserted, not a full-corpus re-embed; a tighter target forces a streaming pipeline.
- ANN, rerank, embedding, and generation per-node budgets are conservative teaching numbers, not vendor limits.
- Cache hit rate and recall are approximated; real systems tune HNSW parameters and rerankers empirically.