Width.ai

LlamaIndex vs LangChain for RAG: Which to Use, and How to Evaluate the Result

Matt Payne
·
October 27, 2026

Choosing LlamaIndex vs LangChain for RAG usually starts after rapid prototyping, once a demo works. The prototype answers the twenty test prompts someone tried, and everyone is happy. Then production brings the thousand questions nobody tried, and many teams start asking whether they picked the wrong framework.

The two frameworks are built around different problems. LlamaIndex is built around your data: parsing documents, indexing data and retrieving the right piece of it. LangChain, with LangGraph underneath, is built around the agent's control flow: what it does next, what it remembers and when a person has to approve.

The short answer: use LlamaIndex if data ingestion and retrieval are the hard part, LangChain with LangGraph if multi-step, stateful agent behavior is, and both if you need both. Either way, the right choice is whichever scores best on a golden dataset built from your own documents.

We build RAG applications on LangGraph when it fits and on neither framework when it does not. Each framework wins some factors outright, and an evaluation on your own corpus settles the rest.

Key Takeaways

  • LlamaIndex leads on ingestion, parsing and retrieval primitives; LangChain with LangGraph leads on state management, interrupts and human approval.
  • For a standard RAG pipeline the overlap is large: same models, vector stores, hybrid search, rerankers and MCP tools.
  • Both ship evaluators, and neither replaces a golden dataset labeled from your own documents.
  • Measure recall twice, on raw retrieval and on the final context, so you know whether search or reranking lost the evidence.
  • Run the same evaluation on each candidate stack, including a thin custom pipeline, and let the numbers pick.

LlamaIndex vs LangChain for RAG: How They Compare at a Glance

  
    ✂️ The short answer    

LlamaIndex vs LangChain for RAG: which should you use?

    

Use LlamaIndex when ingestion and retrieval are the hard part of your RAG system: messy documents, many formats and advanced retrieval. Use LangChain with LangGraph when the hard part is a multi-step, stateful agent with human approval. Use both when you need both, a hybrid pattern LangChain's own comparison describes. Either way, the right choice is the one that scores best on a golden dataset built from your own documents.

  

‍

‍

  

LlamaIndex vs LangChain for RAG

  

How the two frameworks compare for RAG

  
                                                                                
FactorLlamaIndexLangChain + LangGraph
Best primary use in RAGIngestion, parsing, indexing and retrievalAgent loops, state and multi-step control flow
Ingestion and parsingLlamaParse (130+ file formats, paid) and 158 reader packagesDocument loaders and text splitters across 1,000+ integrations
Retrieval primitivesBM25, hybrid fusion, recursive, auto-merging, sub-question and router enginesRetrievers, hybrid search through vector stores, rerankers
Agent loop and stateWorkflows: event-driven; checkpointing is DIY or via a pluginLangGraph: checkpointers (when configured), durable execution, time travel
Human-in-the-loopInput and response events in Workflowsinterrupt() and resume, plus built-in middleware
Built-in evaluationFaithfulness, relevancy, correctness evaluators; MRR and hit rateLangSmith judges for correctness, relevance, groundedness, retrieval relevance
TracingShort setup integrations for Phoenix, Langfuse, W&B Weave, OpenTelemetryLangSmith, framework-agnostic; also OpenTelemetry tools
Managed offeringLlamaCloud and LlamaParse, credit-basedLangSmith tracing and LangSmith Deployment
License and languagesMIT; Python (the TypeScript port was archived in April 2026)MIT; Python and TypeScript
  
  

If the hard part is getting the right evidence out of your documents, LlamaIndex leads. If the hard part is controlling what the agent does with it, LangGraph leads.

The takeaway

If the hard part is getting the right evidence out of your documents, LlamaIndex leads. If the hard part is controlling what the agent does with that evidence, LangGraph leads. If you cannot tell which part is hard, you need the evaluation in Factor 4 before you need a framework.

LangChain's own comparison of LangChain and LlamaIndex reaches a similar split. It recommends LlamaIndex for data-heavy applications and LangChain or LangGraph for orchestration-heavy agents, and it describes wrapping LlamaIndex query engines as tools that LangGraph nodes call.

What Is LlamaIndex in the Context of RAG?

llamaindex vs langchain for reag

