← Back to insightsAI engineering · 9 min read

How RAG Pipelines Work: A Practical Guide to Production RAG

A clear walk through each stage of a RAG pipeline, with the decisions that decide whether answers are grounded or made up.

5 April 2025By CSharpTek Team
Knowledge cards connected through a retrieval layer to a cited answer.

Retrieval-augmented generation, or RAG, lets a language model answer using your own documents instead of only what it learned in training. The idea is simple. Making it reliable at scale is not.

This guide walks through each stage of a RAG pipeline, explains the decisions that matter, and points out where most systems go wrong.

What RAG does

A language model does not know your contracts, policies, tickets or product data. RAG fixes that by retrieving the relevant passages at question time and putting them in the prompt, so the model answers from that evidence. Good RAG returns an answer plus the sources it used, so a person can check it.

The pipeline, stage by stage

1. Ingestion

Content comes from files, databases, SharePoint, wikis, tickets or APIs. Ingestion extracts clean text, handles tables and scanned pages, and records metadata such as source, date, owner and access rules. Poor extraction quietly caps the quality of everything after it.

2. Chunking

Documents are split into passages small enough to retrieve precisely but large enough to carry meaning. Splitting on headings and paragraphs usually beats fixed character counts. Adding the document title and section heading to each chunk helps retrieval, and overlapping chunks can preserve context across boundaries.

3. Embeddings and indexing

Each chunk is converted to a vector with an embedding model and stored in a vector index, together with its metadata. Choose an embedding model that fits your languages and domain, and plan for re-indexing when you change it. Keep the original text alongside the vector so you can show citations.

4. Retrieval

At question time the system finds candidate chunks. Pure vector search handles meaning but can miss exact terms such as product codes or names. Keyword search handles exact terms but misses paraphrases. Hybrid search combines both and is usually the better default. Metadata filters narrow results to the right customer, product or date range.

5. Re-ranking

A second model scores the retrieved candidates against the question and reorders them. This often gives the largest quality gain for the least effort, because it fixes cases where the right passage was retrieved but ranked low.

6. Generation with citations

The prompt includes the best passages and instructs the model to answer only from them, to cite sources and to say when the answer is not in the material. The system returns the answer with links to the passages, which builds trust and makes errors easy to find.

7. Evaluation and monitoring

Build a test set of real questions with expected answers or expected source passages. Measure whether retrieval finds the right passage and whether the answer is faithful to it. Run these tests every time you change chunking, models or prompts, and log live questions that users mark unhelpful.

Where RAG systems go wrong

  • Bad extraction: tables and scanned documents become garbage text.
  • Chunks that are too large, too small or cut mid-thought.
  • No hybrid search, so exact terms are missed.
  • No access control, so users can retrieve documents they should not see.
  • No evaluation, so changes quietly make answers worse.
  • Answers without citations, so errors go unnoticed.
  • Stale indexes that do not update when source documents change.

Permissions: the part prototypes skip

In a company, not everyone may read every document. A production RAG system must apply the same access rules as the source system at retrieval time, filtering results by the user’s identity and groups. This is often the hardest requirement and the one most demos ignore.

Agents and RAG

Simple RAG answers one question from one retrieval. Some tasks need several steps: search, read, search again, call a tool, then answer. Agentic RAG lets a model decide those steps. It can answer harder questions, but it adds cost, latency and failure modes, so it needs step limits, tracing and evaluation.

Building RAG on Azure

A common Azure setup uses Azure OpenAI for generation and embeddings, Azure AI Search for hybrid retrieval and re-ranking, Blob Storage for source files, and Microsoft Entra ID for identity. The same architecture can be built with other providers, and the design decisions above matter more than the product names.

Checklist before you ship

  • Extraction tested on your real documents, including tables and scans
  • Chunking tuned and tested
  • Hybrid retrieval with re-ranking
  • Permission filtering at query time
  • Citations in every answer
  • An evaluation set that runs on each change
  • Index refresh when documents change
  • Logging of questions, retrieved passages and answers

Chunking in practice

Imagine a 60-page policy document. A fixed split every 1,000 characters will cut sentences and separate a rule from its exception. Splitting by heading keeps each rule with its context. Prepending “Travel policy > Expenses > Meals” to each chunk helps the search find it when someone asks about meal allowances. Tables deserve special care: converting a table to rows with column names, instead of loose text, keeps the numbers attached to their labels.

How to evaluate a RAG system

Evaluation has two parts. Retrieval evaluation asks whether the right passage appears in the top results for each test question, often reported as recall at a given number of results. Answer evaluation asks whether the answer is correct, whether it is supported by the retrieved passages, and whether it answers the question that was asked. Start with 50 to 100 real questions. Write the expected source for each. Review failures by hand, because they point to the stage that needs work: extraction, chunking, retrieval, ranking or prompting.

Cost and latency levers

  • Retrieve fewer, better passages after re-ranking instead of sending many
  • Use a smaller model for simple questions and a larger one for hard ones
  • Cache answers to repeated questions and repeated retrievals
  • Stream the answer so users see progress
  • Run retrieval steps in parallel where possible

RAG or fine-tuning?

Fine-tuning changes how a model behaves or writes. RAG gives a model facts it does not have. For company knowledge that changes, RAG is almost always the better first choice: you update documents, not the model, and you can show sources. Fine-tuning can help with tone, format or a narrow repeated task, and it can be combined with RAG.

Questions to ask before building

  • Who will use it and what do they ask?
  • Which sources are authoritative, and how often do they change?
  • Who may see which documents?
  • What happens when the answer is not in the documents?
  • How will we know whether quality is improving?

Planning a RAG system or fixing one that gives weak answers? We build and review RAG pipelines on Azure.

Discuss your initiative
CCSharpTek TeamAI Engineering Team
From insight to implementation

Explore the engineering behind this topic.

Explore the related solution area, then see how our team has applied this work in practice.

RAG Development
Related proof

Relevant engineering stories

See how related product and engineering challenges have been approached.

Keep exploring

More from Csharptek