1. Work
  2. PDF Q&A Bot (RAG System)
  3. Docs

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

Source on GitHub

Drop in a PDF (contract, research paper, manual), ask questions in plain English, get answers with page citations.

How it works

  • generate_sample_pdf.py writes a small fictional employee handbook so the bot has something to ingest without needing a real document.
  • ingest.py extracts text per page (pypdf), splits it into overlapping chunks (langchain-text-splitters), embeds each chunk with a local sentence-transformers model (no API key needed), and stores the vectors in a FAISS index alongside the chunk text + page number.
  • query.py embeds the question, retrieves the top-k nearest chunks, and generates an answer. It tries OpenAI (if OPENAI_API_KEY is set), then a local Ollama server (if running on localhost: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.py is 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.

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature/improvement.
  3. Commit your changes: git commit -m "feat: enhance functionality".
  4. Push to the branch: git push origin feature/improvement.
  5. 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.

Back to top