forked from ChelseaKR/fare-policy-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_reranker_bottleneck_check.py
More file actions
45 lines (32 loc) · 1.49 KB
/
Copy pathtest_reranker_bottleneck_check.py
File metadata and controls
45 lines (32 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Reranker bottleneck check: rank-of-fact helper and report parsing.
Runs the offline BM25 retriever only (no network, no model calls) — same
scope as test_retrieval_ablation.py, whose fixtures and helpers this reuses.
"""
from __future__ import annotations
import json
from evals.reranker_bottleneck_check import _load_failing_ids, _rank_of_fact
class TestRankOfFact:
def test_fact_at_first_position(self):
assert _rank_of_fact("$2.00", ["fare is $2.00", "other text"]) == 1
def test_fact_buried(self):
assert _rank_of_fact("$2.00", ["other text", "fare is $2.00"]) == 2
def test_fact_absent(self):
assert _rank_of_fact("$9.99", ["fare is $2.00", "other text"]) is None
def test_regex_fact(self):
assert _rank_of_fact(r"re:\$\s?1\.00", ["nope", "seniors pay $1.00"]) == 2
class TestLoadFailingIds:
def test_only_suites_with_failures_are_returned(self, tmp_path):
report = {
"suite_results": [
{
"suite_name": "groundedness",
"failing_examples": [{"item_id": "edge-001", "detail": "x"}],
},
{"suite_name": "adversarial", "failing_examples": []},
]
}
path = tmp_path / "eval-report.json"
path.write_text(json.dumps(report), encoding="utf-8")
failing = _load_failing_ids(path)
assert list(failing) == ["groundedness"]
assert failing["groundedness"] == [{"item_id": "edge-001", "detail": "x"}]