RICS / backend /tests /test_baseline_assembly.py
StormShadow308's picture
Add demo documentation and Docker setup for v2 report generation system
aad7814
Raw
History Blame Contribute Delete
1.88 kB
"""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"