AI · Retrieval-Augmented Generation
RAG Document-Chat App
An "Ask my documents" assistant that answers questions from a private library of PDFs — physics, philosophy, language and security essays — with grounded, cited answers, and politely refuses anything the documents don't cover.
Overview
This is a full retrieval-augmented generation (RAG) pipeline I built end to end — from PDF ingestion to a deployed API to the chat widget embedded on this very site (look for the bubble in the corner). It turns a folder of documents into a question-answering assistant that only answers from those documents and always shows where each answer came from.
What it does
📌 Grounded & cited
Every answer is built from retrieved passages and returns citations, so you can trace each claim back to the source document.
🚧 Stays on topic
If the documents don't cover a question, it says so rather than hallucinating — verified against off-topic prompts.
🔁 Resilient
Automatic retry with backoff and model fallback handle free-tier rate limits and transient 503s gracefully.
💰 Cost-guarded
Per-minute rate limiting and a daily cap protect the API budget, since the edge can't enforce CORS on the host.
How it works
- Ingest: 19 PDFs are parsed and split into 365 overlapping text chunks.
- Embed: each chunk becomes a 3072-dimension vector via Gemini
gemini-embedding-001(resumable, cached for free-tier throttling). - Retrieve: a question is embedded and matched to the closest chunks by NumPy cosine similarity.
- Generate:
gemini-2.5-flashwrites a grounded answer from those chunks, with citations. - Serve: a FastAPI
/chatendpoint, containerised with Docker and deployed to Hugging Face Spaces. - Embed in site: a dependency-free JavaScript widget calls the API from this static site.