LlamaIndex is an open-source Python framework that connects large language models to your data sources. In a retrieval augmented generation (RAG) system, it handles the first half of the work. It loads documents, splits them into nodes, builds data structures called indexes and finds the right nodes for each question.

Ingestion and parsing: LlamaParse, the commercial parser, handles more than 130 file formats, and the open framework has 158 reader packages, its data connectors for sources such as PDFs, databases and SaaS tools.

Indexes and query engines: index types such as vector, summary and keyword, with query engines that sit on top and turn retrieved nodes into an answer.

Advanced retrieval: BM25, hybrid fusion, recursive retrieval, auto-merging retrieval, sub-question decomposition and routers that pick an index per question across multiple data sources.

Workflows: an event-driven way to build agentic RAG, with steps that emit and consume events.

The project, which started as GPT Index, has shifted toward documents. Its GitHub repository now calls LlamaIndex the document processing platform for AI and says the primary focus has moved to LlamaParse. The open framework remains available under the MIT license, but the TypeScript version was archived in April 2026, so LlamaIndex is now a Python-first choice.

What Is LangChain (and LangGraph) in the Context of RAG?

LangChain is an open-source framework for building AI applications and agents on language models, in Python and TypeScript. LangGraph is the runtime underneath it. It is built for production agents that run for many steps, handle memory management and pause for people.

Both reached version 1.0 in October 2025. In the LangChain and LangGraph 1.0 release, create_agent became the standard way to build an agent on the LangGraph runtime, with built-in middleware for human-in-the-loop approval, summarization and PII redaction. LangChain also committed to no breaking changes until 2.0.

new create_agent function in LangChain uses underlying LangGraph

‍

Integrations: the LangChain ecosystem has more than 1,000 integrations across chat models, embedding models, vector stores, document loaders and tools.

Durable agents: LangGraph checkpointers save state at every step, so an agent can pause, resume, recover from a crash or replay an earlier state.

Human approval: an interrupt pauses the graph until a person responds, then resumes from the same point.

LangSmith: tracing, datasets and evaluation that work with or without LangChain.

‍

Where LlamaIndex and LangChain Are the Same

For a standard RAG pipeline, both LangChain and LlamaIndex overlap more than their reputations suggest.

  • Same models and stores: both wrap the same LLM providers, embedding models and vector databases, so neither locks you into a model.
  • Same retrieval capabilities: both support vector search, BM25, hybrid search and rerankers.
  • Same agent building blocks: both support tool-calling agents, tools for web search engines, structured output and MCP tools.
  • Same evaluation partners: both trace into Arize Phoenix, Langfuse and OpenTelemetry, and both work with Ragas and similar suites.
  • Same business model: an MIT-licensed open framework with a paid managed layer on top.

That overlap is why IBM's comparison needs one small correction. It says LangChain can combine search techniques, such as adding keyword search, which implies LlamaIndex cannot. LlamaIndex has a BM25 retriever and hybrid fusion of its own. I’ve used it in LlamaIndex countless times. 

The practical point is simple. If your RAG system is a single workflow, one search and one answer, either framework will do the job. The differences start to matter when the documents get messy or the agent runs complex workflows.

Decisive Factor 1: Ingestion, Parsing and Indexing

The parser decides what a RAG system can ever know. If a table comes out as one run of flattened text, no retriever can recover which number belonged to which label.

This is measurable: OHRBench tested OCR and parsing tools across seven domains and found that even the best solutions trailed perfectly extracted text by at least 14% end to end.

LlamaIndex treats this as its core job. LlamaParse supports more than 130 file formats, and the framework adds node parsers that keep document hierarchy, so a chunk can point back to its parent section.

LangChain supports most sources through document loaders and solid text splitters, and it works with any external parser you choose. It does not ship a layout-aware parser of its own.

Whichever you use, check extraction on your hardest documents first: tables, forms, checkboxes and scanned pages. Measure field-level accuracy on a sample before you tune anything downstream. I always run these eval on domains like medical, financial, and legal as I find those tables contain extremely relevant information in many RAG use cases. 

What to Test on Your Own Documents

Chunking comes right after parsing, and it can move recall a lot on its own. Fixed-size chunks cut wherever the token count says. A deposition answer gets split from its question, and a defined term gets split from its definition.

Chunk by structure instead: sections, clauses, table rows and question-and-answer pairs. Then match on small chunks and return the larger section they belong to, so the model sees all the relevant information.

