xinli/项目介绍/环境配置/6. RAG知识库部署.md
2026-01-30 16:23:00 +08:00

1.9 KiB
Raw Permalink Blame History

RAG知识库服务部署

部署文件结构

将以下文件夹整体复制到服务器:

rag-python/
├── app.py                 # 主程序
├── config.py              # 配置文件
├── knowledge_service.py   # 知识库服务
├── vector_store.py        # 向量存储
├── document_parser.py     # 文档解析
├── text_splitter.py       # 文本分块
├── file_watcher.py        # 文件监控
├── requirements.txt       # 依赖
├── knowledge_docs/        # 知识库文档放txt/pdf/docx
├── index_data/            # 索引数据(自动生成)
└── uploads/               # 上传临时目录

部署步骤

1. 安装Python环境

# 确保Python 3.8+
python --version

# 安装依赖
cd rag-python
pip install -r requirements.txt

2. 确保Ollama已启动

RAG服务依赖Ollama的嵌入模型

# 检查Ollama状态
ollama list

# 确保有 nomic-embed-text 模型
ollama pull nomic-embed-text

3. 启动RAG服务

cd rag-python
python app.py

或使用批处理:

start.bat

服务启动后监听 http://0.0.0.0:5000

知识库文档

直接将文档放入 rag-python/knowledge_docs/ 目录即可:

  • 支持格式:.txt, .md, .pdf, .docx
  • 服务启动时自动扫描并建立索引
  • 运行中添加新文件会自动检测并索引

验证服务

# 健康检查
curl http://localhost:5000/api/health

# 查看文档列表
curl http://localhost:5000/api/documents

# 查看统计
curl http://localhost:5000/api/stats

与后端配合

后端 application.yml 中的RAG配置

rag:
  enabled: true
  service-url: http://127.0.0.1:5000

注意事项

  1. RAG服务需要在后端启动前启动
  2. 确保Ollama服务已运行且有 nomic-embed-text 模型
  3. 知识库文档放入 knowledge_docs/ 后会自动索引
  4. 首次启动会建立索引,文档多时需要等待