All projects

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

  1. PDF reports
  2. Per-page extraction (PyMuPDF)
  3. Clean + chunk (400 chars, 80 overlap)
  4. Local embeddings (all-MiniLM-L6-v2)
  5. ChromaDB

Query

  1. Question
  2. Embed
  3. Cosine top-4 + threshold 0.50

NOTHING ABOVE THRESHOLD

Fixed “not covered” reply, no LLM call

PASSAGES ABOVE THRESHOLD

  1. LLM with strict grounding prompt
  2. Citation check against retrieved sources
  1. FastAPI /ask
  2. 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.

Choosing the chunk size (tuning set, 35 answerable, retrieval only)
Chunk / overlapChunksRight page at rank 1In top 4MRR@4
400 / 80 (chosen)81228/3532/350.84
800 / 15040625/3532/350.80
1200 / 20027422/3531/350.75
Tuning set vs held-out (400/80)
MetricTuning setHeld-out
Right page at rank 128/3512/15
Right page in top 432/3514/15
MRR@40.840.87
Answered with valid citations incl. the correct page28/3514/15
Answerable questions declined3/350/15
Unanswerable refused by threshold (no LLM call)7/91/5
Unanswerable declined by the model2/94/5
Unanswerable answered anyway0/90/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

Corpus: three public IEA reports (Critical Minerals Review of Norway 2026; Ensuring a Skilled Renewable Energy and Energy Efficiency Workforce; Household Energy Affordability). The reports are © IEA. This project is not affiliated with the IEA.

All projects