SproutStackSproutStack home

LangChain vs LlamaIndex vs Raw SDK

7 min readBeginner-friendlyFree to read

Read a little, play a little. No scary maths, and no rush.

Share:

Last reviewed: October 2026 · report an issue

The one-line verdict

  • Learning? Raw SDK — 20 lines, zero magic, you own every failure mode.
  • RAG getting serious? LlamaIndex — loaders, indices, and evals purpose-built for data.
  • Agents / fast prototypes? LangChain — biggest ecosystem of chains, tools, and integrations.

Official homes: LangChain · LlamaIndex · OpenAI API.

Same task, three ways

# Raw SDK: explicit and debuggable
resp = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Summarize: ..."}],
    temperature=0.2,
)
# LlamaIndex: data in, answers out
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
docs = SimpleDirectoryReader("docs/").load_data()
index = VectorStoreIndex.from_documents(docs)
print(index.as_query_engine().query("Refund policy?"))
# LangChain: compose chains and tools fast
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
chain = ChatPromptTemplate.from_template("Summarize: {text}") | ChatOpenAI(model="gpt-4o-mini")
print(chain.invoke({"text": "..."}))

What each one actually gives you

  • Raw SDK: full control and nothing hidden. You write your own retries, streaming handling, chunking, and retrieval glue. More code, but every line is yours to read when something breaks.
  • LlamaIndex: built around data. Document loaders for many formats, chunking and indexing, query engines over your documents, and helpers for evaluating retrieval. Strongest when the hard part of your app is getting the right text to the model.
  • LangChain: built around composition and integrations. Prompt templates, chains, tool and agent support, and connectors to a very large number of services. Its companion library, LangGraph, models agents as explicit graphs of steps with saved state.

One feature, three levels of effort

Take "answer questions from our docs folder with citations."

With the raw SDK, you write a loader, a chunker, the embedding and storage calls, retrieval, and the prompt yourself: perhaps a hundred or more lines. Slow to write, and you understand every part.

With LlamaIndex, the snippet above gets a working version in a handful of lines using sensible defaults. The effort moves to learning its settings when you need a different chunk size, metadata filters, or a reranker.

With LangChain, you compose a retriever, a prompt, and a model into a chain. Quick to assemble, with the same trade-off: to tune or debug it, you need to know what each component does inside.

Questions to ask before adopting one

  • Are we rebuilding the same plumbing for the second time?
  • Can we easily see the exact final prompt sent to the model?
  • How often have past upgrades broken existing code?
  • Does the team already know it?
  • Is there a feature we need that it makes awkward?

Honest limits

  • Frameworks move fast — pin versions, expect API churn between tutorials.
  • Abstractions hide prompts, retries, and costs; when answers go wrong, you debug one layer down anyway.
  • Rule of thumb: prototype raw, adopt a framework the second time you rebuild the same plumbing.

The escape hatch matters more than the choice

Whichever you pick, isolate it behind your own thin wrapper (one chat(), one retrieve() function). Frameworks churn fast — pinned versions, narrow integration seams, and evals that run regardless of vendor mean you can migrate in days when the ecosystem shifts under you.

Mixing them is normal

These are libraries, not loyalties. A common setup uses LlamaIndex for loading and retrieval, then calls the provider's SDK directly for generation, where full control over the prompt matters most. Use each where it saves real work, and keep your own thin wrapper between them and the rest of your code.

Check your understanding

5 questions · first-try answers earn the most XP

1. What is the recommended first step when learning to build with LLM APIs?
2. When does LlamaIndex become the better fit compared to the alternatives?
3. What is the shared limitation the chapter names about all three approaches?
4. Why does the chapter argue the escape hatch matters more than the choice of framework?
5. What does the chapter mean by abstractions hiding prompts, retries, and costs?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.