Wire token-budget packing into the overview/rerank fallback path
This commit is contained in:
@@ -159,3 +159,51 @@ def test_find_by_indication_respects_the_limit():
|
||||
hits = retriever.find_by_indication("đau", limit=2)
|
||||
|
||||
assert len(hits) == 2
|
||||
|
||||
|
||||
def _section_payload(drug_id: str, section_key: str, text: str) -> dict:
|
||||
return {
|
||||
"chunk_id": f"{drug_id}__{section_key}__0", "drug_id": drug_id,
|
||||
"drug_name": drug_id.upper(), "section_key": section_key,
|
||||
"chunk_kind": "prose", "text": text,
|
||||
"heading_physical_page": 100, "printed_page_range": [101, 101],
|
||||
}
|
||||
|
||||
|
||||
def test_search_lexical_ranks_by_distinct_matched_term_count():
|
||||
client = _FakeScrollClient([
|
||||
_section_payload("aspirin", "than_trong", "Thận trọng với suy thận."),
|
||||
_section_payload(
|
||||
"aspirin", "chong_chi_dinh",
|
||||
"Không dùng cho người có loét dạ dày tá tràng đang hoạt động.",
|
||||
),
|
||||
])
|
||||
retriever = QdrantRetriever(client, "duocthu_v1", embedder=None)
|
||||
|
||||
hits = retriever.search_lexical(
|
||||
"Thận trọng khi dùng aspirin cho bệnh nhân loét dạ dày", "aspirin", limit=5
|
||||
)
|
||||
|
||||
assert [h.document.section_key for h in hits] == ["chong_chi_dinh", "than_trong"]
|
||||
assert hits[0].score > hits[1].score
|
||||
|
||||
|
||||
def test_search_lexical_drops_stopword_only_queries():
|
||||
client = _FakeScrollClient([
|
||||
_section_payload("aspirin", "than_trong", "Thận trọng với suy thận."),
|
||||
])
|
||||
retriever = QdrantRetriever(client, "duocthu_v1", embedder=None)
|
||||
|
||||
assert retriever.search_lexical("là gì và của", "aspirin", limit=5) == []
|
||||
|
||||
|
||||
def test_search_lexical_excludes_non_matching_sections():
|
||||
client = _FakeScrollClient([
|
||||
_section_payload("aspirin", "than_trong", "Thận trọng với suy thận."),
|
||||
_section_payload("aspirin", "chi_dinh", "Giảm đau hạ sốt."),
|
||||
])
|
||||
retriever = QdrantRetriever(client, "duocthu_v1", embedder=None)
|
||||
|
||||
hits = retriever.search_lexical("loét dạ dày", "aspirin", limit=5)
|
||||
|
||||
assert hits == []
|
||||
|
||||
Reference in New Issue
Block a user