Wire up query history: localStorage session persistence + sidebar UI
This commit is contained in:
@@ -359,6 +359,52 @@ class QdrantRetriever:
|
||||
hits.append(SearchHit(_document(payload), 1.0))
|
||||
return hits
|
||||
|
||||
def list_sections(self, drug_id: str) -> list[tuple[str, str]]:
|
||||
"""Every section this drug has ANY content for — prose or
|
||||
quarantined — as `(section_key, section_display_name)` pairs, in
|
||||
book order (`rag.sections.SECTION_ORDER`). Feature-List #4: the UI
|
||||
needs the real per-drug checklist, not a generic 19-item list, since
|
||||
coverage genuinely varies (confirmed corpus-wide: 7 to 19 sections
|
||||
per drug).
|
||||
|
||||
Deliberately NOT `find_by_drug`'s `chunk_kind == "prose"` filter — a
|
||||
section that exists ONLY as a quarantined table (no prose chunk at
|
||||
all) is still a real section of this monograph; the caller decides
|
||||
how to present a request for it (`find_by_section` already handles
|
||||
the quarantine notice). A projection scroll: only the two payload
|
||||
fields this needs, never `text` — the checklist has no reason to
|
||||
pull every chunk's full content over the wire.
|
||||
"""
|
||||
from qdrant_client.models import FieldCondition, Filter, MatchValue
|
||||
|
||||
from rag.sections import SECTION_ORDER
|
||||
|
||||
scroll_filter = Filter(
|
||||
must=[FieldCondition(key="drug_id", match=MatchValue(value=drug_id))]
|
||||
)
|
||||
found: dict[str, str] = {}
|
||||
offset = None
|
||||
while True:
|
||||
points, offset = self._client.scroll(
|
||||
collection_name=self._collection_name,
|
||||
scroll_filter=scroll_filter,
|
||||
limit=256,
|
||||
offset=offset,
|
||||
with_payload=["section_key", "section_display_name"],
|
||||
)
|
||||
for point in points:
|
||||
payload = dict(point.payload or {})
|
||||
key = payload.get("section_key")
|
||||
if key and key not in found:
|
||||
found[key] = payload.get("section_display_name") or key
|
||||
if offset is None:
|
||||
break
|
||||
|
||||
order = {key: index for index, key in enumerate(SECTION_ORDER)}
|
||||
return sorted(
|
||||
found.items(), key=lambda item: order.get(item[0], len(order))
|
||||
)
|
||||
|
||||
def find_by_indication(self, indication_text: str, limit: int) -> list[SearchHit]:
|
||||
"""Reverse lookup: every drug whose `chi_dinh` text mentions the given
|
||||
symptom/indication, keyword-matched. Deterministic, no fabrication
|
||||
|
||||
Reference in New Issue
Block a user