Skip to content

An end-to-end RAG chatbot using FastAPI, LangChain, ChromaDB & Streamlit with Multi-LLM support to answer questions from uploaded PDFs.

License

Notifications You must be signed in to change notification settings

Zlash65/rag-bot-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👽 RAG PDFBot - V3 (FastAPI + Streamlit)

This is the production-ready refactor of rag-bot-chroma, introducing a real separation between frontend (UI) and backend (logic) using Streamlit and FastAPI respectively. This modular architecture helps in scaling, extending, and deploying the bot in real-world environments.


🔗 Helpful Links

🔄 What Changed from rag-bot-chroma

Feature Version 2 Version 3
Codebase One Streamlit app Split into client/ + server/
PDF Upload In Streamlit Async FastAPI API
Chat In Streamlit Calls /chat API
Vectorstore In UI Controlled by backend
Model Options Static Dynamically fetched
Inspector In sidebar Main panel toggle
Splitting RecursiveTextSplitter TokenTextSplitter
UX Crude Responsive, clear, downloadable
Extendability Hard Easy to plug new LLMs, tools

🧪 How It Looks

Demo

demo-gif


🏗️ Architecture

architecture


🚀 Features

  • 📁 Upload multiple PDFs and chat with them
  • 🔌 Choose from Groq or Gemini as LLM providers
  • 🔎 Query inspector for vectorstore transparency
  • 🧠 RAG with LangChain + ChromaDB
  • 📦 Streamlit frontend, FastAPI backend
  • 🧪 Token-based chunking for LLM precision
  • 💬 Downloadable chat history
  • 🧰 Tools for reset, undo, clear
  • 🌐 Fully API-driven interaction

🛠️ Tech Stack
  • Frontend: Streamlit
  • Backend: FastAPI
  • LLMs: Groq & Gemini via LangChain
  • Vector DB: ChromaDB
  • Embeddings: HuggingFace & Google GenAI
  • Chunking: TokenTextSplitter (was RecursiveCharacterTextSplitter)
  • Parsing: PyPDF
  • Orchestration: LangChain Retrieval Chain

📦 Installation

git clone https://github.com/Zlash65/rag-bot-fastapi.git
cd rag-bot-fastapi

Setup Virtual Environment:

python3 -m venv venv
source venv/bin/activate

Install frontend:

cd client
pip3 install -r requirements.txt

Install backend:

cd ../server
pip3 install -r requirements.txt

🔐 API Keys Required

Create a .env file:

GROQ_API_KEY=your-groq-key
GOOGLE_API_KEY=your-google-key

▶️ Run the Bot

Start FastAPI backend:

# Terminal 1
cd server
uvicorn main:app --reload

Start Streamlit frontend:

# Terminal 2
cd client
streamlit run app.py

📁 Project Structure
rag-bot-v3/
├── client/                         # Streamlit Frontend
│   ├── app.py                      # Main Streamlit entrypoint
│   ├── components/                 # UI modules
│   │   ├── chat.py
│   │   ├── inspector.py
│   │   └── sidebar.py
│   ├── state/
│   │   └── session.py              # Session state manager
│   ├── utils/
│   │   ├── api.py                  # Talks to backend
│   │   ├── config.py               # API_URL and config values
│   │   └── helpers.py              # API wrappers for frontend
│   ├── requirements.txt
│   └── README.md

├── server/                         # FastAPI Backend
│   ├── api/
│   │   ├── routes.py               # API endpoints
│   │   └── schemas.py              # Pydantic schemas for I/O
│   ├── core/
│   │   ├── document_processor.py   # Handles PDF validation and chunking
│   │   ├── llm_chain_factory.py    # Builds LLM chains and prompts
│   │   └── vector_database.py      # Embeddings + ChromaDB ops
│   ├── config/
│   │   └── settings.py             # App config, model provider setup
│   ├── utils/
│   │   └── logger.py               # Logging setup
│   ├── main.py                     # FastAPI app entrypoint
│   ├── requirements.txt
│   └── README.md

├── README.md                       # Root README (overview + instructions)
├── .gitignore

👓 Different Views
View Description
💬 Chat Renders chat bubbles, input box, and chat history download
🔬 Inspector Renders inspector to test vectorstore responses

views


🧼 Tools Panel
Button Function
🔄 Reset Clears session state and reruns app
🧹 Clear Chat Clears chat + PDF submission
↩️ Undo Removes last question/response

📦 Download Chat History

Chat history is saved in the session state and can be exported as a CSV with the following columns:

Question Answer Model Provider Model Name PDF File Timestamp
What is this PDF about? This PDF explains... Groq llama3-70b-8192 file1.pdf, file2.pdf 2025-07-03 21:00:00

🙏 Acknowledgements

🧠 New to this Project?

Start from the basics: 👉 Version 1 - rag-bot-basic

Understand modular design: 👉 Version 2 - rag-bot-chroma

Then return here for real-world patterns.


Happy building! 🛠️

About

An end-to-end RAG chatbot using FastAPI, LangChain, ChromaDB & Streamlit with Multi-LLM support to answer questions from uploaded PDFs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages