LangChain vs. LlamaIndex vs. Vanilla: The Builder's Stack Selection Matrix
A practical way to choose an LLM stack. You compare LangChain and LangGraph, LlamaIndex and plain provider SDKs by where your app's complexity lives (control flow, data or neither), walk a three-question flowchart, see a starter folder layout for each path, and learn when a hybrid of two makes sense.

This guide is for developers starting an LLM app who can't decide between LangChain, LlamaIndex and calling a provider's SDK directly. The usual question, "Should I use LangChain or just call the API?", is the wrong one. The right question is: where does the complexity in your app live? Answer that, and the stack mostly picks itself.
Key takeaways
- If the hard part is control flow (loops, branching, human approval), use LangChain's agents or LangGraph.
- If the hard part is data (many messy documents to load, index and retrieve), LlamaIndex is built for that.
- If the app is one prompt in and one answer out, call the provider's SDK directly. You can mix all three in one app.
An LLM framework is a library that wraps model calls, prompts, tools and data access in shared interfaces, so you write less glue code but accept its abstractions. A common trap is picking one because it's trending, not because it solves the hard part of your app. No single choice is right for every project.
This post is part 2 of the LLM & LangChain Fundamentals series. Part 1 covered what LangChain is and when to write your own code. This part gives you a way to make that call for a whole project.
The three paths
1. LangChain and LangGraph (the generalist)
Best for: agents, tool calling and apps whose next step depends on what came before.
LangChain gives you standard interfaces for models, prompts, tools and vector stores. Its docs say you can "switch models with minimal code changes." Its agent harness, create_agent, is built on top of LangGraph.
LangGraph is the lower layer. Its docs call it "a low-level orchestration framework and runtime for building, managing, and deploying long-running, stateful agents." It handles loops, branching, persistence and human-in-the-loop steps, which are painful to build from scratch. The LangGraph docs suggest starting with LangChain's agents if you're new to agents, and dropping to LangGraph when you need more control.
2. LlamaIndex (the data specialist)
Best for: retrieval-augmented generation (RAG), many messy data sources, and "chat with my documents" apps.
LlamaIndex's docs describe the framework as "a Python toolkit for building LLM-powered agents over your data." Its building blocks are data connectors, indexes and vector stores, and query and chat engines. Loading starts with readers such as SimpleDirectoryReader, which the docs call "the simplest way to load data from local files into LlamaIndex." Its community integrations page lists data loaders for many sources.
LlamaIndex also has agents and event-driven workflows now, so it's not only a retrieval library. As a rule of thumb, though, pick it when retrieval quality is the core of the product.
3. Vanilla SDKs (the surgeon)
Best for: single-purpose features, endpoints where every millisecond counts, and learning the basics.
"Vanilla" means calling the provider's official SDK, such as OpenAI's or Anthropic's, directly. There's less code between you and the model. A framework brings its abstractions with it. When one breaks, you debug the framework, not your code. As a rule of thumb, a framework mostly adds dependencies for a single prompt or a short fixed sequence.
| Path | What it does best | Trade-off | Use it when |
|---|---|---|---|
| LangChain / LangGraph | Control flow: tools, loops, state, approvals | More abstraction to learn and to debug | The next step depends on the last result |
| LlamaIndex | Data: loading, indexing and retrieval | Its own abstractions; less focus on general orchestration | Answers depend on finding the right passage in many documents |
| Vanilla SDK | One call, full visibility | You write retries, parsing and provider switching yourself | Input, prompt, output, done |
The decision flowchart
Ask three questions, in order:
- Does the app need loops, self-correction or multi-step planning?
- Yes: use LangChain agents, or LangGraph for custom control flow.
- No: go to question 2.
- Is the main value finding specific facts in a large pile of unorganized documents?
- Yes: use LlamaIndex.
- No: go to question 3.
- Is it a straight line (input, prompt, output) or a simple classification?
- Yes: use the vanilla SDK.
- No: you're probably in hybrid territory, such as some retrieval plus some branching. Start with the vanilla SDK for the simplest part, and add a framework for the part that grows complex.
If you answer yes to both of the first two questions, read the hybrid section below.
Complexity versus control: the abstraction tax
Every framework charges what you could call an abstraction tax:
- High abstraction (LangChain, LlamaIndex): you write less code to start, and you can swap providers more easily. But you see less. When an agent loops, you trace the problem through framework code instead of your own. Tracing tools help, but they're one more thing to set up.
- Low abstraction (vanilla): you write more boilerplate, and you handle retries and parsing yourself. In return, you know exactly what reaches the model, and you control latency and token use directly.
As a rule of thumb, pay the tax only where the framework saves you more work than it costs to learn and debug.
Starter folder layouts
Here is how each path can look in a repository. These are starting points, not rules: a clear layout early makes later refactors smaller.
Scenario A: the autonomous agent (LangGraph)
Use case: a research assistant that searches the web, summarizes what it finds and writes a report.
/src
/agents
/researcher
graph.py # The state graph (nodes and edges)
state.py # The state schema the nodes share
prompts.py # System prompts for this agent
/tools
search.py # Search API client (Tavily, Serper or similar)
scraper.py # Page fetching and text extraction
/checkpoints # Persistence settings for long-running threads
main.py # Entry point that runs the graph
Why this works: LangGraph makes you think in terms of state. Keeping the graph apart from the tools lets you add or swap the agent's abilities without touching its control flow.
Scenario B: the knowledge engine (LlamaIndex)
Use case: a question-answering bot over thousands of PDF contracts.
/src
/ingestion
loader.py # Readers, such as SimpleDirectoryReader or a parsing service
pipeline.py # Splitting into nodes and extracting metadata
/indices
vector_store.py # Vector store setup (Pinecone, Qdrant or similar)
retriever.py # Custom retrieval, such as hybrid search
/engine
chat.py # The chat engine, with memory
config.py # Embedding model and other settings
Why this works: as a rule of thumb, loading, splitting and indexing take as much effort in RAG as answering questions does. This layout keeps those extract, transform and load steps apart from the query code.
Scenario C: the micro-tool (vanilla)
Use case: an email generator that turns bullet points into a formatted HTML email.
/src
/services
llm_client.py # Thin wrapper around the OpenAI or Anthropic SDK
/prompts
email_templates.py # Plain string templates
/utils
parser.py # JSON or regex extraction
app.py # FastAPI or Streamlit entry point
Why this works: it's flat and easy to follow. You don't need a vector index to write an email. You need a good prompt and a reliable API client.
The hybrid approach
You don't have to pick just one. One way to split a hybrid stack:
- LlamaIndex for the data layer: loading, splitting and retrieval.
- LangChain or LangGraph for orchestration: deciding what to do with that data.
- A vanilla SDK call for the final generation step, when the output format must be exact.
For example, use LlamaIndex to fetch context from your documents and pass it into a LangGraph node. The graph decides whether the context is enough. If it is, it writes the answer. If not, it calls a web search tool.
Each extra framework is one more set of versions to track, so add the second one only when the first doesn't cover the job.
Ship, don't stall
The ecosystem moves too fast to be a purist.
If you're building a prototype to test an idea, a framework gets you there fastest, because its integrations are ready to use. If you're tuning for production reliability, audit what you built. Where a framework piece adds steps you don't need, replace it with a plain SDK call.
Match the stack to where your complexity lives, not to the hype. Next in the series, you'll make a model return data your code can trust with structured JSON output, Pydantic and retry loops.
Frequently asked questions
Is LlamaIndex better than LangChain for RAG?
LlamaIndex is built around getting data in and retrieving it well, with readers, indexes and query engines as its core pieces. LangChain can also do RAG, and its strength is control flow around the model. If retrieval quality is the heart of your product, start with LlamaIndex; if the hard part is what happens after retrieval, start with LangChain.
What is the difference between LangChain and LangGraph?
LangGraph is the lower-level runtime for long-running, stateful agents. LangChain's create_agent is a higher-level harness built on top of it. The LangGraph docs suggest starting with LangChain's agents and moving to LangGraph when you need custom control flow.
Should I skip frameworks and use the OpenAI or Anthropic SDK directly?
For a single prompt, a classification or a short fixed sequence, yes: there is less code between you and the model, and fewer dependencies. Once you need tools, loops, retrieval over many documents or easy provider switching, a framework starts to save you more work than it costs.
Can I use LangChain and LlamaIndex together?
Yes. One option is LlamaIndex for loading and retrieval and LangChain or LangGraph for the agent logic that uses the results. Keep the boundary clear, such as a retriever function the agent calls as a tool, so each part can change on its own.
Sources
Verified against the sources below on October 30, 2026. Products and docs change often: check the linked sources if something looks different.
All 14 parts in this series
- Part 01What Is LangChain? When to Use It and When to Write Your Own Code
- Part 02LangChain vs. LlamaIndex vs. Vanilla: The Builder's Stack Selection Matrix
- Part 03Structured JSON Output from LLMs: Schema Injection, Pydantic and Retry Loops
- Part 04Building Your First LLM Chain: A Developer's Guide to Sequential Logic
- Part 05Building Your First RAG Pipeline: A Developer’s Guide to Context-Aware AI
- Part 06Building Robust RAG Pipelines: A Deep Dive into LangChain Document Loaders
- Part 07Stop Overthinking Vector Databases: A Builder’s Decision Framework
- Part 08Building Long-Term Memory: Setting Up Vector Databases for Semantic Search in LangChain
- Part 09From Chatbot to Agent: The Engineer's Guide to LLM Memory Systems
- Part 10Building State: A Deep Dive into LangChain Memory for Conversational AI
- Part 11Beyond Built-ins: Architecting Custom Tools in LangChain
- Part 12Unmasking the Black Box: Mastering LangChain Callbacks for Debugging
- Part 13Architecting Autonomous Agents: A Builder’s Guide to Complex Workflows
- Part 14Best Practices for Deploying LangChain Apps to Production
AI Automation Engineer & Salesforce Developer
Salesforce developer since June 2018. I build AI agents, n8n workflows and Salesforce integrations, and write up what holds up in real use.



Comments
Loading comments...