LangChain is a broad toolkit for chaining model calls, tools and agents; LlamaIndex specialises in connecting models to your data for retrieval (RAG); writing your own code gives you the most control and understanding. Learn the underlying pattern by hand first, then choose a framework where it saves time. Frameworks change quickly; the concepts underneath them don't.
How do they compare?
| Option | Strengths | Trade-offs |
|---|---|---|
| LangChain | Many integrations, chains, agents and tools; large community | Abstractions can hide what is happening; APIs change often |
| LlamaIndex | Data connectors, indexing, retrieval strategies for RAG | Less suited to general workflows than to data-heavy apps |
| Custom code | Full control, easy debugging, fewer dependencies, clear performance | You write and maintain more; slower to prototype |
What should you build by hand first?
- A RAG pipeline: chunk documents, create embeddings, store them, retrieve the top matches, build the prompt, generate an answer with citations.
- An agent loop: the model chooses a tool, your code runs it, the result goes back, repeat with a step limit (see tool use).
Once you've done both, a framework's documentation reads like a description of things you already understand.
How do you choose for a real project?
- Prototype fast: a framework is fine.
- Data-heavy question answering: LlamaIndex's retrieval tools are a strong fit.
- Complex tool workflows: LangChain's agent tooling, or a small custom loop.
- High control, low dependencies: custom code, with good logging and tests.
Whatever you pick, build an evaluation set so you can switch approaches without guessing.
How Program Zero approaches frameworks
In Phase 8, Program Zero teaches attention and transformers from scratch, then RAG with vector databases and AI agents, so frameworks are tools you understand rather than magic. Read what is RAG and how to build AI agents for the fundamentals.