AskMyPDF is a Flask-based PDF Question Answering (RAG) web application that allows users to upload a PDF and ask questions about its content. The system answers only from the uploaded PDF, using semantic search and a local LLM, with clear source page references.
- 📤 Upload a PDF file
- 🧠 Semantic search over PDF content (vector embeddings)
- 💬 Chat-style interface (Instagram / WhatsApp style)
- 📚 Answers strictly grounded in the PDF (no hallucination)
- 📄 Source page references for each answer
- 🔄 Reset session (PDF + chat)
- ⚡ No page reloads (AJAX / Fetch API)
- 🔐 Session-based chat memory
- 🧠 Local LLM inference (no OpenAI key required)
This project follows a Retrieval-Augmented Generation (RAG) architecture:
PDF → Text Extraction → Chunking → Embeddings → Vector DB (Chroma)
↓
User Question → Semantic Search → Relevant Chunks → LLM → Answer
| Layer | Technology |
|---|---|
| Backend | Flask (Python) |
| Frontend | HTML, CSS, JavaScript |
| Templating | Jinja2 |
| Vector DB | ChromaDB |
| Embeddings | Sentence-Transformers (MiniLM) |
| LLM | Ollama (Gemma 3) |
| PDF Parsing | PyMuPDF |
| Session Storage | Flask Sessions |
askmypdf/
├── app.py # Flask application
├── rag.py # RAG pipeline (index + retrieval + LLM)
├── uploads/ # Uploaded PDF files
├── chroma_store/ # Persistent vector database
├── templates/
│ ├── base.html
│ └── index.html
├── static/
│ ├── style.css
│ └── app.js
├── config/
│ └── .env
├── screenshots/ # Application screenshots
│ └──01-home-empty.png
│ └──02-upload-pdf.png
│ └──03-chat-question.png
│ └──04-chat-answer.png
│ └──05-multiple-qa-demo.png
│ └──06-qa-proof-mywalletpro-tech-page2.png
│ └──07-negative-queries-not-in-pdf.png
│ └──08-reset-state.png
├── .gitignore
├── LICENSE
├── requirements.txt
└── README.md
- User uploads a PDF
- PDF text is extracted using PyMuPDF
- Text is split into overlapping chunks
- Each chunk is converted into a vector embedding
- Vectors are stored in ChromaDB
- User asks a question
- Most relevant chunks are retrieved using semantic similarity
- LLM verifies if the answer exists in the PDF
- LLM generates a final answer only from the PDF
- Source page numbers are returned
- LLM is not allowed to use outside knowledge
- A verification step checks whether the answer exists in the retrieved text
- If not found, the system replies:
Answer is not in this PDF.
- Chat bubbles (user → right, assistant → left)
- Smooth scrolling chat
- Fixed bottom input bar
- 🎤 Voice input (speech-to-text)
- Status messages (uploading, thinking, done)
- PDF name badge in navbar
- Reset button clears PDF + chat without reload
git clone https://github.com/khaledelsayed2003/askmypdf.git
cd askmypdfpython -m venv venv
source venv/bin/activate # macOS / Linux
venv\Scripts\activate # Windowspip install -r requirements.txtDownload from: 👉 https://ollama.com
Pull the model:
ollama pull gemma3:4bCreate config/.env:
FLASK_SECRET_KEY=your-secret-keypython app.pyOpen in browser:
http://127.0.0.1:5000
-
Upload a PDF (CV, paper, report, book)
-
Ask:
- “What programming languages are listed?”
- “What is the project objective?”
- “Who is the author?”
-
Get:
- A concise answer
- Exact source page(s)
-
Clears:
- Uploaded PDF
- Vector collection
- Chat history
-
UI resets instantly (no reload)
This section demonstrates the full workflow of AskMyPDF, from uploading a document to asking questions, validating answers, handling unsupported queries, and resetting the session.
When the application starts, no document is loaded. The user is prompted to upload a PDF before asking any questions.
The user uploads a PDF file, which is:
- Saved locally
- Indexed into a vector database (ChromaDB)
- Prepared for semantic search
Once a PDF is uploaded, the user can ask questions using a chat-style interface. User messages appear on the right, similar to modern messaging apps.
The assistant retrieves relevant content from the PDF and generates an answer. Each answer includes the exact source page number(s) + it might give also the source page for the second highest retrieved vector.
Users can ask multiple questions without reloading the page. The full conversation history is preserved until reset.
This example demonstrates that the answer is:
- Correct
- Present in the PDF
- Referenced with the correct page number
Example shown: MyWallet Pro technologies on page 2.
If a question is not answered explicitly in the PDF, the system responds with:
"Answer is not in this PDF."
This ensures the assistant never fabricates information.
The reset button:
- Clears the uploaded PDF
- Deletes the vector index
- Clears chat history
- Returns the app to its initial state
- Works with text-based PDFs (not scanned images)
- Large PDFs may take longer to index
- Requires local LLM (Ollama) to be running
- 📑 Multi-PDF support
- 🔍 Highlight answer text inside PDF
- 📊 Confidence scoring
- 🌐 Deployment (Docker / Cloud)
This project is licensed under the MIT License. You are free to use, modify, and distribute it.
Khaled Elsayed
- 📧 Email: khaled.elsayed2206@gmail.com
- 🧠 Built for learning, research, and real-world RAG systems







