当前位置: 首页 > 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.dtcms.com/a/330328.html

相关文章:

  • Linux framebuffer 编程入门:直接操作显存画图
  • Flutter权限管理三步曲:检查、申请、处理全攻略
  • 【超算】算力的精度,数据中心的划分标准与行业现状(国家超级计算机,企业万卡GPU集群)
  • 深入详解C语言的循环结构:while循环、do-while循环、for循环,结合实例,讲透C语言的循环结构
  • 关于linux软件编程4:目录IO和一些时间函数
  • PAT 1065 A+B and C (64bit)
  • 驱动开发系列62 - glBufferDataARB实现分析
  • Windows下cuda的安装和配置
  • BGP 笔记梳理
  • 110. 字符串接龙
  • 【Spring AI 1.0.0】Spring AI 1.0.0框架快速入门(6)——MCP Client(MCP客户端)
  • 最新Coze(扣子)智能体工作流:用Coze实现「图片生成-视频制作」全自动化,3分钟批量产出爆款内容
  • Docker网络命名空间隔离与VPS服务器环境的连通性测试方法解析
  • kali linux 2025.2配置局域网打印服务器惠普打印机HP1108p
  • MySQL查询表结构、表大小
  • 告别意外中断,iOS辅助工具按键精灵「异常停止重启脚本」功能介绍
  • <c1:C1DateTimePicker的日期时间控件,控制日期可以修改,时间不能修改,另外控制开始时间的最大值比结束时间小一天
  • git clone 支持在命令行临时设置proxy
  • 康托展开与逆康托展开
  • 词向量转化
  • RocketMQ 消息存储机制 CommitLog和ConsumerQu
  • 第八课:python的运算符
  • 从 VLA 到 VLM:低延迟RTSP|RTMP视频链路在多模态AI中的核心角色与工程实现
  • 论文分享 | Flashboom:一种声东击西攻击手段以致盲基于大语言模型的代码审计
  • 04-spring-手写spring-demo-aop0V1
  • Canal解析MySQL Binlog原理与应用
  • Unity、C#常用的时间处理类
  • Laravel 使用ssh链接远程数据库
  • 使用 Simple Floating Menu 插件轻松实现浮动联系表单
  • AI一周事件(2025年8月6日-8月12日)