← All tutorials
LangChain vs LlamaIndex

LangChain vs LlamaIndex — which framework?

Both are popular open-source frameworks for building LLM applications, and both do RAG — so which do you pick? The short version: LangChain is a broad toolkit for orchestration and agents; LlamaIndex is a focused toolkit for connecting LLMs to your data. They overlap on RAG and can even be used together.

Breadth

🔗 LangChain

Chains, agents, tools, memory, and orchestration (LangGraph) across a huge integration ecosystem.

Depth (on data)

🦙 LlamaIndex

Best-in-class ingestion, indexing, retrieval and query engines — a data framework for RAG.

One line each. LangChain: "give me building blocks to orchestrate LLMs and agents." LlamaIndex: "give me the best pipeline to search and answer over my documents."

At a glance  Two frameworks, one overlap

Each has a home turf, and they meet in the middle at RAG:

LangChain and LlamaIndex overlap on RAG LangChain's strengths are agents, tools, chains and orchestration. LlamaIndex's strengths are data loaders, indexes, retrievers and query engines. They overlap on retrieval-augmented generation (RAG). LangChain LlamaIndex Agents & tools Chains / LCEL LangGraph LangSmith broad ecosystem RAG retrieval + answer Data loaders Indexes Retrievers Query engines LlamaParse / Hub

The overlap is why the "which should I use?" question is confusing — for a basic "chat with my docs," either works. The differences show at the edges: complex agents pull you toward LangChain; sophisticated retrieval over lots of data pulls you toward LlamaIndex.

Framework 1  LangChain

LangChain general LLM-app framework · Python & JS

Solves The "too much glue code" of building LLM apps in general. It provides composable building blocks — prompt templates, output parsers, tool-calling, memory, retrievers — wired together with LCEL, plus LangGraph for stateful multi-step/agent orchestration and LangSmith for tracing & evaluation. Huge ecosystem of provider and tool integrations.

Limits Breadth brings sprawl — many abstractions and layers, fast-moving APIs, and a steeper path for a simple "chat with my docs" than a focused tool. Its default RAG is more manual (you assemble loaders, splitters, stores, retrievers) than LlamaIndex's out-of-the-box indexing.

Choose Agents and tool use, complex multi-step or multi-agent workflows, orchestration with branching/loops, and when you want the widest integration + observability ecosystem.

Already in this repo: the LLM apps tutorial builds LangChain chains, a LangGraph agent, and LangSmith tracing end to end.

Framework 2  LlamaIndex

LlamaIndex data framework for LLMs · Python & TS

Solves Connecting LLMs to your data, exceptionally well. It's built around the RAG pipeline: ingest (100+ data loaders via LlamaHub, plus LlamaParse for messy PDFs), index (vector, summary, tree, keyword, knowledge-graph indexes), retrieve (advanced strategies — auto-merging, recursive, hybrid), and query engines that retrieve and synthesize an answer in a few lines.

Limits Narrower by design — it's optimized for search/retrieval over data, so building complex, branching multi-agent orchestration is less its strength (it has agents/workflows, but they're not the center of gravity like LangGraph). Fewer non-data integrations than LangChain.

Choose RAG is the heart of your app: "chat with documents," knowledge-base Q&A, search over large or messy corpora, or when you want strong retrieval quality with minimal assembly.

Hands-on  The same RAG, both ways

Index a folder of docs and answer a question. Notice how LlamaIndex's opinionated defaults compress the pipeline, while LangChain exposes each step. Switch tabs; hit Copy.

RAG over ./data
# pip install llama-index
# Opinionated defaults: load → chunk → embed → index → query, in ~4 lines.
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

docs   = SimpleDirectoryReader("data").load_data()   # ingest a folder
index  = VectorStoreIndex.from_documents(docs)        # chunk + embed + index
engine = index.as_query_engine()                      # retrieve + synthesize

print(engine.query("What is our refund policy?"))
Read the trade-off. LlamaIndex is faster to a working RAG answer because it decides the pipeline for you. LangChain shows every seam — more to write, but more control over each step (and the same objects slot into agents/graphs).

Side by side

AspectLangChainLlamaIndex
Center of gravityOrchestration & agentsData ingestion & retrieval
Core abstractionsRunnables/LCEL, chains, agents, toolsDocuments/Nodes, Indexes, Retrievers, Query Engines
RAG out of the boxManual assembly, very flexibleOpinionated, minimal-code, advanced retrieval
Agents & workflowsStrong — LangGraph for complex graphsPresent, but not the focus
Ingestion / parsingMany loadersLlamaHub (100+) + LlamaParse for hard docs
ObservabilityLangSmith (first-party)Callbacks + integrations
EcosystemVery broad (tools, providers)Deep on data/RAG
Best forAgentic, multi-step appsSearch/Q&A over your data
They're not mutually exclusive. A common pattern: use LlamaIndex for top-notch ingestion + retrieval, and expose its retriever/query engine as a tool inside a LangChain/LangGraph agent. Best of both.

When to choose which

If your app is mostly…Lean toward…
Search / Q&A over documents ("chat with my data")LlamaIndex
Sophisticated retrieval over large or messy corporaLlamaIndex
Agents, tools, and multi-step orchestrationLangChain (+ LangGraph)
Complex branching/looping workflows & multi-agentLangChain (LangGraph)
Needs deep tracing & evaluation toolingLangChain (LangSmith)
Great retrieval and rich agent orchestrationBoth — LlamaIndex retrieval as a LangGraph tool
Rule of thumb. If the hard part is the data (parsing, indexing, retrieval quality), start with LlamaIndex. If the hard part is the control flow (agents, tools, orchestration), start with LangChain. When both are hard, combine them.

Cheat sheet

QuestionShort answer
One-line difference?LangChain = orchestration/agents; LlamaIndex = data/RAG.
Which is faster to a basic RAG answer?LlamaIndex — opinionated defaults, ~4 lines.
Which for complex agents & workflows?LangChain, with LangGraph.
Which for the best ingestion/retrieval?LlamaIndex (LlamaHub loaders, LlamaParse, rich indexes).
Do I have to pick one?No — use LlamaIndex retrieval as a tool inside a LangChain agent.
Both moving fast?Yes — verify APIs against current docs.

Knowledge check

Six questions on LangChain vs LlamaIndex. Pick an answer for each, then check your score.

1. In one line, how do they differ in focus?

2. Where do the two frameworks clearly overlap?

3. You need best-in-class ingestion and retrieval over lots of messy PDFs. Lean toward…

4. Your app is a complex multi-agent workflow with branching and loops. Lean toward…

5. Why is LlamaIndex often fewer lines for a basic RAG app?

6. You want great retrieval AND rich agent orchestration. Best approach?

Next steps

🤖 LLM apps (LangChain)

Build with LangChain — chains, a LangGraph agent, and LangSmith tracing.

🔎 RAG vs CAG vs GraphRAG

Grounding strategies — the retrieval techniques both frameworks implement.

🧬 Embedding models

The vectors underneath — what powers retrieval in either framework.

📓 All tutorials

The hub — LLM apps, embeddings, retrieval, agents, protocols & more.