Spaces:
Sleeping
Sleeping
ashe0042 commited on
Commit ·
8337957
1
Parent(s): bfd835a
Phase 2 complete: all five configs + eval harness working end to end
Browse files- src/eval.py +59 -0
src/eval.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Runs all five RAG configs against a single query and returns structured
|
| 3 |
+
results for comparison. No scoring/taxonomy logic here yet.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 10 |
+
|
| 11 |
+
from configs.grounded import run as run_grounded
|
| 12 |
+
from configs.hybrid import run as run_hybrid
|
| 13 |
+
from configs.kg_augmented import run as run_kg
|
| 14 |
+
from configs.naive import run as run_naive
|
| 15 |
+
from configs.rerank import run as run_rerank
|
| 16 |
+
|
| 17 |
+
CONFIG_RUNNERS = {
|
| 18 |
+
"naive": run_naive,
|
| 19 |
+
"hybrid": run_hybrid,
|
| 20 |
+
"rerank": run_rerank,
|
| 21 |
+
"kg_augmented": run_kg,
|
| 22 |
+
"grounded": run_grounded,
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def evaluate_query(query: str, source_filter: list[str] | None = None) -> dict:
|
| 27 |
+
results = {}
|
| 28 |
+
|
| 29 |
+
for config_name, run_fn in CONFIG_RUNNERS.items():
|
| 30 |
+
try:
|
| 31 |
+
results[config_name] = run_fn(query, source_filter=source_filter)
|
| 32 |
+
except Exception as e:
|
| 33 |
+
results[config_name] = {"error": str(e), "config_name": config_name}
|
| 34 |
+
|
| 35 |
+
return {"query": query, "results": results}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
smoke_query = (
|
| 40 |
+
"What are the obligations of an APRA-regulated entity under CPS 234 "
|
| 41 |
+
"regarding information security incidents?"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
evaluation = evaluate_query(smoke_query)
|
| 45 |
+
|
| 46 |
+
for config_name, result in evaluation["results"].items():
|
| 47 |
+
print(f"=== {config_name} ===")
|
| 48 |
+
|
| 49 |
+
if "error" in result:
|
| 50 |
+
print(f"ERROR: {result['error']}")
|
| 51 |
+
print("-" * 60)
|
| 52 |
+
continue
|
| 53 |
+
|
| 54 |
+
print(result["answer"][:300])
|
| 55 |
+
print("\nRetrieved paragraph IDs:")
|
| 56 |
+
for chunk in result["retrieved_chunks"]:
|
| 57 |
+
print(f"- [{chunk['source']}] {chunk['paragraph_id']}")
|
| 58 |
+
|
| 59 |
+
print("-" * 60)
|