GridWise: Explainable RAG Assistant for Energy Reports
Ask questions about public IEA reports and get answers cited to the exact page, with the passages used shown alongside. When the reports don't cover a question, it says so instead of guessing.
Solo project · 2026 · Python 3.11, FastAPI, Streamlit, ChromaDB, local LLM (qwen2.5:7b via Ollama)
Held-out set: 20 questions written after the configuration was frozen.
5/5
unanswerable questions declined
1 by the relevance threshold, 4 by the model
0/15
answerable questions wrongly declined
every answerable question got an answer
14/15
correct page among the top 4 retrieved passages
retrieval quality
12/15
answers judged fully correct
one LLM reviewer, human check in progress; 1 answer contained an invented number
Why I built it
RAG demos often hide two things: where an answer came from, and whether the retrieval setup was ever evaluated. GridWise makes both explicit. Every answer carries [Document, page N] citations, backed by the retrieved passages and their similarity scores. The chunk size, top-k and threshold were chosen by measurement, not guesswork. Every citation is checked automatically against the passages that were actually retrieved. That check proves where an answer points, not that it is true, so each answer was also reviewed one by one.
"Explainable" here means source transparency: which passages and pages an answer used. It does not explain the model's internal reasoning.
How it works
Ingestion
- PDF reports
- Per-page extraction (PyMuPDF)
- Clean + chunk (400 chars, 80 overlap)
- Local embeddings (all-MiniLM-L6-v2)
- ChromaDB
Query
- Question
- Embed
- Cosine top-4 + threshold 0.50
NOTHING ABOVE THRESHOLD
Fixed “not covered” reply, no LLM call
PASSAGES ABOVE THRESHOLD
- LLM with strict grounding prompt
- Citation check against retrieved sources
- FastAPI /ask
- Streamlit UI (answer + source cards)
Key decisions
Two layers against made-up answers
A relevance threshold refuses off-topic questions without calling the LLM. If passages get through, the model must reply INSUFFICIENT_EVIDENCE when they don't answer the question.
Citation validity, kept separate from truth
Citations are parsed from the answer and compared to the sources actually returned. The API reports citation validity and refusal as separate fields, and marks claim-level support as "not evaluated" rather than implying it.
Headers removed by repetition, not by string matching
Running headers and footers are found as lines near page edges that recur across pages. Every dropped page is logged at ingest.
No LangChain / LlamaIndex
The pipeline is small enough that the code is the documentation. Transparency is the point.
ChromaDB and local embeddings
One persistent store holds the document, page and chunk metadata. The index rebuilds reproducibly at no API cost.
Evaluation
44 tuning questions (35 answerable, 9 unanswerable) were used to choose the configuration. After that was frozen, 20 held-out questions (15 answerable, 5 unanswerable) were written and reported exactly as they came out, with nothing tuned afterwards. The held-out numbers are the headline; the tuning numbers are optimistic because they chose the setup.
| Chunk / overlap | Chunks | Right page at rank 1 | In top 4 | MRR@4 |
|---|---|---|---|---|
| 400 / 80 (chosen) | 812 | 28/35 | 32/35 | 0.84 |
| 800 / 150 | 406 | 25/35 | 32/35 | 0.80 |
| 1200 / 200 | 274 | 22/35 | 31/35 | 0.75 |
| Metric | Tuning set | Held-out |
|---|---|---|
| Right page at rank 1 | 28/35 | 12/15 |
| Right page in top 4 | 32/35 | 14/15 |
| MRR@4 | 0.84 | 0.87 |
| Answered with valid citations incl. the correct page | 28/35 | 14/15 |
| Answerable questions declined | 3/35 | 0/15 |
| Unanswerable refused by threshold (no LLM call) | 7/9 | 1/5 |
| Unanswerable declined by the model | 2/9 | 4/5 |
| Unanswerable answered anyway | 0/9 | 0/5 |
These are small, self-authored samples; they cannot establish reliable population-level performance. On the held-out set 800/150 was one question better than 400/80, so the evidence doesn't single out one best chunk size. The consistent pattern is that 1200/200 ranks worst.
Limitations and next steps
Limitations
- Claim-level support is not checked automatically. The API reports it as "not evaluated".
- The relevance threshold stops off-topic questions but not near-misses. Those are stopped by the model declining (4 of 5 on the held-out set).
- Tables and "list everything" questions retrieve poorly; there is no table-aware extraction yet.
- The test sets are small and written by me, and the correctness grades come from a single LLM reviewer (a human check is in progress).
- One model (qwen2.5:7b, temperature 0) and three IEA reports.
Next steps
- First experiment: retrieve small chunks plus their neighbouring chunks, which targets the solar-jobs failure directly, and compare it against the current baseline before adding anything else.
- Keep the inspected held-out failures as regression cases, and write a fresh question set to evaluate the next version.
- Only then: hybrid keyword + vector search, a reranker, and an automated claim-level check, each measured on its own.
Stack
- Python 3.11
- FastAPI
- Streamlit
- ChromaDB
- Sentence Transformers
- PyMuPDF
- Ollama (qwen2.5:7b)
- pytest (135 tests)
- Ruff