Adding context to each chunk helps too. In Anthropic's Contextual Retrieval tests, contextual embeddings plus contextual BM25 cut retrieval failures by 49%, and adding a reranker raised that to 67%.

Both frameworks can do this. LlamaIndex has hierarchical node parsers that keep links to parent sections.

In LangChain you pair text splitters with the parent-document retriever. In version 1.x it lives in the legacy langchain-classic package, or you can build the lookup yourself. Test both on your hardest documents, because the winner here is the one that keeps your structure intact.

Winner: LlamaIndex

Its parsing and indexing tools are deeper. LangChain wins only if you already use a separate parser and need the loaders for other sources.

Decisive Factor 2: Retrieval Strategies

Both frameworks do vector search, BM25, hybrid search and reranking. LlamaIndex ships more retrieval patterns ready to use, so less of the data retrieval logic is code you write yourself.

Its auto-merging retriever returns the parent section when enough of its child chunks match, and its sub-question engine splits a comparison into separate lookups. Recursive retrieval follows references between nodes. In LangChain you can build the same patterns, but more of them are custom code you assemble.

Features are not the deciding factor here, though. In our agentic RAG architecture, retrieval recall is the foundation: if the evidence never reaches the model, nothing downstream can fix the answer. We fuse vector and keyword results with Reciprocal Rank Fusion at k = 60, so a document ranked fifth by both retrievers (2/65, about 0.031) outranks one ranked first by only one (1/61, about 0.016).

For files that change faster than they can be reindexed, we also let agents search with grep and glob. None of that depends on which framework wraps it.

So measure recall and retrieval quality, not feature lists. Statsig's comparison makes the same point: pull 30 to 50 real queries into a coverage set and measure precision and recall at k before choosing.

Hybrid Search and Reranking in Practice

Vector search fails in a predictable way on exact strings. Error codes, part numbers, SKUs and clause numbers look almost the same to an embedding model, so ERROR_4001 and ERROR_4002 can land side by side. Keyword search catches the exact match, which is why we run both and fuse the results.

Rerankers need the same care. A reranker rescores the top results with a stronger model and usually helps precision. It also adds roughly 300 to 2,000 milliseconds per query, and many limit input length, often to around 4,096 tokens.

It does not always help. In LegalBench-RAG, a general-purpose reranker slightly lowered scores. Measure recall before and after reranking on your own set, in whichever framework you use, and keep the reranker only if the number goes up.

Winner: LlamaIndex, narrowly

More retrieval patterns come ready to use. The margin closes once you measure recall on your own queries, because both can run the patterns that win.

Decisive Factor 3: Agent Orchestration, State and Human-in-the-Loop

Agentic RAG turns retrieval into a loop. A router sends easy user queries down a fast path, a planner breaks hard ones into steps, ReAct agents search and search again, a merge step deduplicates and fuses results, and a validation step checks the evidence before anything is answered.

Each block needs state that survives between steps. LangGraph's persistence layer saves a checkpoint of the graph's state at every step, which supports human approval, time travel through earlier states and recovery after a failure. Its interrupt function pauses the graph and waits for a person, then resumes with their answer.

LlamaIndex Workflows are event-driven and support human-in-the-loop events too. They can serialize their context and resume a run, but there is no built-in checkpointer to switch on. You snapshot state yourself or add a durability runtime such as DBOS. That gives granular control, but you design more of the state handling yourself.

This is the factor where we most often choose LangGraph. Our agentic e-commerce system for IPG runs roughly fourteen ReAct agent nodes on LangGraph, with a strategist reviewing every brief before anything changes. We compare LangGraph with a visual workflow tool in n8n vs LangGraph for production AI workflows.

Mapping the Agentic RAG Blocks to Each Framework

Here is how the core components of an agentic RAG system map onto the two frameworks. The blocks are the same either way. What changes is how much of the plumbing you write.

  • Router: conditional routing with a conditional edge in LangGraph; a step that emits different events in a LlamaIndex Workflow.
  • Planner: a node or step that writes the plan into shared state before any search runs.
  • ReAct agents: create_agent in LangChain; agent workflows in LlamaIndex. Both call tools in a loop.
  • Context merging: plain glue code in either framework: deduplicate the retrieved data by document, then fuse rankings with RRF.
  • Plan validation: a final node or step that can send an agent back for missing evidence.

