Home>Blogs>What Is a RAG Pipeline? 7 Stages Explained With an Example

What Is a RAG Pipeline? 7 Stages Explained With an Example

What Is a RAG Pipeline? 7 Stages Explained With an Example

What Is a RAG Pipeline? 7 Stages Explained With an Example

A RAG pipeline is the workflow that retrieves relevant information from approved external sources and supplies that evidence to a large language model before it answers. For enterprises, RAG makes AI more useful for current, private, and domain-specific knowledge while improving source traceability without requiring the model to memorize every document.

The pattern comes from retrieval-augmented generation research. Lewis et al.'s original RAG paper combined language-model memory with retrieved external knowledge, while Microsoft Learn describes modern RAG as grounding model responses in retrieved content.

For this guide, stages 1–4 are indexing and stages 5–7 are query-time processing. This is a practical teaching model, not a universal standard.

RAG Pipeline at a Glance

StageInputOutput
Stage 1: Ingest and cleanDocuments, databases, APIsNormalized source content
Stage 2: Chunk and add metadataClean documentsSearchable passages with source and access metadata
Stage 3: Generate embeddingsText chunksVector representations
Stage 4: Build the search indexChunks, vectors, metadataSearchable, filterable index
Stage 5: Process question and retrieveQuestion plus user identityAuthorized candidate passages
Stage 6: Rerank and assemble contextRetrieved candidatesOrdered evidence package
Stage 7: Generate grounded answerQuestion plus evidenceAnswer with sources, or an abstention

A Running RAG Example

Imagine an employee asks: “Can I take my company laptop on an international business trip?”

A fictional current policy, IT-TRAVEL-004 v3, says company laptops may leave the country only when manager approval is recorded in the IT portal at least five business days before travel and full-disk encryption is active.

The knowledge base also contains an older v2 policy and a restricted security document. A well-designed RAG pipeline should retrieve the current policy, exclude the superseded version, and prevent restricted content from reaching an unauthorized user's model context.

The 7 Stages of a RAG Pipeline

Stage 1: Ingest and Clean Source Data

RAG starts by connecting to approved sources such as PDFs, wikis, SharePoint libraries, databases, cloud storage, APIs, manuals, and enterprise applications.

The ingestion layer extracts usable content, removes duplicate or obsolete material, normalizes formatting, and records source identity, ownership, revision date, and classification. Scanned or layout-heavy documents may require OCR or layout-aware extraction.

LuMay's RAG development services include extraction, cleaning, normalization, deduplication, metadata enrichment, OCR, and document processing.

Stage 2: Chunk Documents and Attach Metadata

Large documents are divided into smaller passages so retrieval can return the section that actually answers a question. Good chunking preserves enough context for meaning without making each passage unnecessarily broad.

Microsoft's RAG chunking guidance recommends testing chunking strategies against real documents and queries.

For IT-TRAVEL-004 v3, the international-travel rule becomes a chunk tagged with source ID, section, version, effective date, owner, and access group. That metadata later supports filtering, freshness, permissions, and citations.

Stage 3: Generate Embeddings

An embedding model converts text into numerical vectors that represent semantic relationships. This helps retrieval find conceptually similar passages even when the user's wording differs from the source.

Document chunks can be embedded during indexing, and the user's question can be converted into a query embedding at runtime.

Embeddings are common, but not mandatory. Exact identifiers, names, and policy numbers may benefit from keyword search, and many enterprise systems combine keyword and vector signals.

Stage 4: Build the Search Index

The system stores chunks, metadata, and optional vectors in a searchable index.

A vector database is one implementation choice, not the definition of RAG. Retrieval can use keyword, vector, semantic, graph, relational, or hybrid search. Microsoft documents vector, keyword, and hybrid retrieval as options to test and tune for the workload.

Production indexes should make fields such as source, version, department, date, and access level filterable. LuMay's AI integration services connect AI systems with enterprise data, applications, APIs, and workflows.

Stage 5: Process the Question and Retrieve Authorized Content

At query time, the application interprets the question, may rewrite or expand it, creates a query embedding where appropriate, and searches the index.

Security must happen during retrieval. Permission filters should be applied before content reaches the LLM. Microsoft documents document-level access control for excluding content a caller is not authorized to see.

In our example, access filters remove the restricted security document, while version filters remove IT-TRAVEL-004 v2. The current v3 rule remains.

Stage 6: Rerank Results and Assemble Prompt Context

Initial retrieval often favors recall. A reranker can then reassess candidate passages and move the strongest evidence to the top.

Reranking is optional because it can improve precision but also add latency and cost. The application then assembles a compact context containing the question, selected evidence, source identifiers, and instructions for using that evidence.

