CI / ruff · pytest (pull_request) Successful in 1m30s
- docs/source/rag: PDF sources (KR PTSD 2023, KR depression 2024, meds module spec), pdf->txt converter (tables as markdown, page markers, hand-transcribed figures), word-level check against pdftotext; fixes HAM-D/MADRS fake headers and split rows - config/rag: corpus txt + sources.yaml (documents, audiences, retrieval params, synonyms) - app/llm/rag: Snowball stemmer, section-aware chunker with page citations, BM25 + synonym expansion + densest-passage reranking, extractive answer() with coverage gate, patient dose/prescribing filter, optional LLM rephrasing rejected when it adds content; CLI python -m app.llm.rag - tests: gold retrieval set (hit@3 >= 15/18), off-topic, safety, faithfulness - ADR-011 Refs #60 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 lines
787 B
Python
25 lines
787 B
Python
"""Knowledge base (RAG, #60): clinical guidelines -> citable chunks -> BM25 retrieval -> grounded answers.
|
|
|
|
from app.llm.rag import answer, retrieve
|
|
hits = retrieve("синдром отмены антидепрессантов", audience="doctor")
|
|
reply = await answer(scrub(text), audience="patient") # None -> rag.fallback_text()
|
|
|
|
Corpus and parameters: `config/rag/sources.yaml`; PDF sources and the converter: `docs/source/rag/`.
|
|
"""
|
|
|
|
from app.llm.rag.corpus import Chunk, load_chunks
|
|
from app.llm.rag.index import Hit, get_index, retrieve
|
|
from app.llm.rag.qa import Citation, RagAnswer, answer, fallback_text
|
|
|
|
__all__ = [
|
|
"Chunk",
|
|
"Citation",
|
|
"Hit",
|
|
"RagAnswer",
|
|
"answer",
|
|
"fallback_text",
|
|
"get_index",
|
|
"load_chunks",
|
|
"retrieve",
|
|
]
|