在当前AI领域中,基于检索增强生成(RAG)的应用备受关注,而开源项目RAGFlow因其灵活性和功能性成为了一个热门选择。不过,由于其快速的版本迭代,可能会存在一些Bug,并且在实际项目落地时通常需要根据具体需求对源码进行定制化修改。遗憾的是,RAGFlow官方尚未提供针对Windows开发环境的详细文档。因此,在本地部署过程中,我整理了一份详细的记录,希望能够为有类似需求的开发者提供参考。
一、RAGFlow Python 环境配置
确保您的Python版本符合以下要求:
- Python 版本:>=3.10,<3.13
二、Poetry 下载与安装
使用 Poetry 来管理 Python 依赖。首先,通过 pip 安装 Poetry:
pip install poetry
验证安装是否成功:
poetry --version
三、安装 Python 依赖
- 以管理员身份启动 Anaconda Prompt
- 为了确保权限足够,建议以管理员身份启动 Anaconda Prompt。
2、切换到ragflow运行环境
(base) C:\Windows\System32>D:
(base) D:>conda activate ragflow
(ragflow) D:>cd D:\WorkSpace\ForAi\pythod\ragflow
3、在ragflow根目录下运行poetry安装依赖命令
# 安装所有默认依赖
poetry install
# 安装 full 组中的依赖
poetry install -E full
4、已知问题与后续处理
在安装过程中,pyicu 版本 ==2.14 未能成功安装。目前这一问题对解析文档和聊天功能没有影响,因此暂时未进行处理。后续将更新文档以记录具体的解决方法。
四、前端启动
1、前端web服务器nginx
默认在目录下提供的配置文件是linux的,需要改成windows
nginx.conf
# user 指令在 Windows 上不支持,注释掉或删除
# user root;
worker_processes auto;
# 修改日志路径为 Windows 路径
error_log D:/dockerData/ragflow/nginx-1.21.1/logs/error.log notice;
pid D:/dockerData/ragflow/nginx-1.21.1/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
# 修改 mime.types 文件路径为 Windows 路径
include D:/dockerData/ragflow/nginx-1.21.1/conf/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# 修改访问日志路径为 Windows 路径
access_log D:/dockerData/ragflow/nginx-1.21.1/logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
client_max_body_size 128M;
# 包含自定义配置文件
include D:/dockerData/ragflow/nginx-1.21.1/conf/ragflow.conf;
}
proxy.conf
这个配置文件不做修改
ragflow.conf
server {
listen 80;
server_name _;
# 设置根目录为 Windows 路径
root D:/WorkSpace/ForAi/pythod/ragflow/web/dist;
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
location ~ ^/(v1|api) {
proxy_pass http://127.0.0.1:9380;
include proxy.conf;
}
location / {
index index.html;
try_files $uri $uri/ /index.html;
}
# Cache-Control: max-age~@~AExpires
location ~ ^/static/(css|js|media)/ {
expires 10y;
access_log off;
}
}
2、前端项目build
我使用的nodejs版本是 20.15.0 如果你本地有多个nodejs版本可以使用nvm管理切换
# 进入web目录下
(ragflow) D:\WorkSpace\ForAi\pythod\ragflow>cd web
# 安装前端依赖
npm install
# build项目
npm run build
可以看到web目录下多了个dist,ragflow.conf配置文件里需要配置这个目录
3、启动nginx
D:\dockerData\ragflow\nginx-1.21.1>start nginx
五、下载模型
找到根目录下的download_deps.py直接运行
依赖安装会比较慢
运行完根目录下多了这些文件
六、后端项目启动
1、配置mysql、redis、minio、es、infinity
2、启动项目
需要启动两个文件
(1)api下的ragflow_server.py
(2)rag/svr下的task_executor.py
在启动时遇到了文件是utf-8格式,默认使用的是gbk,我处理方式是直接改了源码,把文件处理的格式改成了utf-8
import os
import json
current_file_path = os.path.dirname(os.path.abspath(__file__))
json_file_path = os.path.join(current_file_path, "res/good_sch.json")
with open(json_file_path, "r", encoding="utf-8") as file:
GOOD_SCH = json.load(file)
import os
import json
current_file_path = os.path.dirname(os.path.abspath(__file__))
# 读取 corp.tks.freq.json 文件
with open(os.path.join(current_file_path, "res/corp.tks.freq.json"), "r", encoding="utf-8") as file:
CORP_TKS = json.load(file)
# 读取 good_corp.json 文件
with open(os.path.join(current_file_path, "res/good_corp.json"), "r", encoding="utf-8") as file:
GOOD_CORP = json.load(file)
# 读取 corp_tag.json 文件
with open(os.path.join(current_file_path, "res/corp_tag.json"), "r", encoding="utf-8") as file:
CORP_TAG = json.load(file)
cnvs = json.load(open(os.path.join(dir, fnm), "r", encoding="utf-8"))