PDF Q&A Bot (RAG System)
RAG bot that answers questions about any PDF with page citations, using FAISS and local embeddings.
2 min read
Drop in a PDF (contract, research paper, manual), ask questions in plain English, get answers with page citations.
How it works
generate_sample_pdf.pywrites a small fictional employee handbook so the bot has something to ingest without needing a real document.ingest.pyextracts text per page (pypdf), splits it into overlapping chunks (langchain-text-splitters), embeds each chunk with a localsentence-transformersmodel (no API key needed), and stores the vectors in a FAISS index alongside the chunk text + page number.query.pyembeds the question, retrieves the top-k nearest chunks, and generates an answer. It tries OpenAI (ifOPENAI_API_KEYis set), then a local Ollama server (if running onlocalhost:11434), then falls back to returning the retrieved passages verbatim with their page citations, so the app fully answers questions with zero LLM configured.app.pyis the Streamlit UI: upload a PDF, ask questions, see the answer plus the exact passages/pages it came from.
Run it
pip install -r requirements.txt
python generate_sample_pdf.py # writes sample_docs/handbook.pdf
python test_ingest.py # smoke test: ingest + retrieve the right page
streamlit run app.py
To get LLM-composed (rather than extractive) answers, set OPENAI_API_KEY
or run Ollama locally (ollama serve + ollama pull llama3) before asking
questions.
Skipped: LlamaIndex/ChromaDB and a re-ranker. FAISS + sentence-transformers covers the same retrieval job with fewer moving parts. Add a re-ranker (e.g. cross-encoder) if retrieval precision on longer documents needs it.
Support
Submit issues, questions, or bug reports to the GitHub issue tracker: https://github.com/ADM1SH/pdf-qa-rag-bot/issues
Roadmap
- Done: Core architecture and baseline implementation.
- Done: Functional verification and test coverage.
- To do: Add multi-vector dense retrieval
- To do: Integrate citation page thumbnail rendering
Contributing
Contributions are welcome.
- Fork the repository.
- Create a feature branch:
git checkout -b feature/improvement. - Commit your changes:
git commit -m "feat: enhance functionality". - Push to the branch:
git push origin feature/improvement. - Open a Pull Request.
Authors and Acknowledgment
- Adam Anwar (ADM1SH) - Lead architect and developer.
- Built by Adam Anwar using FAISS vector indexing and Hugging Face sentence embeddings.
License
Licensed under the MIT License. See LICENSE for details.
Project Status
Working document retrieval and question answering bot.