[03] AI · case study
PDF Q&A
Drop in a PDF and ask it questions in plain English. Every answer comes with the passages it was based on, so you can check it.
What it does
Upload a PDF of up to about 200 pages and ask anything about it. The app finds the parts of the document that matter for your question, hands them to an LLM and shows the answer next to the exact chunks it used.
It also remembers the conversation, so follow-up questions work the way you'd expect.
How it works
- readPulls the text out of the PDF with PyPDF2 and cleans it up.
- splitCuts it into ~1000-character chunks with 200 characters of overlap, breaking on sentence boundaries so ideas don't get cut in half.
- embedTurns every chunk into a 384-dimension vector with a small sentence-transformers model (MiniLM).
- indexStores the vectors in a FAISS index for exact similarity search.
- searchEmbeds the question the same way and pulls the 3 closest chunks.
- answerSends those chunks and the question to Llama 3.3 70B through the Groq API, then shows the answer with its sources.
The code is split into small modules that each do one job: config, PDF processing, chunking, embeddings, the vector store, retrieval, LLM calls and one that ties them together.