← Master Index
Vol. 14 Module 14.3 Lecture

LangChain

LangChain & Orchestration Frameworks

How This Lesson Fits the Module & Volume

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.
Definition

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

PatternControl flowTypical use
RAG chainMostly linear / DAGQ&A over docs
Tool-calling agentModel chooses tools in a loopAPIs, search, calc
Graph agent (LangGraph)Explicit states & edgesLong-running, HITL
Multi-agent crewRoles + handoffsResearch / ops teams

Minimal RAG with LCEL

from langchain_openai import ChatOpenAI, OpenAIEmbeddings from langchain_community.vectorstores import Chroma from langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import RunnablePassthrough from langchain_core.output_parsers import StrOutputParser vectorstore = Chroma( persist_directory="./chroma_store", embedding_function=OpenAIEmbeddings(), collection_name="support_docs", ) retriever = vectorstore.as_retriever(search_kwargs={"k": 4}) prompt = ChatPromptTemplate.from_messages([ ("system", "Answer using only the context. If unknown, say you don't know.\n\n{context}"), ("human", "{question}"), ]) def format_docs(docs): return "\n\n".join(d.page_content for d in docs) rag = ( {"context": retriever | format_docs, "question": RunnablePassthrough()} | prompt | ChatOpenAI(model="gpt-4o-mini") | StrOutputParser() ) print(rag.invoke("How do I reset SSO?"))

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)
Common Misconception

“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

  1. Short Answer: What does LangChain primarily orchestrate? Answer: LLMs, prompts, retrievers, tools, and related app glue.
  2. True/False: A RAG chain is usually more linear than an agent loop. Answer: True.
  3. Multiple Choice: as_retriever() typically wraps: (a) a CSS theme, (b) a vector store, (c) a GPU driver. Answer: (b).
  4. Short Answer: Name LCEL’s composition operator often used between steps. Answer: The pipe | operator on Runnables.
  5. True/False: LangChain replaces the need for a vector database. Answer: False—it integrates with them.
  6. Multiple Choice: LlamaIndex is relatively more focused on: (a) indexing/retrieval, (b) CUDA kernels, (c) CSS. Answer: (a).
  7. Short Answer: When might you skip LangChain? Answer: Tiny fixed pipeline where a few API calls suffice.
  8. Short Answer: What Volume deepens agent concepts next? Answer: Volume 15 (AI Agents).
  9. Multiple Choice: Tool-calling agents let the model: (a) only recite docs, (b) choose tools in a loop, (c) train FAISS. Answer: (b).
  10. 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.
Trainer’s Guide

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.