Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
医学中文RAG项目,使用langchain+milvus,支持快速一键式部署,支持无缝领域迁移
| Date | Stars |
|---|---|
| 2026-07-31 | 290 |
| 2026-08-05 | 291 |
| 2026-08-06 | 291 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# Medical RAG - 医疗智能问答系统
基于 LangChain 0.3.27 + Milvus 2.6.x + LangSmith + langgraph 0.6.6 的专业医疗领域RAG(检索增强生成)系统,支持多向量混合检索和智能问答。
使用约定数据格式,可无缝迁移到其他领域,例如:法学、金融
## 🌟 项目亮点
- **专业医疗领域优化**:支持领域稀疏向量计算,可直接通过配置完成领域词表管理;也可以使用原生的Milvus进行稀疏向量管理
- **多向量混合检索**:稠密向量 + 稀疏向量(BM25) 的混合检索策略
- **灵活的架构设计**:支持一键配置多种LLM提供商(OpenAI、Ollama)和嵌入模型
- **完整的数据流水线**:从数据预处理、入库到检索问答、以及评估的端到端解决方案
- **RAG智能体**:自动确定检索内容、检索参数、自动确定是否符合文档事实、自动确定是否开启网络检索,将检索功能全部交由智能体托管,一站式定义查询即可得到你想要的答案!
- **更丰富的工程细节**:自带token估计、摘要提取、检索文档动态整合等重要特性,在多轮对话性能强悍。
## 🏗️ 项目主要架构
```
medical-rag/
├── src/MedicalRag/
│ ├── config/ # 配置管理系统
│ │ ├── models.py # Pydantic配置模型
│ │ ├── loader.py # 配置加载器
│ │ └── app_config.yaml # 默认配置文件
│ ├── core/ # 核心组件
│ │ ├── utils.py # LLM/嵌入模型创建工具
│ │ ├── KnowledgeBase.py # 多向量知识库
│ │ ├── HybridRetriever.py # 混合检索器
│ │ ├── insert.py # Milvus入库工具类
│ │ ├── DBFactory.py # 知识库工厂,并行检索时保证单例客户端的线程安全
│ │ └── IngestionPipeline.py # 数据入库流水线
│ ├── embed/ # 嵌入相关
│ │ ├── vocab/ # 领域词表默认保存目录
│ │ ├── sparse.py # BM25稀疏向量实现
│ │ └── bm25.py # BM25适配器
│ ├── data/ # 数据处理
│ │ └── annotation.py # 自动标注系统
│ ├── rag/ # RAG核心
│ │ ├── RagBase.py # RAG实现的基类
│ │ ├── RagEvaluate.py # RAG评测的基类与实现类
│ │ ├── utils.py # 工具类
│ │ ├── MultiDialogueRag.py # 多轮对话实现类
│ │ └── SimpleRag.py # 基础RAG实现
│ ├── prompts/ # 提示词管理
│ │ └── templates.py # 提示词模板
│ └── agent/ # 智能体实现
│ │ ├── tools/ # 工具包
│ │ │ ├── AgentTools.py # 工具类
│ │ │ └── TencentSearch.py # 腾讯云网络检索器
│ │ ├── utils.py # 工具函数
│ │ ├── AgentBase.py # 智能体基类
│ │ ├── MedicalAgent.py # 多轮问讯智能体
│ └── └── SearchGraph.py # 单轮对话智能体
├── scripts/ # 使用脚本
├── Milvus/ # Milvus客户端启动相关
└── .vscode/ # vscode快捷运行配置
```
## 🚀 快速开始
### 1. 环境准备
#### 数据集
[huatuo-qa](https://www.huatuogpt.cn/) 数据集
也可以使用本项目提供的由 `huatuo-qa` 采样而来的数据集用作示例,详见 `data` 目录
#### 使用conda环境构建
```bash
git clone https://github.com/yolo-hyl/medical-rag
sudo apt install git-lfs # 如果没有安装lfs
git lfs pull # 拉取大文件数据集
cd medical-rag
conda env create -f environment.yml # 创建虚拟环境
```
#### 安装本项目
```bash
conda activate rag
cd src
python -m pip install --no-build-isolation pkuseg # 安装依赖包
pip install -e .
```
#### 启动基础服务
**启动 Milvus 向量数据库**
由于本项目默认可以采用稀疏向量管理,所以需要使用客户端Milvus。
```bash
# 使用项目提供的脚本
cd Milvus
bash standalone_embed.sh start
```
**启动 Ollama(如果使用本地模型)**
```bash
# 安装并启动 Ollama
ollama serve
# 拉取所需模型
ollama pull bge-m3:latest # 嵌入模型
ollama pull qwen3:32b # 对话模型
```
更多配置详见 [Ollama](https://ollama.com/)
**配置环境变量**
也可以不使用ollama,使用api_key去访问web服务,针对没有本地算力的场景,不推荐将api_key直接明文写入项目中,强烈推荐使用环境变量的方式进行读取。
```bash
# 编辑环境变量配置文件
vim ~/.bashrc
# 输入api
export DASHSCOPE_API_KEY = "xxxxx"
```
记住上面的环境变量名,后续配置需要提供。
总而言之,你需要配置三个环境变量:
1. llm或者embedding服务的环境变量(如需,如果使用ollama则不需要配置)
2. langchain的api key,用于检测服务(也是可选)
3. 腾讯云服务的id和key(网络搜索需要用)
### 2. 配置及向量库说明
编辑 `src/MedicalRag/config/app_config.yaml`可修改默认配置,也可在引入config时动态修改部分配置:
```yaml
# Milvus向量数据库配置
milvus:
uri: http://localhost:19530
token: null
collection_name: medical_knowledge
drop_old: true # 第一次建库时,是否删除同名 collection,调试用,生产环境严禁使用
auto_id: false # 可选是否自动生成id,否则采用hash值作为id自动去重
# 嵌入模型配置(支持多向量字段)
embedding:
summary_dense: # 问题/摘要 向量(稠密)
provider: ollama # 可选openai接口 或者 ollama库接口
model: bge-m3:latest # 模型名称
env_key_name: DASHSCOPE_API_KEY # 可选的api_key的环境变量名,否则默认使用`openai_ky`
base_url: http://localhost:11434 # 请求接口
dimension: 1024 # 编码的向量维度
text_dense: # 主文本向量(稠密)
provider: ollama
model: bge-m3:latest
base_url: http://localhost:11434
dimension: 1024
text_sparse: # BM25稀疏向量
provider: self # 或 "Milvus" 使用内置BM25
vocab_path_or_name: vocab.pkl.gz
algorithm: BM25
domain_moExcerpt of 11,599 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:261800bc8ddb6acf, llm:Description: '医学中文RAG项目,使用langchain+milvus,支持快速一键式部署,支持无缝领域迁移' (Medical Chinese RAG project using LangChain + Milvus).
matched fp:261800bc8ddb6acf, llm:Description: '医学中文RAG项目,使用langchain+milvus,支持快速一键式部署,支持无缝领域迁移' (Medical Chinese RAG project using LangChain + Milvus).
matched fp:261800bc8ddb6acf, llm:Description: '医学中文RAG项目,使用langchain+milvus,支持快速一键式部署,支持无缝领域迁移' (Medical Chinese RAG project using LangChain + Milvus).
matched fp:261800bc8ddb6acf, llm:Description: '医学中文RAG项目,使用langchain+milvus,支持快速一键式部署,支持无缝领域迁移' (Medical Chinese RAG project using LangChain + Milvus).