Three problems I wanted to solve.
Retrieval-augmented generation (RAG) lets a language model answer from a specific set of documents instead of from memory. Tutorials make it look simple, but three problems usually get skipped.
AI assistants make things up
A model will answer confidently even when it has nothing to go on. With company documents, a wrong answer that sounds right is worse than no answer. I wanted an assistant that shows its evidence and says so when it has none.
Some documents can't leave the building
Contracts, handbooks and client files often can't be sent to a third-party API. So everything runs locally, including both AI models and the search index.
Demos break when used for real
Most examples stop once the first answer works. I wanted to cover what comes after: failure recovery, start-up checks, automated tests and measured quality.
What a user sees.
The app is a simple web interface. Behind it is a pipeline that I designed so each step can be checked and tested on its own.
Ask questions in plain language
A chat interface built with Streamlit. It shows each step as it happens: searching, checking the evidence, answering.
Answers show their source
Every answer includes the source link and the exact excerpt it came from, so a person can verify it in seconds.
An honest “I don't know”
If the documents don't support an answer, the assistant declines instead of guessing.
Upload PDFs
Text is extracted on the machine and cited down to the page. Uploading the same file twice is detected and skipped.
A readiness check
One command confirms the configuration, documents, local AI server, models and index are all ready, and explains what to fix if not.
Configured without code changes
Models, chunk sizes, search limits and thresholds are set in a .env file.
Adding documents can't break the working system.
Before the assistant can search documents, it splits them into chunks and converts each chunk into an embedding, a numeric representation stored in a vector database. That process can fail partway through, for example on a corrupt file or when the model server stops.
Upload
JSONL records or text PDFs, up to 20 MB each
Extract
Page text read locally; original file not kept
Validate
Every record checked before indexing
Chunk
1,000 characters, 200 overlapping
Embed → staging
Built in a separate, temporary index
Swap in
Replaces the live index only on full success
Why it matters: the new index is built separately and swapped in only once the whole build succeeds. If anything fails, the previous documents and index are restored, so users never search a half-built index.
It checks the evidence before it answers.
A basic RAG app retrieves some text and asks the model to answer from it, whether or not that text is relevant. I added an agent step: a separate judgement of whether the evidence actually supports an answer. If it doesn't, the agent rewrites the search once and tries again. If the evidence is still weak, it declines.
Only one retry
An agent that keeps retrying can loop, slow down and use unpredictable compute. One retry keeps the behavior predictable and testable.
The judgement outranks the similarity score
Text can look similar to a question without answering it. A high search score never overrides an “insufficient evidence” verdict.
Citations the model can't invent
Source links come from the stored document records, not from the model's text, so the assistant can't cite a page that doesn't exist.
Clear progress without internal reasoning
The interface shows what the agent is doing without exposing the model's internal reasoning.
Decisions I made, and what each one costs.
Every design choice has a downside. I wrote them down so the reasoning behind each choice can be reviewed along with the result.
| Decision | What it gives | What it costs |
|---|---|---|
| Local models (Ollama) | Private, works offline, no per-request fees | Speed and answer quality depend on the hardware |
| Chroma vector database | Simple to run, persists on disk | Single machine; not built for many users at once |
| Evidence check before answering | Retry and decline behavior can be tested | One extra model call per question |
| At most one retry | No loops or unpredictable delays | A second attempt might occasionally find an answer |
| Citations from stored records | Sources can't be invented | Still only as good as the search results |
| Rebuild, then swap | A failed update never breaks the working index | Needs temporary extra disk space |
| Page-level PDF extraction | Uploads are searchable right away, with page citations | Scanned PDFs need OCR first |
How I checked that it works.
I built an evaluation tool that asks the assistant questions with known answers and scores the results. It fails the run if any score drops below a set threshold, and records the model versions and settings so runs can be compared.
The release run below used six questions. Four have answers in the documents and two deliberately don't. It shows the guardrails behave as designed; it doesn't claim general accuracy, which would need a much larger question set.
# download the two local models $ ollama pull mxbai-embed-large $ ollama pull llama3.2:3b # check that everything is ready $ python -m local_rag.readiness # build the index, then start the app $ python -m local_rag.ingestion $ streamlit run app.py
Automated checks on every change
What this project shows, and what comes next.
Skills demonstrated
Building AI applications
Retrieval, embeddings, agent flows and guardrails against hallucinated answers.
Measuring AI quality
An evaluation tool with defined metrics, thresholds and reproducible reports.
Reliable data pipelines
Validation, isolated builds, rollback on failure and duplicate detection.
Software engineering practice
Automated tests, CI on two operating systems, clear docs, and tradeoffs written down.
Known limits and next steps
Want to see the details or talk about a project?
The full source, documentation and evaluation records are on GitHub. I'm open to roles and freelance work building practical AI tools.