A question-answering assistant about the electric power grid. It searches a small library of Wikipedia articles, then has a language model write an answer that cites its sources.
Live demo: https://grid-guide-m2sysqrhzlaazenuso57t6.streamlit.app/
Measured with python -m ragbot.evaluate on October 21, 2026.
| Measure | Result |
|---|---|
| Knowledge base | 16 articles, 482 chunks, about 85,588 words |
| Test questions with a known answer | 20 |
| Right article is the top result | 70% |
| Right article is in the top 4 | 100% |
| Mean reciprocal rank | 0.83 |
| Median search time | 0.4 ms |
| Off-topic questions refused by search | 4 of 4 |
ragbot/fetch.pydownloads the articles through Wikipedia's public API.ragbot/chunking.pycuts each article into 180-word pieces that overlap by 40 words.ragbot/search.pybuilds a TF-IDF index and returns the best-matching pieces for a question.ragbot/answer.pysends those pieces, numbered, to Claude (Haiku, set inragbot/config.py) with instructions to answer only from them and cite each fact.ragbot/evaluate.pyscores the search against 24 test questions: 20 with a known source article and 4 off-topic.app.pyis the Streamlit chat page.
If the search finds nothing relevant, the assistant says so without calling the model. If no API key is set, it runs in search-only mode and shows the best passage.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
pip install -r requirements.txt
python -m ragbot.fetch
python -m ragbot.evaluate
streamlit run app.py
Set ANTHROPIC_API_KEY in your environment to get written answers.
pytest
22 tests cover file handling, chunk overlap, search ranking, the off-topic refusal, and the prompt. The model is replaced by a stand-in during tests, so they need no key and cost nothing.
- Search matches words, not meaning. A question phrased with different vocabulary than the article can miss.
- Each question is answered on its own; the assistant does not remember earlier turns.
- The knowledge base is 16 articles and is only as accurate as those articles.
- The evaluation checks whether the right article is retrieved, not the exact passage or the quality of the written answer.
The code is MIT licensed (see LICENSE). Article text comes from Wikipedia and is licensed CC BY-SA 4.0; each answer links to its source articles.