RAG Pipelines (in LlamaIndex)
This is where it all comes together. A RAG pipeline in LlamaIndex is the full path from raw documents to a grounded answer: load → parse → index → store → query. LlamaIndex gives you this in five lines for the simple case — then lets you swap in better parsing, hybrid retrieval, and reranking without rewriting the pipeline.
💡 In one line: A LlamaIndex RAG pipeline runs load → parse → index → store → query, with each stage independently upgradable.
The Two Halves
Like any RAG system, a LlamaIndex pipeline has:
- Ingestion (offline) — load → parse into nodes → embed → store.
- Query (online) — question → retrieve → postprocess → synthesise → answer.
The index bridges them.
The Basic Pipeline
Five lines is the starting point, not the ceiling.
The Ingestion Pipeline
For production, IngestionPipeline makes ingestion explicit and reusable — a list of transformations applied to documents:
It also supports caching (skip re-processing unchanged docs) and document management (upserts via doc IDs, so re-running doesn't duplicate).
Upgrading Each Stage
The point of the abstraction: improve one stage without touching the rest.
| Stage | Upgrade with |
|---|---|
| Loading | LlamaParse for messy PDFs/tables |
| Parsing | Sentence-window, semantic, or hierarchical parsers |
| Indexing | A real vector store; hybrid-capable stores |
| Retrieval | Hybrid search, higher top_k, metadata filters |
| Postprocess | Rerankers (Cohere, ColBERT, BGE) |
| Synthesis | Response modes (compact / refine / tree) |
Advanced Pipelines
Beyond the basics — patterns you've met in the RAG topic, available here as first-class features:
- Sentence-window retrieval — small match, wider context returned.
- Auto-merging / hierarchical — merge child nodes into parents.
- Sub-question decomposition — split a complex question.
- Recursive retrieval — follow node references.
- Router / agentic RAG — query engines as tools an agent chooses.
Workflows (the Modern Path)
For anything non-trivial, LlamaIndex recommends Workflows — event-driven step composition with branching, loops, and parallelism. (Query Pipelines are deprecated in favour of it, and query engines are themselves Workflows under the hood.)
Evaluation
Measure both halves: retrieval (hit rate, MRR) and response (faithfulness, relevancy). LlamaIndex ships evaluators — FaithfulnessEvaluator, RelevancyEvaluator — and integrates with RAGAS.
Production Concerns
- Persist the index; cache ingestion.
- Manage updates with doc-ID upserts — don't rebuild blindly.
- Watch embedding cost on large corpora.
- Add observability (Langfuse, Phoenix, or LlamaCloud).
Best Practices
- Start with the 5-line default, then measure.
- Fix retrieval first — better parsing, chunking, and reranking beat prompt-tweaking.
- Use LlamaParse for messy documents.
- Persist and cache; evaluate before and after each change.
Summary
- A LlamaIndex RAG pipeline runs load → parse → index → store → query.
IngestionPipelinemakes ingestion explicit, with caching and upserts.- Each stage is independently upgradable — parser, retriever, reranker, synthesiser.
- Advanced patterns (sentence-window, auto-merging, sub-question, agentic RAG) are first-class.
- Use Workflows for non-trivial apps, and evaluate retrieval and response.