Self-RAG
This directory is retained purely for archival purposes and is no longer updated. Please see the newly [consolidated LangChain documentation](https://docs.langchain.com/oss/python/langgraph/overview) for the most current information and resources.
Get this prompt chain
This directory is retained purely for archival purposes and is no longer updated. Please see the newly consolidated LangChain documentation for the most current information and resources.
Self-RAG
Self-RAG is a strategy for RAG that incorporates self-reflection / self-grading on retrieved documents and generations.
In the paper, a few decisions are made:
- Should I retrieve from retriever,
R-
- Input:
x (question)ORx (question),y (generation) - Decides when to retrieve
Dchunks withR - Output:
yes, no, continue
- Are the retrieved passages
Drelevant to the questionx-
- Input: (
x (question),d (chunk)) fordinD
- Input: (
dprovides useful information to solvex- Output:
relevant, irrelevant
- Are the LLM generation from each chunk in
Dis relevant to the chunk (hallucinations, etc) -
- Input:
x (question),d (chunk),y (generation)fordinD - All of the verification-worthy statements in
y (generation)are supported byd - Output:
{fully supported, partially supported, no support
- The LLM generation from each chunk in
Dis a useful response tox (question)-
- Input:
x (question),y (generation)fordinD y (generation)is a useful response tox (question).- Output:
{5, 4, 3, 2, 1}
We will implement some of these ideas from scratch using LangGraph.

Setup
First let's install our required packages and set our API keys
Set up LangSmith for LangGraph development
Sign up for LangSmith to quickly spot issues and improve the performance of your LangGraph projects. LangSmith lets you use trace data to debug, test, and monitor your LLM apps built with LangGraph — read more about how to get started here.
Retriever
Let's index 3 blog posts.
LLMs
Graph
Capture the flow in as a graph.
Graph state
Build Graph
The just follows the flow we outlined in the figure above.
LangSmith Traces -
