LangChain RAG Tutorial
by LangChain
The official RAG walkthrough, rewritten as an agentic build with sub-agents and a retrieval filesystem.
Overview
LangChain's official RAG tutorial was rewritten for the v1 documentation and is now an agentic-RAG build, not the classic load-split-embed-retrieve-generate chain that most copies of it still teach. It opens with four RAG patterns — skills-guided retrieval, rubric-checked grounding, todo-driven investigation, and retrieve-offload-delegate — then demonstrates the failure case by running an agent with no retrieval at all. Setup is five steps. The indexing section is the familiar four: fetch documents with requests, wrap them in `Document`, split with `RecursiveCharacterTextSplitter`, embed with `OpenAIEmbeddings`, and store in `InMemoryVectorStore`, with Chroma, Pinecone, Qdrant and MongoDB offered as drop-in swaps. The agent section is where it diverges: a `@tool`-decorated search function, a system prompt, and `create_deep_agent()` from the MIT-licensed `deepagents` package, which layers a planning tool, a pluggable filesystem `StateBackend` and sub-agents on top of LangGraph. The finished agent indexes 14 LangChain documentation pages into 782 chunks, writes retrieved chunks to its own filesystem under `/retrieved/`, fans up to three parallel 'chunk-analyst' sub-agents out to read them, and synthesises a cited answer — the retrieve-offload-delegate pattern, which keeps large retrieved payloads out of the orchestrator's context window. It closes on LangSmith tracing and a section on indirect prompt injection through indexed content. Model support spans OpenAI, Anthropic, Google, Ollama and others.
At a Glance
- Topic
- RAG
- Level
- Intermediate
- Format
- Tutorial
- Cost
- Free
- Duration
- ~1-2 hours, self-paced
- Provider
- LangChain
- Hands-on
- Yes — code/exercises
- Certificate
- None
What You’ll Learn
- ✓The full indexing path: load, split, embed and store documents in a vector store
- ✓Exposing retrieval to an agent as a decorated tool rather than a fixed chain
- ✓Building an agent with create_deep_agent on top of the LangGraph runtime
- ✓The retrieve-offload-delegate pattern that keeps chunks out of the main context
- ✓Fanning parallel sub-agents over retrieved chunks and synthesising their reports
- ✓Guarding against indirect prompt injection carried inside indexed documents
Highlights
- •The official LangChain tutorial, kept current with the v1 documentation
- •Teaches agentic RAG with sub-agents, not the 2023 retrieval chain most tutorials copy
- •Names four distinct RAG patterns up front so you pick an architecture deliberately
- •Includes a security section on indirect prompt injection — rare in RAG tutorials
- •Model-agnostic: OpenAI, Anthropic, Google, Ollama and OpenRouter all work
Who It’s For
Best For
- ✓Developers building question-answering over their own documentation
- ✓Engineers moving a working RAG chain toward an agentic architecture
- ✓Teams evaluating deepagents and LangGraph for retrieval-heavy work
Prerequisites
- •Working Python and comfort installing packages into a virtual environment
- •An API key for a chat model and an embeddings provider
- •Basic understanding of embeddings and vector similarity search
FAQ
What is LangChain RAG Tutorial?
LangChain's official RAG tutorial, rewritten for the v1 docs as an agentic build. You index LangChain's own documentation into a vector store, expose retrieval as a tool, then assemble a deep agent that offloads retrieved chunks to a filesystem and delegates their analysis to parallel sub-agents before synthesising a cited answer. It closes on LangSmith tracing and defending against prompt injection.
Is LangChain RAG Tutorial free?
LangChain RAG Tutorial is free to access.
What level is LangChain RAG Tutorial for?
LangChain RAG Tutorial is aimed at a intermediate audience. Recommended background: Working Python and comfort installing packages into a virtual environment, An API key for a chat model and an embeddings provider, Basic understanding of embeddings and vector similarity search.
How long does LangChain RAG Tutorial take?
Expect roughly ~1-2 hours, self-paced. Most learners work through it at their own pace.
What will I learn from LangChain RAG Tutorial?
You'll learn: The full indexing path: load, split, embed and store documents in a vector store; Exposing retrieval to an agent as a decorated tool rather than a fixed chain; Building an agent with create_deep_agent on top of the LangGraph runtime; The retrieve-offload-delegate pattern that keeps chunks out of the main context; Fanning parallel sub-agents over retrieved chunks and synthesising their reports; Guarding against indirect prompt injection carried inside indexed documents.
Topics
Sources
This page was written from 3 sources, 2 on domains other than docs.langchain.com.