|
| 1 | +# RAG Eval Workbench |
| 2 | + |
| 3 | +Offline, standard-library RAG evaluation workbench for testing retrieval quality, answer grounding, latency, and hallucination risk without paid API keys. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Why This Project Matters |
| 8 | + |
| 9 | +This repository is built as a portfolio-grade AI/ML/LLMOps project. It shows the practical engineering around RAG systems that hiring teams care about: |
| 10 | + |
| 11 | +- deterministic document loading and chunking; |
| 12 | +- local vector-style retrieval with hashed TF-IDF and cosine similarity; |
| 13 | +- citation-first answer synthesis; |
| 14 | +- retrieval, grounding, hallucination, latency, and cost metrics; |
| 15 | +- trace files and reproducible run artifacts; |
| 16 | +- CI that runs tests and the demo without network services. |
| 17 | + |
| 18 | +The core demo uses only Python 3 standard library modules. Optional integrations are documented for FastAPI, Streamlit, LangChain, and MLflow, but they are not required to run the project. |
| 19 | + |
| 20 | +## Quickstart |
| 21 | + |
| 22 | +```bash |
| 23 | +cd rag-eval-workbench |
| 24 | +python -m rag_eval_workbench demo --output runs/demo |
| 25 | +python -m unittest discover -s tests |
| 26 | +``` |
| 27 | + |
| 28 | +If your system only exposes Python as `python3`, use `python3 -m ...` for the same commands. |
| 29 | + |
| 30 | +Open the generated dashboard: |
| 31 | + |
| 32 | +```bash |
| 33 | +open runs/demo/dashboard.html |
| 34 | +``` |
| 35 | + |
| 36 | +The command works from a fresh checkout because the repo uses a `src/` package layout plus a thin top-level checkout shim for local execution. Installing the package is optional. |
| 37 | + |
| 38 | +## Demo Output |
| 39 | + |
| 40 | +The demo writes a portable run folder: |
| 41 | + |
| 42 | +```text |
| 43 | +runs/demo/ |
| 44 | + dashboard.html |
| 45 | + metrics.csv |
| 46 | + metrics.json |
| 47 | + results.json |
| 48 | + run_manifest.json |
| 49 | + summary.md |
| 50 | + traces.jsonl |
| 51 | +``` |
| 52 | + |
| 53 | +Example terminal output: |
| 54 | + |
| 55 | +```text |
| 56 | +Run complete: runs/demo |
| 57 | +Dashboard: runs/demo/dashboard.html |
| 58 | +Metrics: retrieval@k=1.000 groundedness=0.900 risk=0.100 latency_ms=1.200 cost=$0.000000 |
| 59 | +``` |
| 60 | + |
| 61 | +Actual latency varies by machine, but the corpus, benchmark questions, retrieval algorithm, and evaluation logic are deterministic. |
| 62 | + |
| 63 | +## Metrics |
| 64 | + |
| 65 | +| Metric | What It Answers | Why It Matters | |
| 66 | +| --- | --- | --- | |
| 67 | +| `retrieval@k` | Did the expected source document appear in the retrieved top-k contexts? | Catches retrieval and chunking regressions. | |
| 68 | +| `groundedness` | Are answer terms supported by retrieved context terms? | Flags unsupported generated claims. | |
| 69 | +| `answer_relevance` | Does the answer overlap with the reference answer? | Keeps responses aligned to expected facts. | |
| 70 | +| `hallucination_risk` | How risky is the answer based on grounding and retrieval quality? | Gives release owners a triage signal. | |
| 71 | +| `latency_ms` | How long did the local pipeline take per question? | Makes evaluation performance visible. | |
| 72 | +| `estimated_cost_usd` | What is the configured per-run token cost estimate? | Defaults to zero for the offline standard-library demo. | |
| 73 | + |
| 74 | +## Architecture |
| 75 | + |
| 76 | +```text |
| 77 | +examples/docs |
| 78 | + -> load markdown/text documents |
| 79 | + -> create overlapping word chunks |
| 80 | + -> build local hashed TF-IDF vectors |
| 81 | + -> retrieve top-k chunks by cosine similarity |
| 82 | + -> synthesize extractive cited answers |
| 83 | + -> compute heuristic metrics |
| 84 | + -> write traces, metrics, and static dashboard |
| 85 | +``` |
| 86 | + |
| 87 | +Key modules live under `src/rag_eval_workbench/`: |
| 88 | + |
| 89 | +| Module | Role | |
| 90 | +| --- | --- | |
| 91 | +| `documents.py` | Document loading and deterministic chunking. | |
| 92 | +| `retrieval.py` | Local hash-vector retriever. | |
| 93 | +| `synthesis.py` | Extractive answer synthesis with citations. | |
| 94 | +| `evaluator.py` | Heuristic RAG metrics. | |
| 95 | +| `benchmark.py` | End-to-end benchmark orchestration. | |
| 96 | +| `tracing.py` | JSON, JSONL, CSV, and Markdown artifact writing. | |
| 97 | +| `dashboard.py` | Static HTML dashboard generation. | |
| 98 | +| `cli.py` | `python -m rag_eval_workbench` entrypoint. | |
| 99 | + |
| 100 | +See [docs/architecture.md](docs/architecture.md) and [docs/eval-methodology.md](docs/eval-methodology.md) for more detail. |
| 101 | + |
| 102 | +## CLI Usage |
| 103 | + |
| 104 | +Run the bundled demo: |
| 105 | + |
| 106 | +```bash |
| 107 | +python -m rag_eval_workbench demo --output runs/demo |
| 108 | +``` |
| 109 | + |
| 110 | +Run against your own local corpus: |
| 111 | + |
| 112 | +```bash |
| 113 | +python -m rag_eval_workbench benchmark \ |
| 114 | + --docs examples/docs \ |
| 115 | + --questions examples/questions.json \ |
| 116 | + --output runs/custom \ |
| 117 | + --top-k 3 |
| 118 | +``` |
| 119 | + |
| 120 | +Optional cost modeling: |
| 121 | + |
| 122 | +```bash |
| 123 | +python -m rag_eval_workbench demo \ |
| 124 | + --output runs/demo-costed \ |
| 125 | + --cost-per-1k-tokens 0.002 |
| 126 | +``` |
| 127 | + |
| 128 | +## Repository Layout |
| 129 | + |
| 130 | +```text |
| 131 | +. |
| 132 | + .github/workflows/ci.yml |
| 133 | + docs/ |
| 134 | + examples/ |
| 135 | + src/rag_eval_workbench/ |
| 136 | + tests/ |
| 137 | + .env.example |
| 138 | + pyproject.toml |
| 139 | +``` |
| 140 | + |
| 141 | +## Resume Relevance |
| 142 | + |
| 143 | +This project maps directly to AI engineer and LLMOps responsibilities: |
| 144 | + |
| 145 | +- eval harness design for RAG quality gates; |
| 146 | +- deterministic local baseline before paid model integrations; |
| 147 | +- trace-first debugging for retrieval failures; |
| 148 | +- CI-friendly tests and demo artifacts; |
| 149 | +- static dashboard generation for stakeholder review; |
| 150 | +- clean extension path for model providers, vector stores, and experiment tracking. |
| 151 | + |
| 152 | +## Optional Integrations |
| 153 | + |
| 154 | +The standard demo intentionally avoids third-party packages. Suggested production wrappers are documented in [docs/optional-integrations.md](docs/optional-integrations.md): |
| 155 | + |
| 156 | +- FastAPI for benchmark service endpoints; |
| 157 | +- Streamlit for analyst exploration; |
| 158 | +- LangChain for provider-backed retrievers; |
| 159 | +- MLflow for experiment tracking and artifact logging. |
| 160 | + |
| 161 | +## Limitations |
| 162 | + |
| 163 | +- The synthesizer is extractive and deterministic; it is not a generative LLM. |
| 164 | +- The evaluator is heuristic and transparent; it is not a replacement for human review or an LLM judge. |
| 165 | +- Hash-vector retrieval is a local baseline; production systems can swap in embeddings while keeping the same benchmark shape. |
0 commit comments