LangGraph pulls ahead when something fails in the middle of a run. With a checkpointer configured, it saves state after every step, and LangSmith Deployment sets that up for you. If one agent fails, it can resume without rerunning the whole plan. In a Workflow you build that yourself.

Winner: LangChain + LangGraph

Durable state, interrupts and approval are built into the runtime. LlamaIndex Workflows are enough when the agent is short-lived and nobody needs to pause it.

Decisive Factor 4: Evaluating the RAG System You Build

This is the factor that decides LlamaIndex vs LangChain for RAG. Both frameworks will produce a working demo. The question is which one produces the better system on your documents, and you can only answer that with an evaluation you trust.

What Each Framework Ships

LlamaIndex's evaluation module includes response evaluators for correctness, semantic similarity, faithfulness, context relevancy, answer relevancy and guideline adherence. Its retrieval evaluator reports ranking metrics such as MRR and hit rate, and it can generate question and context pairs from your documents.

LangSmith's RAG evaluation tutorial uses LLM judges for correctness against a reference, relevance of the answer to the question, groundedness in the retrieved documents and retrieval relevance. LangChain's open-source OpenEvals package offers the same kinds of evaluators as code, and its sister package AgentEvals scores agent trajectories.

Both are useful unit tests. But neither builds a golden dataset from your documents. Neither measures recall at two points or checks its judges against people. And neither tells you whether the agent gives the same answer twice.

‍

  

Evaluating RAG

  

What each framework measures, and what you still need to add

  
                                                                    
What to measureWhat it catchesLlamaIndex built-inLangSmith / OpenEvalsAdd from the method
Recall@K on raw retrievalEvidence never retrievedHit rate, MRR, precisionRetrieval relevance judgeGolden spans, Full Recall@K
Recall on the final contextEvidence cut by reranking or truncationNot separateNot separateScore both points per query
GroundednessClaims the context does not supportFaithfulnessGroundednessJudge calibrated on human labels
CorrectnessWrong answer vs the referenceCorrectness, semantic similarityCorrectnessOracle and no-retrieval baselines
CompletenessParts of the question left outGuideline adherence (custom)HelpfulnessFact-level nuggets
AbstentionAnswers when it should declineNot built inNot built inNo-answer questions, sufficiency check
Agent consistencyDifferent answer on each runNot built inTrajectory match (AgentEvals)pass^k across repeated runs
  
  

Built-in evaluators are useful unit tests. The golden dataset, two-point recall, calibrated judges and pass^k come from your own evaluation harness.

A Six-Step Evaluation That Works on Either Framework

This is the evaluation we run before we optimize anything, and it works the same on either framework. Run it once per candidate stack, on the same dataset, and compare.

1. Build a golden dataset from your documents. Start with 100 to 300 questions that cover lookups, comparisons, multi-document questions and questions the documents cannot answer. Label the evidence by document and text span, not chunk ID, so the labels survive when either framework rechunks.

2. Measure recall at two points. Score Recall@K, Full Recall@K and MRR on the raw retrieval output and again on the final context sent to the model. If evidence appears in the first and not the second, reranking, filtering or truncation lost it.

3. Trace every request. Record each query rewrite, tool call, retrieved chunk, rerank and final context, one trace per request. Arize Phoenix traces both frameworks, runs the same dataset against each pipeline version and ships pre-built evaluators for faithfulness, correctness and retrieval relevance.

4. Calibrate the answer judges. Track correctness, groundedness, completeness and appropriate abstention, scored pass or fail. Check each judge against human labels first; Husain and Shankar suggest labeling 100 to 200 examples per failure mode and tracking the judge's true positive and true negative rates.

5. Measure consistency. Agents can take a different path each run, so run each question several times and report pass^k, the chance that all k runs succeed. In τ-bench, even GPT-4o's retail pass^8 fell below 25%.

6. Record baselines and bucket the failures. Run the answer model with only the gold evidence and with no context at all, then sort every failure into a bucket. The seven failure points of RAG are a good starting list, and ranx adds significance tests so you know whether a gap between two stacks is real.

Abstention deserves its own check. Google's sufficient-context research found that models often answer wrongly instead of declining when the retrieved context is not enough.

