Spaces:
Runtime error
Runtime error
File size: 1,880 Bytes
aad7814 | 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 | """REFERENCE baseline assembly and in-place mapping orchestration."""
from __future__ import annotations
from backend.core.paragraph_retriever import assemble_reference_baseline
from backend.core.rag_store import SearchHit, TIER_REFERENCE
def _hit(
text: str,
*,
score: float,
section_id: str = "D2",
paragraph_index: int = 1,
source: str = "past.docx",
) -> SearchHit:
return SearchHit(
text=text,
score=score,
tier=TIER_REFERENCE,
is_scrubbed=False,
section_id=section_id,
paragraph_index=paragraph_index,
source_filename=source,
doc_id=f"reference:{source}",
)
def test_assemble_reference_baseline_combines_section_paragraphs():
short = _hit("The roof comprises slate tiles.", score=0.91, paragraph_index=1)
long = _hit(
"Inspection was limited to ground level using binoculars. "
"The underfelt and battens were not visible.",
score=0.90,
paragraph_index=2,
)
baseline, hits = assemble_reference_baseline(
[short, long],
paragraph_section_id="D2",
)
assert "slate tiles" in baseline
assert "binoculars" in baseline
assert len(baseline.split()) > len(short.text.split())
assert len(hits) == 2
def test_assemble_reference_baseline_prefers_longer_same_score():
brief = _hit("Slate roof.", score=0.95, paragraph_index=1)
verbose = _hit(
"The roof covering comprised natural slate tiles laid to pitched timber rafters "
"with underfelt and counter battens. Inspection was from ground level only.",
score=0.95,
paragraph_index=1,
source="verbose.docx",
)
baseline, hits = assemble_reference_baseline([brief, verbose], paragraph_section_id="D2")
assert "timber rafters" in baseline
assert hits[0].source_filename == "verbose.docx"
|