PDF RAG app
Personal project
Ask a question about a long PDF, like a report, a manual or a set of rules, and get an answer with the page numbers it came from.
Built withPython, LangChain, OpenAI API, FAISS, PyPDF
CodeGitHub
The idea
Most documents are too long to paste into a language model. This app only sends the parts that matter, so answers stay grounded in the document and you can look up the pages yourself.
How it works
- Split. The PDF is read page by page and split into chunks of 500 characters that overlap a little so sentences aren't cut in half.
- Index. Each chunk becomes an embedding and goes into a local FAISS index.
- Answer. Your question pulls out the four most relevant chunks, and the model answers from those, listing the pages it used.
$ python main.py report.pdf Your question: What is the main topic of this document? Answer: ... Sources used: 4 chunk(s) [1] Page 2: ... [2] Page 5: ...
Run it yourself
It runs in the terminal with your own OpenAI key, so there's no public demo.
git clone https://github.com/mbilal1005/pdf-rag-app cd pdf-rag-app pip install -r requirements.txt export OPENAI_API_KEY="sk-..." python main.py path/to/your.pdf