Technical case study
PDF RAG System
Upload a PDF and ask questions in natural language. The application retrieves relevant passages and sends them to Mistral to generate a context-grounded answer.

Overview
The application combines a PDF ingestion pipeline, a vector index, and a document-question interface. FastAPI serves the HTML frontend and exposes indexing, query, and document-management endpoints.
Problem
Keyword search works best when a reader already knows the terminology in a document. Sending a whole PDF to a language model can also exceed its context window.
Objective
Make uploaded PDFs queryable through the browser and API, with a way to narrow retrieval to a particular document.
My approach
I separated the system into PDF processing, vector storage, and a retrieval-and-generation pipeline. Uploads are indexed once. A query then searches the index and passes the relevant text to a hosted model.
Technology stack
- Python
- FastAPI
- LangChain
- ChromaDB
- SentenceTransformers
- Mistral AI
- Docker
- HTML
Architecture
-
PDF
Upload a PDF through the frontend or the FastAPI upload endpoint.
-
Processing
PyPDF extracts page text. LangChain splits the text into 500-character chunks with 50 characters of overlap.
-
Embeddings
SentenceTransformers all-MiniLM-L6-v2 encodes chunks locally as 384-dimensional vectors.
-
ChromaDB
Store vectors with their source text and metadata in a cosine similarity index.
-
Retrieval
Encode the question and search for the nearest text snippets. The API accepts a source filter and a configurable result count.
-
LLM
Assemble the question and retrieved passages and send the context to the hosted Mistral API.
-
Answer
Return the generated response through the query API and display it in the document interface.
Key engineering decisions
- Generate embeddings locally while using a hosted language model for response generation.
- Keep source metadata with each chunk so the query can be scoped to one PDF.
- Use a single HTML frontend served by FastAPI and provide Docker Compose for repeatable setup.
Implementation details
- Document routes upload, list, and delete indexed PDFs.
- The query API accepts a question, optional filename filter, and top-k setting.
- Separate modules own extraction and chunking, vector-store operations, and prompt generation.
Results and limitations
The repository documents an end-to-end implementation and API examples. It contains no quantitative retrieval or answer-quality evaluation. PDF extraction affects what can be indexed, and hosted Mistral generation requires network access and sends retrieved context to the provider.
Lessons learned
The chunks and metadata stored at ingestion determine what retrieval can answer later. Evaluate retrieval and generation separately so a poor answer can be traced to weak evidence or the model’s use of that evidence.