Every piece covered so far, wired into one runnable script — from raw files to a grounded, cited answer
Every page so far has shown one piece of the pipeline in isolation — a loader snippet here, a splitter snippet there. This page exists to remove any doubt about how those pieces actually connect: one script, start to finish, that a naive-but-correct RAG system genuinely looks like. Everything past this page (advanced retrieval, search types, evaluation, production concerns) is an improvement layered on top of exactly this script, not a different architecture.
Everything above this line runs once (or on a schedule, per Production Concerns → incremental indexing) — it builds the index. Everything below runs on every single user question.
This is the same flow traced with concrete numbers in RAG Pipeline Overview — this page just makes it copy-pasteable.
Nothing about the shape of this script changes as the system matures — every improvement below replaces one line, not the architecture:
DirectoryLoader(..., loader_cls=TextLoader) becomes a mix of format-specific loaders once real PDFs, HTML, and database rows enter the corpus — see Document Loaderschunk_size=500 stops being a guess and becomes a value chosen by testing candidates against a labeled eval set — see Text Splitters → picking chunk size and Evaluationvectorstore.as_retriever(search_kwargs={"k": 5}) becomes search_type="mmr" once duplicate results are observed, or gets wrapped in an EnsembleRetriever once exact-keyword misses are observed — see Advanced Retrieval and Search TypesContextualCompressionRetriever with a cross-encoder once retrieval precision is the bottleneck, not just recall — see Advanced Retrieval → Rerankingfilter={} gets added to every vector search call once more than one tenant or permission level exists — see Production Concerns → access controlanswer() gets wrapped in tracing (so every retrieved chunk and generated answer is logged) before it ever serves real traffic — see Evaluation → toolingNone of these changes require touching the loader→splitter→embed→store→retrieve→augment→generate shape above — they tune or replace individual stages within it, which is exactly the point of learning the pipeline stage by stage rather than as one opaque block.