Skip to content

heiparth07/Adaptive-RAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Adaptive RAG - AI Chatbot

Python 3.9+ FastAPI LangGraph Qdrant

📋 About the Project

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.


✨ Features

  • 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

🛠️ Tech Stack

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

🚀 Getting Started

Prerequisites

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)

Installation

# 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.txt

Environment Setup

Create 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_rag

Running the App

Open two terminals:

Terminal 1 — Start the backend:

python -m uvicorn src.main:app --reload --host 0.0.0.0 --port 8000

Terminal 2 — Start the frontend:

streamlit run streamlit_app/home.py

Then open your browser:


💬 How to Use

  1. Go to http://localhost:8501
  2. Create an account or log in
  3. Upload a PDF or TXT file from the sidebar
  4. Start asking questions in the chat!

📁 Project Structure

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

🔌 API Endpoints

Ask a Question

POST /rag/query
Content-Type: application/json

{
  "query": "What is the document about?",
  "session_id": "user_123"
}

Upload a Document

POST /rag/documents/upload
X-Description: Brief description of the document

Form Data:
- file: <your PDF or TXT file>

🙏 Acknowledgments


👤 Author

Parth Dangaria


📄 License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors