Repository navigation
Fix #7: answer drug questions and extract known names in structured queries - #14
Open
xiaoyao-666-coder wants to merge 2 commits into
Open
xiaoyao-666-coder wants to merge 2 commits into
xiaoyao-666-coder wants to merge 2 commits into
Conversation
… structured queries
- Drug intent: add usage phrasing (怎么吃/如何服用/用量/能吃吗...) to
drug keywords and score drug intent on known drug names derived
from knowledge-base drug documents, so '布洛芬怎么吃?有什么注意
事项?' is no longer misrouted to faq with zero citations. Also
allow bare negated safety phrasing ('不自行停药') in the safe
output whitelist to stop false-positive safety blocks.
- Structured queries: _extract_term now longest-matches against
registered entity names from the whitelisted tables; unknown
entities return blocked with a clarification instead of an empty
result that reads as 'out of stock'. Injection guards unchanged.
- Add backend/tests/test_drug_query.py (18 tests).
Closes zhengdaodeguL#7.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #7. 两处“听不懂用户问法”的问题。
A. 用药问题:根因不是知识库缺资料(布洛芬文档一直都在),而是意图识别:drug 关键词里既没有药品名也没有“怎么吃”这类用法词,“布洛芬怎么吃?有什么注意事项?”因含“注意事项”被判为 faq,而检索按 category == intent 硬过滤,drug 文档被排除 → 0 引用 → 通用引导。
B. 结构化查询抽词:
_extract_term按白名单表里已登记的实体名做最长匹配(如“布洛芬”←“布洛芬缓释胶囊”),仍保持 LIKE 前缀可走索引;匹配不到已知实体时返回 blocked + 澄清(能抽出用户写的词时点名澄清),不再返回“0 行假装没货”。注入防护未放松。验证:新增
backend/tests/test_drug_query.py(18 个测试);MEDGUIDE_MODE=test python -m pytest -q backend/tests539 passed(基线 521 + 18 新);前端未改动。已知未动:修前就有的“发烧怎么退热”判 unknown、“怎么止痛”0 引用,未顺手改。