A Retrieval-Augmented Generation (RAG) chatbot that lets you upload any PDF and ask questions about it. Answers are grounded in the document's content — not the model's general knowledge.
Built with Python, LangChain, FAISS, Flask, and the Gemini API.
- Upload — A PDF is split into overlapping text chunks using
RecursiveCharacterTextSplitter - Embed — Each chunk is converted into a vector embedding via Gemini's embedding model
- Index — Embeddings are stored in a FAISS similarity index for fast retrieval
- Retrieve — On a question, the top-k most relevant chunks are fetched from the index
- Generate — Retrieved chunks are injected into a grounded prompt sent to Gemini, which returns an answer based strictly on the document
The backend follows an object-oriented design with three domain classes, each with a single responsibility:
DocumentLoader → loads a PDF and splits it into chunks
VectorStoreService → embeds chunks and builds/queries the FAISS index
RAGChatbot → orchestrates retrieval + LLM generation
Flask exposes two REST endpoints:
POST /upload— accepts a PDF, indexes itPOST /ask— accepts a question, returns a grounded answer
rag-chatbot/
├── application.py # Flask app + domain classes
├── requirements.txt
├── .env.example
├── static/
│ └── css/
│ └── style.css
├── templates/
│ └── home.html
└── tests/
├── conftest.py # fixtures + mock pipeline
└── test_application.py # 8-case pytest suite
The test suite has 8 cases across 4 classes, with all external dependencies (Gemini API, FAISS, PDF parsing) replaced by monkeypatched fakes. This means tests run instantly, offline, and without any API key — only Flask routing and orchestration logic is under test.
pytest tests/ -vTest classes:
TestRoutes— verifies HTTP status codes and error shapes for all endpointsTestUploadFlow— checks that upload triggers indexing and loads the retrieverTestAskFlow— covers ask before/after upload, JSON and form-encoded inputTestDocumentLoaderUnit— unit test for the loader's chunking output
1. Clone and install dependencies
git clone https://github.com/MeghaMuskan/rag-chatbot.git
cd rag-chatbot
pip install -r requirements.txt2. Add your Gemini API key
cp .env.example .env
# Edit .env and add your key:
# GOOGLE_API_KEY=your_key_here3. Run the app
python application.pyVisit http://localhost:5000, upload a PDF, and start asking questions.
| Layer | Technology |
|---|---|
| Language | Python 3 |
| Web framework | Flask |
| LLM | Gemini 2.5 Flash (via LangChain) |
| Embeddings | Gemini Embedding 001 |
| Vector store | FAISS |
| PDF parsing | PyPDF + LangChain |
| Testing | pytest + monkeypatch |
"Designed and deployed a RAG document Q&A chatbot (LangChain · FAISS · Gemini API) with a 3-class OOP architecture separating document loading, vector indexing, and LLM orchestration; validated Flask routing logic via an 8-case pytest suite using monkeypatched fakes to eliminate external API dependencies."
Megha Muskan