Using the same evaluate-first principles, we built a healthcare records Q&A system that reached 95.6% top-5 retrieval accuracy and over 91% accuracy on 50 clinical questions reviewed by healthcare professionals. When generic embeddings struggled there, we fine-tuned a medical model that reached 68% MRR@5 on the NFCorpus benchmark, where the next-best published model scores 52%.

Running a Fair Comparison Between Stacks

A fair comparison changes one thing at a time. Keep the parser, the embedding model and the answer model the same, and swap only the framework's retrieval or orchestration layer. Otherwise you cannot tell which change caused the performance differences.

1. Split the golden dataset into development, validation and holdout sets before you start.

2. Run each stack on the development set with full tracing, and bucket every failure.

3. Fix the largest bucket in each stack, then rerun the full set to check nothing else got worse.

4. Compare the final versions on the holdout set, question by question, with significance tests.

5. Agree in advance which failure types block a release, such as answering when the documents say nothing.

Read the results by bucket, not just by the headline score. One stack may win on lookups and lose on multi-part questions, and the questions your users ask most should decide which one you keep.

Winner: Tie

Both frameworks ship good evaluators, and neither replaces your own golden dataset. The evaluation is the test that picks the framework, not a feature of one.

‍

Evaluate Your AI System Before You Optimize It

The exact playbook we use to evaluate AI systems for accuracy, performance and scale, so changes can be measured.

  
    Free ebook    

Evaluate Your AI System Before You Optimize It

    

The exact playbook we use to evaluate AI systems for accuracy, performance and scale, so changes can be measured.

    Get the free AI system eval ebook →  

‍

Decisive Factor 5: Observability, Cost and Hosting in 2026

Both frameworks are free and MIT-licensed, so the cost question is about the managed layers and about how many tokens your design spends.

LlamaCloud prices LlamaParse and its other services in credits. Its pricing page lists a free tier with 10,000 credits, Starter at $50 a month and Pro at $500 a month, with 1,000 credits costing $1.25 as of October 2026.

LangSmith's pricing starts with a free Developer seat at up to 5,000 base traces a month, then Plus at $39 per seat a month. LangSmith Deployment, the hosting service for LangGraph agents, is metered separately.

For tracing, LangSmith works with any framework, and LlamaIndex has short observability integrations for Phoenix, Langfuse, W&B Weave and OpenTelemetry, often a single line of setup. You are not locked into either vendor's tool.

Design matters more than the framework. A 2026 study, Is Agentic RAG Worth It?, measured agentic RAG at 2.7 to 3.6 times the input tokens and about 1.5 times the latency of a tuned conventional pipeline. My own guide to whether agentic RAG is worth it covers when that cost pays off.

Self-Host or Pay for the Managed Layer

For most teams, both frameworks run fine on your own servers. You can self-host the code, the vector database and an open tracing tool such as Phoenix, and pay only for compute and LLM API usage.

The managed layers save time, not license fees. Pay for LlamaParse when your documents are hard to parse, especially across large datasets, and your team has no parser to maintain. Pay for LangSmith when you want tracing, datasets and deployment in one place.

Count tokens and API cost per question as part of your evaluation. A stack that wins on answer quality but costs three times as much per answer may still lose. Track cost, latency and user feedback next to the quality metrics, and treat them as guardrails that a change must not break.

Winner: Tie, depending on workload

LlamaCloud costs more when parsing is heavy; LangSmith costs more when traces and seats grow. Routing simple questions to a fast path saves more than either.

LlamaIndex vs LangChain for RAG stage by stage: LlamaIndex leads parsing and retrieval, LangGraph leads orchestration, evaluation and hosting are a tie, and the same evaluation run on both settles the choice
Who leads at each stage of a RAG system, and the evaluation that settles the choice.

Pros and Cons of LlamaIndex and LangChain for RAG

LlamaIndex

  • Pro: the deepest ingestion and parsing tools, including LlamaParse.
  • Pro: many retrieval patterns ready to use, with sensible defaults for retrieval applications.
  • Pro: a simple interface and a short path from documents to a working query engine.
  • Con: durable state and approval steps take more design work.
  • Con: the best parsing is a separate paid product, and the TypeScript version is archived.
  • Con: the project's focus is moving toward document processing, so check the roadmap before a long commitment.

