# 13.1 医疗：电子病历问答系统

## 13.1.1 场景背景

医生在诊疗过程中，需要快速从患者厚厚的历史病历中查阅既往史、用药情况和检查报告。传统的关键词搜索难以处理“患者最近一次血糖异常是什么时候？”这类语义查询。

## 13.1.2 上下文设计挑战

1. **准确性要求极高**：医疗场景容错率极低，绝对不能出现幻觉。
2. **术语复杂**：包含大量缩写、同义词和专业术语。
3. **时序敏感**：病情的演变与时间高度相关，必须严格区分“现在”和“过去”。

## 13.1.3 解决方案

### 结构化病历重组（写入策略）

原始病历通常是非结构化的文本。在写入向量库之前，先进行结构化处理：

```json
{
  "date": "2025-10-12",
  "type": "检查报告",
  "content": "空腹血糖 7.8 mmol/L",
  "entities": ["空腹血糖", "7.8"],
  "standardized_code": "GLU"
}
```

**关键点**：引入医学知识图谱（KG），将自然语言映射到标准术语代码（如 ICD-10, LOINC）。

### 混合检索策略（选择策略）

采用 **关键词检索 + 向量检索 + SQL 查询** 的三路召回：

* **关键词**：精确匹配药物名（“二甲双胍”）。
* **向量**：匹配语义描述（“降糖药”）。
* **SQL**：处理时间查询（“最近三个月” -> `date > NOW() - 90d`）。

### 说明书式上下文（隔离策略）

System Prompt 采用严格的“说明书”风格：

```markdown
你是一个严肃的医疗助手。遵循以下原则：
1. 只能依据 <context> 标签中的内容回答。
2. 如果上下文中没有提及，必须回答"未在病历中找到相关记录"，严禁编造。
3. 引用每一条结论的来源（如：[2025-10-12 门诊记录]）。
```

## 13.1.4 效果评估

通过构建覆盖典型问答场景的黄金数据集，对比优化前后效果（示意口径）：

* **准确性与一致性**：相较基线有明显提升。
* **幻觉风险**：在“仅依据病历回答”的约束下显著降低。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/context_engineering_guide/di-si-bu-fen-gong-cheng-shi-zhan-yu-wei-lai-yan-jin/13_cases/13.1_medical.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
