xinli/rag-python/知识库处理说明.md
2025-12-20 18:33:07 +08:00

125 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 知识库多人协作处理方案
## 一、分工方式
将 PDF 文件按数量或类型分配给不同人员处理:
| 人员 | 负责文件 | 预计时间 |
|-----|---------|---------|
| 人员A | 心理测量类 (10个PDF) | 2-3小时 |
| 人员B | 心理治疗类 (10个PDF) | 2-3小时 |
| 人员C | 心理学基础 (10个PDF) | 2-3小时 |
## 二、每个人需要的文件
将以下文件打包发给每个处理人员:
```
rag-python-处理包/
├── batch_index.py # 索引脚本
├── config.py # 配置文件
├── document_parser.py # 文档解析
├── text_splitter.py # 文本分块
├── vector_store.py # 向量存储
├── knowledge_docs/ # 空目录用于放PDF
├── index_data/ # 空目录,存放结果
└── requirements.txt # Python依赖
```
## 三、处理人员操作步骤
### 1. 环境准备
```bash
# 安装 Python 依赖
pip install -r requirements.txt
# 安装 Tesseract OCR用于扫描版PDF
# Windows: 下载安装 https://github.com/UB-Mannheim/tesseract/wiki
# 安装时勾选中文语言包
# 安装 Ollama 并下载嵌入模型
ollama pull nomic-embed-text
```
### 2. 放入 PDF 文件
将分配的 PDF 文件放入 `knowledge_docs/` 目录
### 3. 执行索引
```bash
python batch_index.py
```
等待处理完成,会显示:
- 处理进度
- 每个文件的字符数和向量块数
- 总耗时
### 4. 返回结果
处理完成后,将 `index_data/` 文件夹打包发回:
- 重命名为 `index_data_姓名/`
- 包含 `documents.json``faiss.index` 两个文件
## 四、合并索引(汇总人员操作)
### 1. 收集所有人的结果
将各人返回的 `index_data_xxx/` 文件夹放到 `to_merge/` 目录:
```
rag-python/
├── to_merge/
│ ├── index_data_张三/
│ │ ├── documents.json
│ │ └── faiss.index
│ ├── index_data_李四/
│ │ ├── documents.json
│ │ └── faiss.index
│ └── index_data_王五/
│ ├── documents.json
│ └── faiss.index
└── merge_index.py
```
### 2. 执行合并
```bash
python merge_index.py
```
### 3. 验证结果
```bash
python app.py
# 访问 http://localhost:5000/api/stats 查看统计
```
## 五、注意事项
1. **Ollama 必须运行** - 所有处理人员的电脑都需要运行 Ollama
2. **模型要一致** - 都使用 `nomic-embed-text` 模型
3. **避免重复文件** - 不同人员处理的 PDF 不要重复
4. **大文件耐心等待** - 200MB 的 PDF 可能需要 30-60 分钟
## 六、常见问题
### Q: 处理中断了怎么办?
A: 删除 `index_data/` 目录,重新运行 `batch_index.py`
### Q: 某个 PDF 处理失败怎么办?
A: 检查 PDF 是否损坏,或尝试用其他工具转换格式
### Q: 合并后发现有重复怎么办?
A: 合并脚本会自动去重(按文件名判断)
## 七、预估时间
| PDF 类型 | 大小 | 预估时间 |
|---------|------|---------|
| 文字版 PDF | 10MB | 1-2 分钟 |
| 扫描版 PDF | 10MB | 5-10 分钟 |
| 大型扫描版 | 200MB | 30-60 分钟 |