Retrieved text should be treated as untrusted data. OWASP's prompt-injection guidance notes that RAG does not fully eliminate prompt-injection risk.

Stage 7: Generate an Evidence-Grounded Answer With Sources

The LLM receives the question plus selected evidence and generates an answer grounded in that context.

For the fictional example:

Yes, with two conditions. Your manager's approval must be recorded in the IT portal at least five business days before travel, and full-disk encryption must be active. Source: IT-TRAVEL-004 v3.

If the evidence does not answer the question, the system should abstain rather than invent a response. RAG reduces unsupported answers, but it cannot guarantee factual accuracy.

RAG vs. Search vs. Fine-Tuning

CapabilityOrdinary SearchRAGFine-Tuning
Primary goalFind documentsAnswer from retrieved evidenceChange model behavior
OutputLinks or ranked resultsNatural-language answer with sourcesResponses shaped by additional training
Knowledge updatesUpdate search corpusUpdate knowledge base and indexRetrain or further train
Best fitFinding informationCurrent, private, verifiable knowledgeStyle, format, specialized behavior

RAG builds on retrieval rather than replacing search. It can also complement fine-tuning when a system needs both current knowledge and specialized model behavior.

Common RAG Failures and Production Checks

FailureProduction Check
Stale contentVersion filters, refresh jobs, retired-source removal
Poor retrievalTest chunking, hybrid search, filters, query rewriting, reranking
Permission leaksApply identity-aware filters inside retrieval
Prompt injectionIsolate retrieved content, limit tools, validate outputs
Unsupported answersUse groundedness checks and abstention rules
Citation errorsValidate every source against retrieved context

How to Evaluate and Monitor a RAG Pipeline

Measure the pipeline stage by stage rather than judging only whether the final answer sounds good.

Track:

  • Retrieval relevance: Did the system retrieve the right passages?
  • Groundedness: Is the answer supported by the retrieved evidence?
  • Citation accuracy: Do references substantiate the associated claims?
  • Permissions: Can users retrieve only authorized content?
  • Latency: How long do embedding, search, reranking, and generation take?
  • Cost: What does each query cost across the pipeline?

Microsoft Foundry includes RAG evaluators for retrieval, groundedness, and relevance. LuMay's RAG offering also covers retrieval relevance, groundedness, citation accuracy, latency, cost, index refreshes, monitoring, and optimization.

Build a Production RAG Pipeline With LuMay

LuMay's RAG development services cover enterprise knowledge integration, document preparation, embeddings and vector implementations, custom retrieval, LLM integration, evaluation, deployment, and ongoing optimization.

These capabilities are supported by broader AI engineering and integration services for connecting models to enterprise systems and workflows.

If you are planning an enterprise knowledge assistant, internal search experience, or RAG-enabled application, book a LuMay consultation to review data readiness, retrieval architecture, permissions, evaluation, and production deployment.

Tags:

#RAG

Frequently Asked Questions

Everything you need to know about Engineering Services

1. What is a RAG pipeline in simple terms?

It finds relevant information in approved sources and gives that evidence to an LLM so the model can answer from current data.

2. Does RAG retrain the LLM?

No. Most RAG systems retrieve knowledge at query time; updating the index usually updates what the application can use.

3. Does every RAG system need a vector database?

No. Keyword, hybrid, relational, graph, and other retrieval methods can also support RAG.

4. Why are documents chunked?

Chunking lets retrieval return focused passages instead of entire documents, improving relevance and controlling context size.

5. Is reranking required?

No. It is an optional second scoring step used when the quality gain justifies added latency and cost.

6. Where should permissions be enforced?

During retrieval, before content reaches the model.

7. Can RAG eliminate hallucinations?

No. It reduces risk by supplying evidence, but retrieval and generation can still fail.

8. What happens when evidence is insufficient?

The application should abstain, ask for clarification, or direct the user to an appropriate source owner.

9. How is RAG different from enterprise search?

Search finds and ranks information; RAG retrieves information and uses it as evidence for a generated answer.

10. What should teams monitor first?

Start with retrieval relevance, groundedness, citation accuracy, permissions, latency, and cost.

About the Editorial Team

Sarath Babu

Sarath Babu

Content Writer and SEO Specialist at Lumay

Creates insightful content on SEO, AI-powered marketing, digital growth, and emerging technologies. He simplifies complex topics into practical, research-backed guidance.

Palanisamy

Palanisamy

CEO and Founder at LuMay

27+ years of experience leading enterprise-scale AI, data, and systems architecture initiatives, delivering mission-critical platforms with a strong emphasis on trust, governance, and reliability.