Modules 14.1–14.2 gave you RAG pieces: chunks, embeddings, and stores like Qdrant. LangChain opens Module 14.3 by orchestrating those pieces—prompts, models, retrievers, tools—into runnable chains.
LangChain is the broad toolkit; LangGraph adds durable agent graphs; LlamaIndex leans retrieval/indexing. Volume 15 then deepens AI agents on top of these patterns.
Learning Objectives
By the end of this lesson, students should be able to:
- Explain LangChain’s role: compose LLMs, prompts, retrievers, and tools.
- Build a LCEL-style RAG chain (retrieve → prompt → model → parse).
- Contrast RAG orchestration with multi-step agent workflows.
- Connect a vector store (e.g., Chroma/Qdrant) as a retriever.
- Compare LangChain vs LlamaIndex vs LangGraph at a high level.
- Recognize when a thin custom pipeline beats a heavy framework.
LangChain is an open-source framework for building applications powered by language models. It provides abstractions for prompts, models, retrievers, tools, memory, and composition (LCEL / Runnable) so developers wire RAG and tool-using flows without reinventing glue code.
RAG Orchestration vs Agent Workflows
| Pattern | Control flow | Typical use |
|---|---|---|
| RAG chain | Mostly linear / DAG | Q&A over docs |
| Tool-calling agent | Model chooses tools in a loop | APIs, search, calc |
| Graph agent (LangGraph) | Explicit states & edges | Long-running, HITL |
| Multi-agent crew | Roles + handoffs | Research / ops teams |
Minimal RAG with LCEL
Framework Landscape (Preview)
LangChain
- Broad integrations
- Chains + tools
- Ecosystem hub
LlamaIndex
- Index/query focus
- Strong data connectors
- RAG-centric DX
LangGraph
- Stateful graphs
- Cycles, persistence
- Agent control plane
Strengths
- Huge connector surface
- Fast RAG prototypes
- Shared patterns across vendors
- Path into LangGraph agents
Tradeoffs
- Abstraction churn across versions
- Debugging nested runnables
- Easy to over-framework simple jobs
- Need observability (traces)
“LangChain is an agent platform by itself.” Classic chains are orchestration glue. Serious cyclic agents, checkpoints, and human-in-the-loop belong with LangGraph (and Volume 15 agent design).
Knowledge Check
- Short Answer: What does LangChain primarily orchestrate? Answer: LLMs, prompts, retrievers, tools, and related app glue.
- True/False: A RAG chain is usually more linear than an agent loop. Answer: True.
- Multiple Choice:
as_retriever()typically wraps: (a) a CSS theme, (b) a vector store, (c) a GPU driver. Answer: (b). - Short Answer: Name LCEL’s composition operator often used between steps. Answer: The pipe | operator on Runnables.
- True/False: LangChain replaces the need for a vector database. Answer: False—it integrates with them.
- Multiple Choice: LlamaIndex is relatively more focused on: (a) indexing/retrieval, (b) CUDA kernels, (c) CSS. Answer: (a).
- Short Answer: When might you skip LangChain? Answer: Tiny fixed pipeline where a few API calls suffice.
- Short Answer: What Volume deepens agent concepts next? Answer: Volume 15 (AI Agents).
- Multiple Choice: Tool-calling agents let the model: (a) only recite docs, (b) choose tools in a loop, (c) train FAISS. Answer: (b).
- True/False: Observability/tracing helps debug LangChain apps. Answer: True.
Key Takeaways
- LangChain composes RAG and tool flows over models and vector stores.
- Prefer simple chains for Q&A; graduate to graphs for cyclic agents.
- Integrations accelerate demos but need discipline and tracing.
- Next lectures specialize: graphs, indexes, multi-agent, typed agents, pipelines.
- Continue with LangGraph for stateful agent orchestration.
Lab: Wire Qdrant or Chroma into the LCEL RAG sketch; ablate k=2 vs k=8 and discuss context noise.
Whiteboard: Draw RAG chain vs agent loop; mark where Volume 15 concepts (tools, memory, planning) attach.
Recap: LangChain is the orchestration hub for RAG apps. Continue with LangGraph.