Repository navigation
Evaluation
Read this first. Evaluation numbers in this project are a historical baseline produced before the move to Anthropic and DeepSeek. The generator model was not recorded in the result files; earlier project documents attribute runs to GPT-3.5-turbo and GPT-4-turbo. Retrieval metrics depend only on the retriever, the knowledge base and the test set. Grounding, attribution and latency figures depend on the generator and the host, are not comparable to the current default setup, and have not been re-run.
| Step | Script | What it does |
|---|---|---|
| 1 | generate_test_set.py |
Samples chunks across domains (seed 42), has the easy-tier model write one question per chunk, and adds 10 hand-written Kenya-specific questions. Writes test_set.json: 40 queries (30 generated, 10 hand-written), each with a ground-truth chunk ID |
| 2 | seed_interactions.py |
Sends every test query to a running server's /query (session ID eval_seed, 1.5 s apart, 60 s timeout) so verification results are logged |
| 3 | evaluate.py |
Computes retrieval metrics by calling the production retrieve(), and grounding and latency metrics by reading the log database directly. Writes results/evaluation_summary.txt and results/evaluation_report.json
|
Run the loop (the server must be running for step 2):
python evaluation/generate_test_set.py # overwrites test_set.json; skip to reuse the committed one
uvicorn app.main:app --host 127.0.0.1 --port 8000 &
python evaluation/seed_interactions.py
python evaluation/evaluate.pyCost: up to 30 question-generation calls plus 40 /query calls to your configured providers. evaluate.py reads the whole log database, so use a fresh DATABASE_URL if you want a clean run.
- Precision@K / Recall@K / MRR: whether the one ground-truth chunk appears in the top results. With a single ground-truth chunk per query, Precision@K and Recall@K are equal by construction.
- Source attribution: share of answers with inline citations.
- Mean grounding score and contradiction rate: from Grounding Verification.
- Estimated hallucination rate = 1 - mean grounding score. This is a proxy built on a heuristic, not a measured hallucination rate.
- Latency: from the log database, per endpoint.
From evaluation/results/evaluation_summary.txt, generated 2026-06-18, 30 retrieval queries and 64 verified interactions:
| Metric | Value | Original target |
|---|---|---|
| Precision@1 | 0.60 | n/a |
| Precision@3 | 0.7667 | 0.85 |
| Recall@5 | 0.7667 | 0.90 |
| MRR | 0.6833 | 0.80 |
| Source attribution | 0.75 | 0.90 |
| Mean grounding score | 0.7855 | n/a |
| Contradiction rate | 0.1094 | n/a |
/query latency, median / P95 |
5.5 s / 35.0 s | 5 s |
By domain: food_safety MRR 0.80 (n=15), nutrition MRR 0.57 (n=15). The targets come from the project proposal; all but the Kenya domain-relevance one were not met.
An earlier, smaller run is described in docs/rag_evaluation_report.md (5 interactions; Precision@3 0.53, MRR 0.45). It is superseded by the numbers above.
- Small samples: 30 retrieval queries, 10 Kenya queries.
- Latency includes network time to the provider on an uncontrolled host. Do not compare it with the current setup.
- Kenya domain relevance = 1.0 only checks that the retrieved chunk belongs to a known domain, which is nearly always true. It is a weak metric.
-
Display bug: the "TARGETS vs ACTUALS" table in the summary prints the wrong value for the hallucination row (it shows 1 minus the rate: 0.7855 instead of 0.2145). The metric section above it is correct. The row comes from
evaluate.pyand has not been fixed. - Generated questions can be easier than real user questions because each is written from the answer chunk.
No current-setup numbers exist yet. If you run the loop above, record: date, LLM_MODEL_* values, the commit, and the host (CPU/GPU). Retrieval results are reproducible; generation results are not exactly repeatable.
Documentation last verified against the code on 2026-11-05. Evaluation figures are historical, see Evaluation. Educational tool, not medical advice.
Use it
How it works
- Architecture
- Retrieval Pipeline
- LLM Layer
- Prompts and Lessons
- Grounding Verification
- Knowledge Base
- Data and Logging
Quality
Develop