| title | emoji | colorFrom | colorTo | sdk | app_file | pinned |
|---|---|---|---|---|---|---|
Adaptive RAG Chat |
๐ง |
yellow |
red |
streamlit |
app.py |
false |
An adaptive Retrieval-Augmented Generation (RAG) system that dynamically routes queries between vector search and web search for accurate, grounded answers.
โจ Features โข ๐๏ธ Architecture โข ๐ Quick Start โข ๐ฌ How It Works โข ๐ Project Structure
Adaptive-RAG is a production-oriented RAG pipeline built using LangChain and LangGraph that intelligently decides how to retrieve information before generating an answer.
Instead of relying on a single data source, the system:
- Routes questions to a local FAISS vectorstore when internal knowledge is sufficient
- Falls back to web search (Tavily) when information is missing or outdated
- Grades retrieved documents and generated answers
- Automatically rewrites queries when retrieval quality is poor
This results in more accurate, less hallucinated, and context-aware answers.
The Problem: Traditional RAG systems blindly retrieve documents from a vectorstore, even when:
- The question is out of domain
- Knowledge is outdated
- Retrieval quality is poor
This leads to hallucinations or incomplete answers.
My Goal: Build a self-correcting RAG pipeline that can:
- Decide where to retrieve from
- Judge how good the retrieval is
- Improve itself by rewriting queries when needed
Key Learning: LangGraph is ideal for building conditional, feedback-driven RAG workflows instead of linear chains.
-
Adaptive Routing Automatically selects between vectorstore retrieval and web search.
-
Retrieval Grading Evaluates whether retrieved documents are relevant to the query.
-
Hallucination Detection Grades generated answers against retrieved context.
-
Query Rewriting Reformulates weak questions to improve retrieval quality.
-
Graph-based Control Flow Uses LangGraph for explicit decision-making and retry loops.
-
Interactive UI Streamlit app for real-time querying and visualization.
User Query
โ
โผ
Router Node
(Vectorstore or Web?)
โ
โโโโบ Vectorstore Retrieval (FAISS)
โ
โโโโบ Web Search (Tavily)
โ
โผ
Document Grader
โ
โโโ Relevant โ Answer Generator
โ
โโโ Not Relevant โ Query Rewriter
โ
โโโ Loop Back to Router
LangGraph enables:
- Conditional edges
- Feedback loops
- Explicit state transitions
- Clean separation of logic
A router node decides whether the query should go to:
- Vectorstore (domain-specific questions)
- Web Search (open-ended or current topics)
- Vectorstore uses FAISS embeddings
- Web search uses Tavily API
LLM-based graders check:
- Document relevance
- Answer grounding
- Hallucination risk
If retrieval is weak, the query is rewritten and re-routed automatically.
| Component | Technology |
|---|---|
| Orchestration | LangGraph |
| RAG Framework | LangChain |
| Vector Store | FAISS |
| Web Search | Tavily |
| LLM | Groq (Llama 3.3) |
| UI | Streamlit |
| Language | Python |
- Python 3.10+
- Groq API key
- Tavily API key
Create a .env file:
GROQ_API_KEY=your_groq_key
TAVILY_API_KEY=your_tavily_key
pip install -r requirements.txtstreamlit run app.pyOn first run:
- A FAISS index is built
- Cached under
data/index/faiss_index
.
โโโ app.py # Streamlit UI that invokes the LangGraph workflow
โโโ requirements.txt # Python dependencies
โโโ src/
โ โโโ graphs/graph_builder.py # FAISS index + retriever setup
โ โโโ llms/llm.py # RAG prompt and LLM chain
โ โโโ nodes/node_implementation.py # Router, retrieve, web_search, graders, transform
โ โโโ states/state.py # Graph state + compile (app)
โโโ data/faiss_index/ # Vectorstore cache (created at runtime)
- Create a new Space: choose SDK "Streamlit".
- Push this repository to the Space (or connect via GitHub).
- In the Space Settings โ Secrets, add:
GROQ_API_KEY: your Groq keyTAVILY_API_KEY: your Tavily key
- The app auto-builds using
requirements.txtand runsapp.py. - Optional: users can also paste keys in the sidebar if Secrets are not set.
Notes:
- First run may build a FAISS index and cache under
src/data/faiss_index/. - If web search is disabled (missing Tavily key), queries will route to the vectorstore.
- Not a basic RAG demo
- Uses decision-making and self-correction
- Demonstrates real LangGraph value
- Clean separation of concerns
- Directly aligned with industry GenAI systems
This is the kind of RAG system used in:
- Enterprise knowledge assistants
- AI support bots
- Research copilots
- Internal search tools
- Multi-vector routing (code, docs, FAQs)
- Tool-augmented RAG
- Caching and latency optimization
- Confidence-based answer refusal
- Evaluation dashboards
Vivek Kumar Gupta AI Engineering Student | GenAI & Agentic Systems Builder
- GitHub: https://github.com/vivek34561
- LinkedIn: https://linkedin.com/in/vivek-gupta-0400452b6
- Portfolio: https://resume-sepia-seven.vercel.app/
MIT License ยฉ 2025 Vivek Kumar Gupta