SproutStackSproutStack home

Building a Production RAG Pipeline

5 min readBeginner-friendlyFree to read

Read a little, play a little. No scary maths, and no rush.

Share:

From demo to dependable

The 20-line demo retrieves something and answers something. Production means answering correctly, citing sources, surviving weird queries, and proving it with numbers. This chapter is the full pipeline checklist — every stage you'd build, in order, with the decision each one hides.

Ingest: parsing and chunking

Real documents arrive as PDFs with tables, HTML with navbars, Confluence exports with macros. Each format needs parsing that extracts content while dropping chrome — and tables/code often need special handling (keep whole, never slice mid-row). Then chunk by headings at 300–800 tokens with 10–20% overlap, attaching metadata (source, section, page, updated). Chunking quality decides retrieval quality more than any embedding model choice.

Retrieve: better than plain vectors

  • Query rewriting: vague user questions ("it broke again") get expanded into precise retrieval queries, sometimes multiple angles.
  • Hybrid retrieval: BM25 keywords catch exact codes and names (ERR-4041) that vectors blur past; vectors catch meaning. Fuse both.
  • Reranking: cheap bi-encoder recalls 50, precise cross-encoder reranks to top-5. Precision where it counts, speed where it matters.

Generate: grounded and cited

The prompt carries numbered chunks with a strict contract: answer only from context, cite every claim ([2]), say NOT FOUND otherwise. Parse the output, validate citations point at real chunks (yes, models fake those too), and log the full trace — query, retrieved IDs, prompt version — for every answer.

Evaluate and operate

The 50-question golden set from Evals Basics runs on every change: faithfulness, recall@K, abstain precision, cost/latency. Updates are surgical (re-embed changed chunks only), rollouts canary, and dashboards watch quality drift — not just uptime. See /animations/rag-pipeline for the flow in motion.

Before and after: an internal docs assistant

Version 1 used vectors only. It handled "how do I rotate an API key?" well, but questions mentioning ERR-4041 kept returning a page about a different error, because the two codes look almost identical to an embedding. Adding keyword search fixed those in one change. A reranker then moved the right chunk into the top three far more often, so answers improved without raising top-K. Citation validation caught the model occasionally citing [6] when only five chunks existed. Each fix targeted one failure seen in the eval set, which is why each one could be confirmed rather than hoped for.

Freshness and deletions

Adding new documents is the easy direction. Removal is the one teams forget: when a page is deleted or a policy is withdrawn, every chunk from it must leave the index, or the assistant keeps quoting rules that no longer exist. Store a document ID and version on every chunk, delete by ID whenever a source changes, and periodically compare the index against the source system to find orphans.

Access control belongs in retrieval

If some documents are restricted to certain teams, filter them out at retrieval time using permission metadata on each chunk. Never retrieve everything and instruct the model to hide what the user may not see. A model can be talked into revealing text that is in its context, but it cannot reveal text that was never retrieved.

Remember this

  • Parse → chunk → embed → hybrid retrieve → rerank → cite → eval. Skip a stage, inherit its failure mode.
  • Metadata and evals are the unglamorous 80% that make RAG trustworthy.

Check your understanding

5 questions · first-try answers earn the most XP

1. Why does the chapter say chunking quality matters more than the embedding model you pick?
2. Why parse PDFs and HTML carefully before chunking?
3. Why does a RAG pipeline rerank 50 retrieved candidates down to a handful?
4. Why validate that citations point at real chunks?
5. Why attach metadata such as source, section and updated date to every chunk?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Practice this in an incident

End of Embeddings, Vector Search & RAG

Take the section checkpoint

A short mixed quiz on all 6 chapters, to check you are ready to move on.

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.