LangChain + LangGraph

  • Pro: durable state, interrupts, human approval and fine-grained control over each step, built into the runtime.
  • Pro: more than 1,000 integrations, and Python and TypeScript support.
  • Pro: LangSmith tracing and evaluation, plus a 1.0 stability commitment.
  • Con: a steeper developer experience, with more abstractions to learn before the first useful agent.
  • Con: fewer specialized retrieval patterns out of the box.
  • Con: a history of breaking changes before 1.0, and older tutorials that no longer run.

LlamaIndex vs LangChain for RAG: Which Should You Choose?

Choose LlamaIndex if: your documents are the hard part, with many formats, tables and scans; you need advanced retrieval patterns quickly; and the agent loop is short, such as question answering over a document set.

Choose LangChain + LangGraph if: the agent is the hard part, with multi-step reasoning, long-running state, tools that span business processes, and people who must approve actions.

Use both if: you need strong retrieval and a durable agent. Wrap LlamaIndex retrievers or query engines as tools inside a LangGraph agent, which is the pattern LangChain's own comparison describes.

Use neither if: your evaluation shows a thin pipeline on your vector database and model SDK scores as well. A framework that adds nothing measurable adds only framework overhead and upgrades to maintain.

Questions to Ask Before You Commit

  • Where do our current failures come from: parsing, retrieval, the answer or the agent's choices?
  • Does the agent need to pause for people, or run for minutes across many steps?
  • Do we need TypeScript, or is Python enough?
  • Which managed services would we pay for, and which would we host ourselves?
  • Can we run the same evaluation on each option before we commit?

Whether you lean toward LangChain or LlamaIndex, build the golden dataset first and run the same evaluation on each candidate. In our experience, skipping this step is how teams end up switching frameworks after launch, and a second build costs more than the evaluation would have.

Let the Evaluation Pick the Framework

LlamaIndex vs LangChain for RAG is a fair fight with a clear split. LlamaIndex leads on parsing and retrieval, LangGraph leads on orchestration, and the two tie on evaluation and cost.

The framework is the commodity layer. What decides whether your system works in production is the evaluation: a golden dataset from your documents, recall measured before and after reranking, and judges you have checked against people. Run that test on each option, and the framework choice falls out of the numbers.

‍

Get the Agentic RAG Playbook

The exact playbook we use to build, improve and evaluate agentic RAG systems, whichever framework sits underneath.

  • How agentic RAG works: routing, planning, ReAct agents, context merging and validation

  • The build stack, from document processing to rerankers and agent frameworks

  • Golden datasets, the metrics we track and the tools we use to compute them

  • Fixes organized by symptom: retrieval, answers and agent behavior

  
    Free ebook    

Get the Agentic RAG Playbook

    

The exact playbook we use to build, improve and evaluate agentic RAG systems, whichever framework sits underneath.

                                                    
How agentic RAG works: routing, planning, ReAct agents, context merging and validation
The build stack, from document processing to rerankers and agent frameworks
Golden datasets, the metrics we track and the tools we use to compute them
Fixes organized by symptom: retrieval, answers and agent behavior
    Get the free Agentic RAG Playbook →  

‍

‍

Frequently Asked Questions About RAG for LlamaIndex or LangChain

Can LlamaIndex and LangChain be used together in one RAG system?

Yes. A common pattern wraps LlamaIndex retrievers or query engines as tools that a LangGraph agent calls, so you get LlamaIndex retrieval inside a LangGraph control loop.

Is LlamaIndex free and open source?

Yes. The LlamaIndex framework is open source under the MIT license and free to use. LlamaParse and LlamaCloud are paid services with a free tier of 10,000 credits.

Who are LlamaIndex's competitors?

LangChain and LangGraph are the closest RAG frameworks, followed by other popular frameworks such as Haystack and DSPy. SDKs for building AI agents from OpenAI, Anthropic and Microsoft compete for the orchestration layer.

How do I evaluate a RAG system built with either framework?

Build a golden dataset from your own documents, measure recall on raw retrieval and on the final context, and calibrate answer judges against human labels. Run the same evaluation on each framework and compare.

Do I need a framework for RAG at all?

Not always. A thin pipeline, one vector search and one LLM call through your model SDK, can match a framework on simple retrieval, so let your evaluation decide whether a framework adds anything.

‍