An advanced Retrieval-Augmented Generation (RAG) system built with LangGraph, featuring:
- Adaptive RAG — Intelligent routing between vectorstore and web search
- Self RAG — Hallucination detection and answer quality verification
- Corrective RAG — Document relevance evaluation before generation
The system dynamically decides whether to use the vectorstore or web search based on the user's query.
Retrieved documents are evaluated for relevance before generating the final answer.
The generated response is checked to ensure it is grounded, relevant, and free from hallucinations.
- Python 3.13+
- Poetry (for dependency management)
- OpenAI API Key
- Tavily API Key (for web search)
git clone https://github.com/tinars/langgraph-rag-system.git
cd langgraph-rag-systempoetry installCopy the example environment file and add your API keys:
cp .env.example .envThen edit the .env file:
OPENAI_API_KEY=sk-...
TAVILY_API_KEY=tvly-...Load documents into the vector store:
poetry run python ingestion.pypoetry run python main.pylanggraph-rag-system/
├── graph/
│ ├── chains/ # LLM chains (grading, generation, etc.)
│ ├── nodes/ # Graph nodes (retrieve, generate, web_search, etc.)
│ ├── state.py # State definition
│ ├── consts.py # Constants
│ └── graph.py # Main graph construction
├── ingestion.py # Vector store ingestion
├── main.py # Entry point
├── graph.png # Graph visualization
├── pyproject.toml # Poetry configuration
└── README.md # This file
poetry run pytest . -s -vUser Question
↓
Router (Vectorstore or Web Search?)
↓
┌───────────┴───────────┐
│ │
Vectorstore Web Search
↓ ↓
Grade Documents │
↓ │
┌───┴───┐ │
│ │ │
Relevant Not Relevant ─┘
│ │
Generate Web Search → Generate
↓
Check Hallucination
↓
Check Relevance to Question
↓
Final Answer
- LangChain — Core LLM framework
- LangGraph — Graph-based workflow orchestration
- OpenAI GPT-4 — Language model
- Chroma — Vector database
- Tavily — Web search API
- HuggingFace Embeddings — Text-to-vector embedding model
MIT License — Free to use and modify.
Pull requests and issues are welcome!
his project was developed during a course to deepen my understanding through hands-on implementation and practical experimentation.
- GitHub: @tinars
- Email: tinarostami110@gmail.com
By Tina Rostami
