test_retrieval_logging.py
2.6 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from types import SimpleNamespace
from src.rag.retrieval import Candidate, _candidate_log_items, _chunk_log_items
def test_candidate_log_items_include_source_score_and_metadata():
candidate = Candidate(
child_chunk_id="child-1",
parent_chunk_id="parent-1",
file_id="file-1",
retrieval_type="direct",
hybrid_score=0.87654,
payload={
"source_name": "source.pdf",
"chunk_index": 12,
"page_start": 3,
"page_end": 4,
"section_title": "features",
"brand": "brand-a",
"business_category": "vehicle",
"content_kind": "text",
},
)
items = _candidate_log_items([candidate], limit=5)
assert items == [
{
"rank": 1,
"type": "direct",
"score": 0.8765,
"child": "child-1",
"parent": "parent-1",
"file_id": "file-1",
"source": "source.pdf",
"chunk_index": 12,
"page": "3-4",
"section": "features",
"kind": "text",
"brand": "brand-a",
"category": "vehicle",
}
]
def test_chunk_log_items_include_scores_location_and_preview():
chunk = SimpleNamespace(
chunk_id="parent-1",
child_chunk_id="child-1",
file_id="file-1",
source_name="source.pdf",
chunk_index=12,
page_start=3,
page_end=3,
row_start=None,
row_end=None,
title_path="features > cockpit",
section_title="features",
content_kind="text",
brand_series="brand-a",
business_category="vehicle",
retrieval_type="direct",
vector_score=0.45678,
final_score=0.45678,
rerank_score=0.81234,
is_neighbor=False,
metadata_json={},
content="line one\nline two",
)
items = _chunk_log_items([chunk], limit=5, include_preview=True)
assert items == [
{
"rank": 1,
"chunk_id": "parent-1",
"child": "child-1",
"file_id": "file-1",
"source": "source.pdf",
"chunk_index": 12,
"page": "3",
"title": "features > cockpit",
"section": "features",
"kind": "text",
"brand": "brand-a",
"category": "vehicle",
"type": "direct",
"vector_score": 0.4568,
"final_score": 0.4568,
"rerank_score": 0.8123,
"neighbor": False,
"chars": 17,
"preview": "line one line two",
}
]