Spaces:
Sleeping
Sleeping
Islam Mamedov commited on
Commit ·
d6df2f2
1
Parent(s): a29c69c
Fix CI recall gate and add workflow badge
Browse files- README.md +2 -1
- src/eval.py +41 -25
README.md
CHANGED
|
@@ -20,6 +20,7 @@ Ask technical questions about FastAPI and receive answers grounded in its source
|
|
| 20 |
[](https://github.com/islam-mamedov/codebase-rag)
|
| 21 |
[](https://www.python.org/)
|
| 22 |
[](LICENSE)
|
|
|
|
| 23 |
|
| 24 |
</div>
|
| 25 |
|
|
@@ -699,4 +700,4 @@ Built as an evaluation-driven AI engineering project.
|
|
| 699 |
|
| 700 |
**[Try the live demo](https://huggingface.co/spaces/islam-mamedov/fastapi-codebase-qa)**
|
| 701 |
|
| 702 |
-
</div>
|
|
|
|
| 20 |
[](https://github.com/islam-mamedov/codebase-rag)
|
| 21 |
[](https://www.python.org/)
|
| 22 |
[](LICENSE)
|
| 23 |
+
[](https://github.com/islam-mamedov/codebase-rag/actions/workflows/ci.yml)
|
| 24 |
|
| 25 |
</div>
|
| 26 |
|
|
|
|
| 700 |
|
| 701 |
**[Try the live demo](https://huggingface.co/spaces/islam-mamedov/fastapi-codebase-qa)**
|
| 702 |
|
| 703 |
+
</div>
|
src/eval.py
CHANGED
|
@@ -96,47 +96,63 @@ def main() -> None:
|
|
| 96 |
# -------- retrieval metrics --------
|
| 97 |
recalls, mrrs = [], []
|
| 98 |
retrieved_per_q = []
|
|
|
|
| 99 |
for item in items:
|
| 100 |
hits = retrieve(item["question"], k=args.k, mode=args.mode)
|
| 101 |
retrieved_per_q.append(hits)
|
|
|
|
| 102 |
if not item["answerable"]:
|
| 103 |
continue
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
recalls.append(1.0 if rank else 0.0)
|
| 107 |
mrrs.append(1.0 / rank if rank else 0.0)
|
|
|
|
| 108 |
if not rank:
|
| 109 |
print(f" [miss] {item['question']}")
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
recall_at_k = sum(recalls) / len(recalls)
|
| 115 |
-
mrr = sum(mrrs) / len(mrrs)
|
| 116 |
-
|
| 117 |
-
print(f"\n=== Retrieval (mode={args.mode}, k={args.k}) ===")
|
| 118 |
-
print(
|
| 119 |
-
f"recall@{args.k}: {recall_at_k:.2f} "
|
| 120 |
-
f"({int(sum(recalls))}/{len(recalls)})"
|
| 121 |
)
|
| 122 |
-
print(f"MRR: {mrr:.2f}")
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
| 131 |
|
|
|
|
|
|
|
| 132 |
print(
|
| 133 |
-
f"\n[gate]
|
| 134 |
-
f"
|
| 135 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
# -------- generation + judge metrics --------
|
| 142 |
import os
|
|
|
|
| 96 |
# -------- retrieval metrics --------
|
| 97 |
recalls, mrrs = [], []
|
| 98 |
retrieved_per_q = []
|
| 99 |
+
|
| 100 |
for item in items:
|
| 101 |
hits = retrieve(item["question"], k=args.k, mode=args.mode)
|
| 102 |
retrieved_per_q.append(hits)
|
| 103 |
+
|
| 104 |
if not item["answerable"]:
|
| 105 |
continue
|
| 106 |
+
|
| 107 |
+
rank = next(
|
| 108 |
+
(
|
| 109 |
+
position
|
| 110 |
+
for position, hit in enumerate(hits, 1)
|
| 111 |
+
if is_gold_hit(hit, item["gold"])
|
| 112 |
+
),
|
| 113 |
+
None,
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
recalls.append(1.0 if rank else 0.0)
|
| 117 |
mrrs.append(1.0 / rank if rank else 0.0)
|
| 118 |
+
|
| 119 |
if not rank:
|
| 120 |
print(f" [miss] {item['question']}")
|
| 121 |
|
| 122 |
+
if not recalls:
|
| 123 |
+
raise RuntimeError(
|
| 124 |
+
"The evaluation set contains no answerable questions."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
)
|
|
|
|
| 126 |
|
| 127 |
+
recall_at_k = sum(recalls) / len(recalls)
|
| 128 |
+
mrr = sum(mrrs) / len(mrrs)
|
| 129 |
+
|
| 130 |
+
print(f"\n=== Retrieval (mode={args.mode}, k={args.k}) ===")
|
| 131 |
+
print(
|
| 132 |
+
f"recall@{args.k}: {recall_at_k:.2f} "
|
| 133 |
+
f"({int(sum(recalls))}/{len(recalls)})"
|
| 134 |
+
)
|
| 135 |
+
print(f"MRR: {mrr:.2f}")
|
| 136 |
|
| 137 |
+
if args.min_recall is not None:
|
| 138 |
+
if recall_at_k < args.min_recall:
|
| 139 |
print(
|
| 140 |
+
f"\n[gate] FAIL: recall@{args.k}={recall_at_k:.4f} "
|
| 141 |
+
f"is below the required {args.min_recall:.4f}"
|
| 142 |
)
|
| 143 |
+
raise SystemExit(1)
|
| 144 |
+
|
| 145 |
+
print(
|
| 146 |
+
f"\n[gate] PASS: recall@{args.k}={recall_at_k:.4f} "
|
| 147 |
+
f"meets the required {args.min_recall:.4f}"
|
| 148 |
+
)
|
| 149 |
|
| 150 |
+
if not args.answers:
|
| 151 |
+
print(
|
| 152 |
+
"\n(retrieval-only run; add --answers "
|
| 153 |
+
"for generation metrics)"
|
| 154 |
+
)
|
| 155 |
+
return
|
| 156 |
|
| 157 |
# -------- generation + judge metrics --------
|
| 158 |
import os
|