Adaptive RAG is an AI-powered chatbot that can answer questions from your own uploaded documents. You can upload a PDF or text file, ask questions about it, and the system will find the most relevant answers.
It smartly decides whether to answer from your uploaded documents, use its general knowledge, or search the web in real time — all automatically.
- Upload Documents: Upload PDF or TXT files and chat with them
- Smart Query Routing: Automatically picks the best way to answer your question
- Web Search: Can search the web for real-time information when needed
- Chat History: Remembers your conversation using MongoDB
- Simple Web UI: Easy-to-use chat interface built with Streamlit
- REST API: FastAPI backend with clean endpoints
| Component | Technology |
|---|---|
| Language | Python 3.9+ |
| AI Framework | LangChain + LangGraph |
| Backend API | FastAPI |
| Frontend UI | Streamlit |
| Vector Database | Qdrant |
| Chat Database | MongoDB |
| LLM Provider | OpenAI (GPT-4o) |
| Web Search | Tavily |
Make sure you have the following installed and ready:
- Python 3.9 or higher
- MongoDB (local or cloud)
- Qdrant vector database
- OpenAI API key
- Tavily API key (for web search)
# Clone the repository
git clone https://github.com/YOUR_USERNAME/Adaptive-Rag.git
cd Adaptive-Rag
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtCreate a .env file in the root folder and add your keys:
OPENAI_API_KEY=your_openai_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here
QDRANT_URL=http://localhost:6333
QDRANT_API_KEY=your_qdrant_api_key
QDRANT_CODE_COLLECTION=code_documents
QDRANT_DOCS_COLLECTION=documents
MONGODB_URL=mongodb://localhost:27017
MONGODB_DB_NAME=adaptive_ragOpen two terminals:
Terminal 1 — Start the backend:
python -m uvicorn src.main:app --reload --host 0.0.0.0 --port 8000Terminal 2 — Start the frontend:
streamlit run streamlit_app/home.pyThen open your browser:
- Chat App: http://localhost:8501
- API Docs: http://localhost:8000/docs
- Go to http://localhost:8501
- Create an account or log in
- Upload a PDF or TXT file from the sidebar
- Start asking questions in the chat!
AdaptiveRag/
├── src/ # Main backend code
│ ├── main.py # FastAPI app entry point
│ ├── api/routes.py # API endpoints
│ ├── rag/ # RAG pipeline logic
│ │ ├── graph_builder.py # LangGraph workflow
│ │ ├── nodes.py # Pipeline steps
│ │ └── document_upload.py # Document processing
│ ├── memory/ # Chat history
│ ├── models/ # Data schemas
│ └── tools/ # Utility functions
│
├── streamlit_app/ # Frontend UI
│ ├── home.py # Login page
│ └── pages/chat.py # Chat interface
│
├── requirements.txt # Python dependencies
└── README.md # This file
POST /rag/query
Content-Type: application/json
{
"query": "What is the document about?",
"session_id": "user_123"
}POST /rag/documents/upload
X-Description: Brief description of the document
Form Data:
- file: <your PDF or TXT file>- Developed in collaboration with Dhruv Singhal (@dhruvsinghal09)
- Built using LangChain and LangGraph
- Vector search by Qdrant
- LLM by OpenAI
- Web search by Tavily
Parth Dangaria
This project is licensed under the MIT License.