当前位置: 首页 > news >正文

RagFlow启动源码说明

RagFlow主要有两个启动文件,本文从核心启动文件ragflow_server.py入手,讲解源码并梳理ragflow的启动逻辑。

if __name__ == '__main__':logging.info(r"""____   ___    ______ ______ __               / __ \ /   |  / ____// ____// /____  _      __/ /_/ // /| | / / __ / /_   / // __ \| | /| / // _, _// ___ |/ /_/ // __/  / // /_/ /| |/ |/ / /_/ |_|/_/  |_|\____//_/    /_/ \____/ |__/|__/                             """)logging.info(f'RAGFlow version: {get_ragflow_version()}')logging.info(f'project base: {utils.file_utils.get_project_base_directory()}')# 打印配置信息,例如版本号、服务名称等# 主要涉及两个文件,一个是源码constants.py,另一个是配置文件service_conf.yamlshow_configs()# 初始化配置,包括数据库、es、minio、大模型等settings.init_settings()print_rag_settings()if RAGFLOW_DEBUGPY_LISTEN > 0:logging.info(f"debugpy listen on {RAGFLOW_DEBUGPY_LISTEN}")import debugpydebugpy.listen(("0.0.0.0", RAGFLOW_DEBUGPY_LISTEN))# init db# 初始化数据库表,如果不存在表,则执行表创建init_web_db()init_web_data()# init runtime configimport argparseparser = argparse.ArgumentParser()parser.add_argument("--version", default=False, help="RAGFlow version", action="store_true")parser.add_argument("--debug", default=False, help="debug mode", action="store_true")args = parser.parse_args()if args.version:print(get_ragflow_version())sys.exit(0)RuntimeConfig.DEBUG = args.debugif RuntimeConfig.DEBUG:logging.info("run on debug mode")RuntimeConfig.init_env()RuntimeConfig.init_config(JOB_SERVER_HOST=settings.HOST_IP, HTTP_PORT=settings.HOST_PORT)GlobalPluginManager.load_plugins()signal.signal(signal.SIGINT, signal_handler)signal.signal(signal.SIGTERM, signal_handler)def delayed_start_update_progress():logging.info("Starting update_progress thread (delayed)")t = threading.Thread(target=update_progress, daemon=True)t.start()# 处理未完成解析的文档,会更新文档状态# 未完成解析的文档会生成列表,存入redis, 然后通过从redis读取进行解析if RuntimeConfig.DEBUG:if os.environ.get("WERKZEUG_RUN_MAIN") == "true":threading.Timer(1.0, delayed_start_update_progress).start()else:threading.Timer(1.0, delayed_start_update_progress).start()# start http servertry:logging.info("RAGFlow HTTP server start...")run_simple(hostname=settings.HOST_IP,port=settings.HOST_PORT,application=app,threaded=True,use_reloader=RuntimeConfig.DEBUG,use_debugger=RuntimeConfig.DEBUG,)except Exception:traceback.print_exc()stop_event.set()time.sleep(1)os.kill(os.getpid(), signal.SIGKILL)

init_web_db()的源码如下:

@DB.connection_context()
@DB.lock("init_database_tables", 60)
def init_database_tables(alter_fields=[]):members = inspect.getmembers(sys.modules[__name__], inspect.isclass)table_objs = []create_failed_list = []for name, obj in members:if obj != DataBaseModel and issubclass(obj, DataBaseModel):table_objs.append(obj)if not obj.table_exists():logging.debug(f"start create table {obj.__name__}")try:obj.create_table(safe=True)logging.debug(f"create table success: {obj.__name__}")except Exception as e:logging.exception(e)create_failed_list.append(obj.__name__)else:logging.debug(f"table {obj.__name__} already exists, skip creation.")if create_failed_list:logging.error(f"create tables failed: {create_failed_list}")raise Exception(f"create tables failed: {create_failed_list}")# 表中添加字段migrate_db()

init_web_data()源码如下:

def init_web_data():start_time = time.time()#初始化大模型工厂,主要涉及表llm,llm_fatories,tenant_llm中的初始化数据# 同时也会更新知识库表中的文档数init_llm_factory()# if not UserService.get_all().count():# 这段代码源码是注释掉的,用于初始化管理员账号# 管理员账号可以用于自定义扩展功能#    init_superuser()#初始化表Canvas_Template中的数据add_graph_templates()logging.info("init web data success:{}".format(time.time() - start_time))

http://www.lryc.cn/news/620089.html

相关文章:

  • 前后端分离项目在云服务器的部署
  • 【系统安装】虚拟机中安装win10企业版系统记录
  • CSS保持元素宽高比,固定元素宽高比
  • 用 mock 把 ES 单元测试@elastic/elasticsearch-mock 上手
  • Python 环境隔离实战:venv、virtualenv 与 conda 的差异与最佳实践
  • 变分自编码器VAE的Pytorch实现
  • day39_2025-08-13
  • Go 微服务限流与熔断最佳实践:滑动窗口、令牌桶与自适应阈值
  • Day19 C 语言标准 IO 机制
  • React useMemo 深度指南:原理、误区、实战与 2025 最佳实践
  • React常见的Hooks
  • 万字详解C++11列表初始化与移动语义
  • OpenCV的实际应用
  • 类和对象----中
  • 【COMSOL】Comsol学习案例时的心得记录分享
  • Mysql数据库迁移到GaussDB注意事项
  • pycharm配置连接服务器
  • 3.Cursor提效应用场景实战
  • MySQL相关概念和易错知识点(6)(视图、用户管理)
  • 大厂语音合成成本深度对比:微软 / 阿里 / 腾讯 / 火山 API 计费拆解与技术选型指南
  • trace分析之查找点击事件
  • cisco无线WLC flexconnect配置
  • python类--python011
  • 数仓建模理论-数据域和主题域
  • 8.13服务器安全检测技术和防御技术
  • 免费生成视频,Coze扣子工作流完全免费的视频生成方案,实现图生视频、文生视频
  • [ Mybatis 多表关联查询 ] resultMap
  • LeetCode Day5 -- 二叉树
  • 使用 HTML5 Canvas 打造炫酷的数字时钟动画
  • Kubernetes-03:Service