EN 中文

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

Normal evolution scenarios

Click left to right for the intended demo path. Each card changes the workload inputs.

Workload

These are inputs, not preset architecture stages.

Recommended shape

Current architecture path
Retrieval-augmented generation architecture diagram Whiteboard-style architecture diagram for a RAG system: clients, a RAG API, a retrieval stage embedding the query and searching a vector index, a rerank and context-assembly stage, LLM generation with a response cache, and an asynchronous ingestion pipeline that chunks and embeds documents. Clients RAG API Retrieval Rerank + assemble Generation Ingestion Client asks questions RAG API orchestrates query Response cache repeat queries Query embedder text to vector Vector index ANN top-k Keyword index BM25 matches Reranker cross-encoder Context assembler fit window LLM generator grounded answer Chunk + embed async pipeline Index writer upsert vectors
Clients
Client sends natural-language questions and renders grounded answers
RAG API
RAG API orchestrates embed, retrieve, rerank, assemble, and generate per query
Response cache returns cached answers for repeated or similar questions before any retrieval
Retrieval
Query embedder embeds the question with the same model used at ingestion
Vector index approximate-nearest-neighbour search returns the top-k candidate chunks
Keyword index inverted index that catches exact terms dense vectors miss, for hybrid search
Rerank + assemble
Reranker reorders candidates by query-chunk relevance before they enter the context
Context assembler packs the best chunks plus the prompt to fit within the context window
Generation
LLM generator generates the answer conditioned on the assembled context
Ingestion
Chunk + embed splits new documents into chunks and embeds them off the query path
Index writer upserts chunk vectors into the index to keep retrieval fresh

Bottlenecks

Vector index scale

ANN query load

Rerank load

Context window fit

Ingestion / freshness

Why this changes

    Decision tradeoffs

    Chunking strategy

    Vector index / ANN

    Hybrid search

    Reranking

    Context assembly

    Ingestion / freshness

    Source-backed rules

    These are the durable system-design claims behind the model. The exact slider thresholds are deliberately labeled as teaching assumptions.

    Verified rule

    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)
    Verified rule

    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.

    FAISS
    Verified rule

    HNSW 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)
    Verified rule

    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.

    pgvector

    Teaching 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.