A RAG pipeline is two paths and a test set.
A retrieval-augmented generation pipeline has an indexing path (load, chunk, embed, store) that runs when documents change, and a query path (rewrite, retrieve, re-rank, gate, generate, cite) that runs per question. Each stage is replaceable and measurable. Deploy it as a small API, FastAPI in Python is the usual choice, with streaming answers and logs that feed your evaluation set.
- Indexing path
- Load, chunk, embed, store, keyword index
- Query path
- Rewrite, retrieve, fuse, re-rank, gate, generate, cite
- Deploy as
- FastAPI with streaming, behind a gateway
- I built
- RAG.NextUpgrad, this architecture in production
- 5production AI apps
- 14engineers led
- 200+students mentored
Questions students ask
The RAG pipeline questions searched most, answered from a pipeline that runs in production.
How do RAG pipelines work?
Two flows share one index. When documents arrive or change, the indexing flow reads them, splits them into chunks, turns each chunk into an embedding, and stores vector, text and metadata in a vector store, with a keyword index alongside. When a question arrives, the query flow embeds it, retrieves candidate chunks from both indexes, fuses and re-ranks them, checks that the evidence is strong enough, and prompts a language model to answer from those chunks with citations, streaming the result. Logging on the query flow produces the questions you use to evaluate and improve both flows.
What is RAG pipeline architecture?
The architecture is a set of stages with clear interfaces so each can be swapped and measured. Ingestion: loaders per source type, a parser that keeps structure, a chunker, an embedding model, a vector store and a keyword index, plus a scheduler for re-indexing. Serving: an API that accepts a question and conversation, a query rewriter, a hybrid retriever, a re-ranker, a confidence gate, a prompt builder, a model client with streaming, a citation resolver, and a logger. Around both: an evaluation harness with a labelled question set that runs in CI. RAG.NextUpgrad is built this way, and the stage boundaries are what made it possible to improve retrieval without touching generation.
What are the components of RAG pipeline?
- Loaders: read PDFs, HTML, Markdown, databases, APIs into documents with metadata.
- Chunker: split by structure at a few hundred tokens with overlap; attach title, section, page, date.
- Embedding model: one fixed model for documents and queries.
- Vector store and keyword index: pgvector or Qdrant plus BM25 or full-text search.
- Retriever: hybrid query with reciprocal-rank fusion and metadata filters.
- Re-ranker: a cross-encoder over the top twenty.
- Confidence gate: a score threshold that decides answer or decline.
- Generator: a language model with a prompt that enforces answering from passages and citing them.
- Citation resolver and streamer: markers mapped back to passages, sent as server-sent events.
- Evaluation harness and logs: recall at k, faithfulness, latency, cost, on every change.
What is indexing in RAG pipeline?
Indexing is everything that happens to documents before any question is asked: parsing them into clean text with structure, chunking, embedding, and writing to the stores. It runs once per document and again whenever a document changes, so it needs to be idempotent (re-indexing a file replaces its old chunks rather than duplicating them) and incremental (only changed files are processed). Indexing decisions set the ceiling on answer quality because retrieval can only return what indexing preserved. Keep an index version in metadata so you can re-index with a new chunker or embedding model and compare the two versions on your test set.
What is embedding in RAG pipeline?
Embedding is the step that turns each chunk, and later each question, into a vector so that similarity can be computed. The same embedding model must be used on both sides; a change of model means re-embedding the whole corpus. Choose it for your language and chunk length, run it in batches at index time, and cache query embeddings for repeated questions. Embedding is the part of the pipeline most people over-think and chunking the part they under-think: a better embedding model lifts retrieval a little, a better chunker lifts it a lot. Measure both on your question set.
How to design RAG pipeline
Start from the questions, not the documents. Collect fifty to a hundred real questions and the passages that answer them; that set is the specification and the test. Then design backwards: which documents hold those passages, what structure they have (and therefore how to chunk), which terms are exact (and therefore need keyword search), what metadata filters users will need, how fresh the index must be, and what should happen when nothing answers the question. Decide the stage interfaces, build the simplest version of each, and run the test set. Improve the stage with the worst numbers. Most of the design effort should go into retrieval; the model is the easy part.
How to create RAG pipeline
In plain Python: a loader (pypdf or a layout parser, BeautifulSoup for HTML), a structure-aware chunker, an open embedding model from sentence-transformers, pgvector or FAISS for vectors, rank_bm25 or Postgres full-text for keywords, a fusion function, a cross-encoder re-ranker, a prompt template, and a model client with streaming. Wire indexing as a script and querying as a function that returns passages, scores and the streamed answer. Add the test harness in the same repository. Frameworks such as LangChain and LlamaIndex can assemble the same thing faster; I recommend the plain version first so you know what each stage does when you need to debug it.
How to deploy RAG pipeline
Wrap the query function in a FastAPI service with an endpoint that accepts the question and conversation, runs retrieval, and returns a streaming response of server-sent events carrying tokens and citation markers. Run indexing as a separate worker or scheduled job so heavy re-indexing never blocks queries. Put Postgres with pgvector (or Qdrant) and Redis for caching next to it. Containerise, add a gateway for keys and rate limits, log every question with its retrieved passages and scores, and ship the evaluation harness as a CI job that fails on regression. Watch latency at each stage; retrieval and re-ranking should stay well under a second before generation starts.
How to make RAG chatbot
A chatbot adds conversation to the pipeline. Keep recent turns, and before retrieval rewrite the latest message into a standalone question using that history, so 'what about refunds?' becomes 'what is the refund policy for damaged items' with the subject recovered. Retrieve for the rewritten question, answer with citations, and keep the retrieved passages in the turn's record so follow-ups can refer to them. Show sources in the interface and provide a way to report a wrong answer; those reports become test cases. Decline politely when the gate says the documents do not cover the question, and suggest the nearest topics instead of guessing.
What are RAG projects?
- A course or textbook assistant that answers from lecture notes with page citations.
- A documentation bot for an open-source project, indexed from its docs and issues.
- A support assistant over a product manual and past tickets, with a decline path.
- A research reading tool that answers across a folder of papers and shows the passages.
- A policy assistant for a college or company handbook, with per-section citations.
- A code-aware assistant over one repository, chunked by function with file paths in metadata.
- Each is a weekend to prototype and a month to make trustworthy; the month is the test set, the gate and the citations.
From notebook to service
The build order that avoids rework.
- 01
Questions first
Fifty labelled questions before any code. They are the spec and the test.
- 02
Indexing script
Load, chunk by structure, embed, store in pgvector, build BM25. Idempotent per document.
- 03
Query function
Rewrite, hybrid retrieve, fuse, re-rank, gate, generate with citations. Measure recall at five.
- 04
FastAPI and CI
Streaming endpoint, logs, a worker for re-indexing, the test set in CI.
In the room
Where these systems get explained to students.


Read next
Each stage in depth.
A RAG pipeline that is measured, not hoped?
I design, build and deploy them with the test set in CI. Let's scope yours.

