Skip to content

Anurag-M1/Self-RAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Self RAG (LangGraph + LangChain)

A notebook-based Self-RAG pipeline over internal company PDFs, with retrieval, relevance filtering, support verification, and usefulness checks.

Self RAG Graph

What this project does

  • Loads internal PDFs from ./documents/
  • Splits and embeds text chunks into a FAISS vector store
  • Routes each question through a LangGraph workflow:
    1. Decide whether retrieval is needed
    2. Retrieve + relevance filter
    3. Generate answer from context
    4. Verify grounding (IsSUP)
    5. Revise answer if not fully supported
    6. Check usefulness (IsUSE)
    7. Rewrite retrieval query and retry if needed

Main implementation: self_rag_step7.ipynb

Project structure


├── self_rag.ipynb
├── SRAG.png
└── documents/
    ├── Company_Policies.pdf
    ├── Company_Profile.pdf
    └── Product_and_Pricing.pdf

Requirements

  • Python 3.10+
  • OpenAI API key

Install dependencies:

pip install -U \
  jupyter \
  python-dotenv \
  pydantic \
  langgraph \
  langchain-core \
  langchain-community \
  langchain-openai \
  langchain-text-splitters \
  faiss-cpu \
  pypdf

Setup

Create a .env file in the project root:

OPENAI_API_KEY=your_openai_api_key

Run

jupyter notebook self_rag_step7.ipynb

Then run cells top-to-bottom.

Workflow summary

The notebook builds a StateGraph with these key nodes:

  • decide_retrieval
  • retrieve
  • is_relevant
  • generate_from_context
  • is_sup -> revise_answer loop
  • is_use -> rewrite_question retry loop
  • no_answer_found

This design reduces hallucination by forcing answer support checks before final output.

Notes

  • Retrieval source files are currently the PDFs in ./documents/.
  • Default embedding model: text-embedding-3-large
  • Default chat model: gpt-4o-mini
  • Tune MAX_RETRIES and MAX_REWRITE_TRIES in the notebook for stricter/looser behavior.

About

Self-RAG chatbot with LangGraph that retrieves from internal PDFs, verifies grounding (IsSUP), checks usefulness (IsUSE), and iteratively rewrites queries to improve answer quality.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors