0.3.0 起不再直接加载本地模型路径,需先自行启动 Xinference/Ollama 等推理框架并加载模型;Langchain-Chatchat 与模型部署框架应放在不同 Python 虚拟环境中以避免依赖冲突;默认监听地址为 127.0.0.1,需改 basic_settings.yaml 为 0.0.0.0 才能用机器 IP 访问。

Langchain-Chatchat
chatchat-spaceApache-2.0长期未更新基于 Langchain 和 ChatGLM、Qwen、Llama 等本地大模型搭建的知识库问答应用,支持 RAG 检索增强与 Agent 能力,可离线部署私有文档问答系统。
Langchain-Chatchat(原Langchain-ChatGLM)基于 Langchain 与 ChatGLM, Qwen 与 Llama 等语言模型的 RAG 与 Agent 应用 | Langchain-Chatchat (formerly langchain-ChatGLM), local knowledge based LLM (like ChatGLM, Qwen and Llama) RAG and Agent app with langchain
pip install langchain-chatchat -U
chatchat init
chatchat kb -r
chatchat start -aREADME 说明 0.3.0 起支持 CPU、GPU、NPU、MPS 等不同硬件条件,未给出具体显存要求;模型需由外部推理框架加载,显存取决于所选模型。
基于 Langchain 的开源可离线 RAG 与 Agent 应用,让中文知识库问答能用本地模型私有部署
基于 Langchain 和 ChatGLM、Qwen、Llama 等本地大模型搭建的知识库问答应用,支持 RAG 检索增强与 Agent 能力,可离线部署私有文档问答系统。
核心能力
- 接入 Xinference、Ollama、LocalAI、FastChat 等推理框架
- 支持 GLM-4、Qwen2、Llama3 等开源 LLM 与 Embedding 模型
- File RAG 统一支持 BM25+KNN 等多种检索方式
- Agent 针对 ChatGLM3 和 Qwen 优化,可自动调用多工具
- 提供 FastAPI 接口与 Streamlit WebUI 两种使用方式
容易踩的坑
- v0.3.1Langchain-Chatchat v0.3.1最新正式版2024-07-12 · 2024-07-12 15:23 UTC
重要提示
Langchain-Chatchat v0.3.1 中命令行调用方式发生调整,请依据项目 README 进行操作;知识库的源文件与向量库仍可与前序版本通用,建议参考项目 README.md 中 快速上手 章节内容进行新版本部署。
新增功能
- 所有配置项改成 yaml 配置文件,改为命令行执行 chatchat init 初始化项目配置,需要本地文件中修改配置,配置项修改后即时生效,无需重启项目 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4421
- chatchat init 可以直接指定 Xinference API 地址、LLM 模型、Embedding 模型,一步完成知识库初始 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4425
- 新增 RAG 对话页面,包含知识库对话、文件对话、搜索引擎对话 by @liunux4odoo @imClumsyPanda in https://github.com/chatchat-space/Langchain-Chatchat/pull/4471
- 调整对话界面按钮布局,对话输入框左右分别设置"模型配置"与"清空对话"按钮 by @imClumsyPanda @liunux4odoo
- 支持 searx 搜索引擎 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4476
- 支持 GLM-4V、Qwen-VL 等 Vision 模型接入进行图片对话 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4421
- 使用 Xinference 接入本地模型时,支持自动检测已启动模型,无需手动填写模型名称 by @imClumsyPanda @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4421
- Agent 可调用工具中增加了维基百科搜索、高德地图天气查询、高德地图POI搜索 by @yhfgyyf in https://github.com/chatchat-space/Langchain-Chatchat/pull/4419
- Agent 工具新增 text2promql by @yuehua-s in https://github.com/chatchat-space/Langchain-Chatchat/pull/4399
- 增加 dockerfile 并更新 README 中关于 docker 部署的操作介绍 by @yuehua-s in https://github.com/chatchat-space/Langchain-Chatchat/pull/4271 and https://github.com/chatchat-space/Langchain-Chatchat/pull/4274
- 新增 Agent 添加工具操作说明 by @zRzRzRzRzRzRzR in https://github.com/chatchat-space/Langchain-Chatchat/pull/4484
- 新增数据库对话配置说明 by @srszzw in https://github.com/chatchat-space/Langchain-Chatchat/pull/4475
- 添加 Agent & Chat API 接口调用的说明,修正知识库检索bug by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4341
- 增加知识库初始化时对 Ctrl+C 中止操作的支持 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4352
- 增加 Pypi 发布自动化操作 by @glide-the in https://github.com/chatchat-space/Langchain-Chatchat/pull/4260
- 增加不同系统部署环境测试 by @glide-the in https://github.com/chatchat-space/Langchain-Chatchat/pull/4480
问题修复
- 在 readme 中增加对 windows 下创建知识库卡住的说明与解决办法 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4330
- 统一搜索引擎与本地知识库返回格式,修改 WEBUI 渲染上下文方式 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4344
- 修复文生图工具 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4349
- 修复 Milvus 作为知识库时可能发生的错误 by @kwunhang in https://github.com/chatchat-space/Langchain-Chatchat/pull/4319
- 修复 max_tokens 问题 by @yuehua-s in https://github.com/chatchat-space/Langchain-Chatchat/pull/4355
- 修改api文档中手动输入工具参数的说明 by @srszzw in https://github.com/chatchat-space/Langchain-Chatchat/pull/4367
- 解决text2sql对GLM的兼容,即temperature不能设置为0 by @srszzw in https://github.com/chatchat-space/Langchain-Chatchat/pull/4370
- 解决es数据库删除时只能删除50条数据的BUG by @YangSuoze in https://github.com/chatchat-space/Langchain-Chatchat/pull/4351
- 解决天气、text2Sql Agent 运行报错的BUG by @21Janur in https://github.com/chatchat-space/Langchain-Chatchat/pull/4336
- 修复知识库对话中的bug by @srszzw in https://github.com/chatchat-space/Langchain-Chatchat/pull/4468
- fix: action model initialize error by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/4347
New Contributors
- @kwunhang made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/4319
- @YangSuoze made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/4351
- @21Janur made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/4336
Full Changelog: https://github.com/chatchat-space/Langchain-Chatchat/compare/v0.3.0...v0.3.1
- v0.3.0Langchain-Chatchat v0.3.02024-06-20 · 2024-06-20 23:27 UTC
查看更新说明
重要提示
Langchain-Chatchat v0.3.0 相比 0.2.x 有较大项目结构变动,但知识库的源文件与向量库仍可与前序版本通用,建议参考项目 README.md 中
快速上手章节内容进行新版本部署。
新增功能
- Langchain-Chatchat Python 库现已发布至 Pypi,可通过 pip install langchain-chatchat 方式直接安装;
- 替换原有 FastChat 模型推理框架,支持 Xinference、Ollama、One API 等多种模型推理与在线 API 框架的接入;
- 所有 Chat 接口修改为与 OpenAI API 形式对齐,真正实现 OpenAI API In, OpenAI API Out;
- 重构 Agent 功能,针对 GLM 和 Qwen 模型进行适配优化;
- 新增 ArXiv 文献对话、Wolfram 对话、文生图等多种 Agent 可调用工具;
- 更新知识库问答功能,支持 Ensemble Retriever 接入,并将在后续接入更多不同类型 Retriever;
- 更新 Streamlit WebUI,支持模型推理框架选择、对话管理、工具选择等多种新功能;
- 增加 Text2SQL 工具,支持 SQLAlchemy 大部分数据库,支持特定表、智能判定表与 Read-Only 模式,支持对表名进行额外说明;
- 新增 chatchat、chatchat-config、chatchat-kb 命令,支持通过命令行进行项目配置、知识库重构与项目启动;
- 更多细节更新,期待你的探索发现!
新晋贡献者
- @yhfgyyf made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2630
- @HALIndex made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2591
- @596192804 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2013
- @Lijia0 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2480
- @xyhshen made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2648
- @MSZheng20 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2688
- @showmecodett made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2740
- @songpb made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2816
- @fengyaojieTTT made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2919
- @criwits made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2949
- @wusongbai139 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2960
- @thinklover made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2892
- @hollowdjj made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3155
- @dignfei made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3276
- @Sumkor made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3324
- @oslijunw made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3404
- @liudichen made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3407
- @srszzw made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3508
- @RoceoRobin made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3585
- @yuehua-s made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3664
- @LOGIC-10 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3108
- @saliven1970 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3458
- @dengpeng777 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3574
- @FJiangArthur made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3340
- @Kudoryafuka3 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3804
- @An0nymous0 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3564
- @pearjelly made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3912
- @qqlww1987 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/3203
- @vegetablest made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/4048
- @selfuppen made their first contribution in https://github.c
- v0.2.102024-01-25 · 2024-01-25 23:24 UTC
查看更新说明
重要提示
Langchain-Chatchat v0.2.10 版本中修改了
configs中配置项,建议所有用户按照 Wiki 的开发部署中的相关描述重新完成项目中的配置文件生成。开发部署过程遇到问题请先到 Github Wiki / issues 中搜索。本次更新中依赖 Python 包与其版本发生了大量更新,请使用
pip install -r requirements.txt进行更新。此版本为 v0.2.x系列最后一个版本,具备全新 Agent 功能的 v0.3.0即将上线,敬请期待。
新增功能
- 优化 PDF 文件的 OCR,过滤无意义的小图片 by @liunux4odoo #2525
- 支持 Gemini 在线模型 by @yhfgyyf #2630
- 支持 GLM4 在线模型 by @zRzRzRzRzRzRzR
- elasticsearch更新https连接 by @xldistance #2390
- 增强对PPT、DOC知识库文件的OCR识别 by @596192804 #2013
- 更新 Agent 对话功能 by @zRzRzRzRzRzRzR
- 每次创建对象时从连接池获取连接,避免每次执行方法时都新建连接 by @Lijia0 #2480
- 实现 ChatOpenAI 判断token有没有超过模型的context上下文长度 by @glide-the
- 更新运行数据库报错和项目里程碑 by @zRzRzRzRzRzRzR #2659
- 更新配置文件/文档/依赖 by @imClumsyPanda @zRzRzRzRzRzRzR
- 添加日文版 readme by @eltociear #2787
问题修复
- ApiRequest.agent_chat 返回 dict 而非 str by @liunux4odoo #2520
- 修复milvus_kwargs问题 by @hzg0601 #2540
- 纠正 make_text_splitter 中 chunk_* parameters 参数的使用 by @liunux4odoo #2564
- 过滤 sse_starlette 返回的 ping 包,避免 JSON Decoder error : ping -... by @liunux4odoo #2585
- langchain 更新后,PGVector 向量库连接错误 by @HALIndex #2591
- 删除重复的引入和纠正拼写错误 by @tiandiweizun #2599
- Minimax's model worker 错误 by @xyhshen
- ES库无法向量检索.添加mappings创建向量索引 by @MSZheng20 #2688
- KBService 中几处拼写错误 by @hzg0601 #2640
- pytorch 自动检测设备 by @chatgpt-1, @Drincann, @zRzRzRzRzRzRzR #2514 #2570
新晋贡献者
- @Drincann made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2514
- @chatgpt-1 made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2570
- @tiandiweizun made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2599
Full Changelog: https://github.com/chatchat-space/Langchain-Chatchat/compare/v0.2.9...v0.2.10
- v0.2.9Langchain-Chatchat v0.2.92023-12-31 · 2023-12-31 12:20 UTC
查看更新说明
重要提示
Langchain-Chatchat v0.2.9 版本中修改了
configs中配置项,建议所有用户按照 Wiki 的开发部署中的相关描述重新完成项目中的配置文件生成。开发部署过程遇到问题请先到 Github Wiki / issues 中搜索。此外,v0.2.9 版本中知识库相关信息的数据库表发生了变化,如果继续使用之前版本的配置,可使用
python init_database.py --create-tables仅更新数据库表,不重建知识库。本次更新中依赖 Python 包与其版本发生了大量更新,请使用
pip install -r requirements.txt进行更新。新增功能
- 文件对话和知识库对话 API 接口实现全异步操作,防止阻塞 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2256
- 更新默认模型下载链接 by @YQisme in https://github.com/chatchat-space/Langchain-Chatchat/pull/2259
- OCR 支持 GPU 加速(需要手动安装 rapidocr_paddle[gpu]);知识库支持 MHTML 和 Evernote 文件。 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2265
- 使用Reranker模型对召回语句进行重排 by @hzg0601 in https://github.com/chatchat-space/Langchain-Chatchat/pull/2435
- 知识库管理界面支持查看、编辑、删除向量库文档 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2471
问题修复
- 修改 duckduckgo 依赖错误 by @zRzRzRzRzRzRzR @hzg0601 in https://github.com/chatchat-space/Langchain-Chatchat/pull/2251 and https://github.com/chatchat-space/Langchain-Chatchat/pull/2252
- 修复Azure 不设置Max token的bug by @zRzRzRzRzRzRzR in https://github.com/chatchat-space/Langchain-Chatchat/pull/2254
- fix: prompt template name error in file_chat by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2366
- 优化EventSource回包 by @lookou in https://github.com/chatchat-space/Langchain-Chatchat/pull/1200
- fix: 文档错误 by @jaluik in https://github.com/chatchat-space/Langchain-Chatchat/pull/2384
- 更新 self.dims_length 赋值错误 by @xldistance in https://github.com/chatchat-space/Langchain-Chatchat/pull/2380
- 修复knowledge_base_chat_iterator 传参错误 by @xldistance in https://github.com/chatchat-space/Langchain-Chatchat/pull/2386
- fixed 迭代器参数传递错误,知识库问答报错TypeError: unhashable type: 'list' by @Astlvk in https://github.com/chatchat-space/Langchain-Chatchat/pull/2383
- fix:使用在线embedding模型时 报错 There is no current event loop in thread 'Any… by @Funkeke in https://github.com/chatchat-space/Langchain-Chatchat/pull/2393
- fix Yi-34b model config error(close #2491) by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2492
- remove /chat/fastchat API endpoint by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2506
新晋贡献者
- @YQisme made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2259
- @lookou made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/1200
- @jaluik made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2384
- @xldistance made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2380
- @Astlvk made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2383
- @Funkeke made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2393
Full Changelog: https://github.com/chatchat-space/Langchain-Chatchat/compare/v0.2.8...v0.2.9
- v0.2.8Langchain-Chatchat v0.2.82023-12-01 · 2023-12-01 14:13 UTC
查看更新说明
重要提示
Langchain-Chatchat v0.2.8 版本中修改了
configs中配置项,建议所有用户按照 Wiki 的开发部署中的相关描述重新完成项目中的配置文件生成。开发部署过程遇到问题请先到 Github Wiki / issues 中搜索。此外,v0.2.8 版本中知识库相关信息的数据库表发生了变化,且默认 embedding 模型修改为
bge-large-zh,如保持默认设置,请按需重建知识库。如果继续使用之前版本的配置,可使用python init_database.py --create-tables仅更新数据库表,不重建知识库。本次更新中依赖 Python 包与其版本发生了大量更新,请使用
pip install -r requirements.txt进行更新。新增功能
- 添加文件对话模式 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2071
- 知识库支持 .jsonl, .epub, .xlsx, .xlsd, .ipynb, .odt, .py, .srt, .toml, .doc, .ppt 文件 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2079
- 支持昆仑万维天工大模型 by @nathubs in https://github.com/chatchat-space/Langchain-Chatchat/pull/2166
- 完善对 ChatGLM3-6B 的支持 by @zRzRzRzRzRzRzR in https://github.com/chatchat-space/Langchain-Chatchat/pull/2021 and https://github.com/chatchat-space/Langchain-Chatchat/pull/2058
- 增加聊天记录在数据库中的存储 by @qiankunli in https://github.com/chatchat-space/Langchain-Chatchat/pull/2046
- 完善 WebUI 模型列表中对在线模型和本地模型的支持 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2060
- 支持软连接的知识库 by @zRzRzRzRzRzRzR in https://github.com/chatchat-space/Langchain-Chatchat/pull/2167
- 给 ApiModelWorker 添加 logger 成员变量,API请求出错时输出有意义的错误信息。 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2169
- 提供文档 summary_chunk ,支持单文件总结业务实现使用 MapReduceDocumentsChain 生成摘要 by @glide-the in https://github.com/chatchat-space/Langchain-Chatchat/pull/2175
- 单个知识库根据 doc_ids 摘要 by @glide-the in https://github.com/chatchat-space/Langchain-Chatchat/pull/2176
- 添加自定义命令用于管理多会话 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2229
- 优化知识库文档加载 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2091
- 统一在线模型异常报文、增加详细日志 by @glide-the in https://github.com/chatchat-space/Langchain-Chatchat/pull/2130
- 更新 ChatGLM3-6B agent的文档,提示词 by @zRzRzRzRzRzRzR in https://github.com/chatchat-space/Langchain-Chatchat/pull/2041
- 更新 requirements by @liunux4odoo @hzg0601 @zRzRzRzRzRzRzR @imClumsyPanda in https://github.com/chatchat-space/Langchain-Chatchat/pull/2033 , https://github.com/chatchat-space/Langchain-Chatchat/pull/2170 , https://github.com/chatchat-space/Langchain-Chatchat/pull/2213 and https://github.com/chatchat-space/Langchain-Chatchat/pull/2246
- 更新 README.md by @VignetteApril @weartist in https://github.com/chatchat-space/Langchain-Chatchat/pull/2034 and https://github.com/chatchat-space/Langchain-Chatchat/pull/2049
- 更新 config 模版 by @hzg0601 @zRzRzRzRzRzRzR @imClumsyPanda in https://github.com/chatchat-space/Langchain-Chatchat/pull/2110 and https://github.com/chatchat-space/Langchain-Chatchat/pull/2171
- 数据库和向量库中文档 metadata["source"] 改为相对路径,便于向量库迁移 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2153
问题修复
- 修复:知识库json文件的中文被转为 unicode 码,导致无法匹配 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2128
- 将 MiniMax 和 千帆 在线 Embedding 改为 10 个文本一批,防止接口数量限制 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2161
- 修复 startup.py by @hzg0601 in https://github.com/chatchat-space/Langchain-Chatchat/pull/2162 and https://github.com/chatchat-space/Langchain-Chatchat/pull/2173
- bug 修复和提示词修改 by @zRzRzRzRzRzRzR in https://github.com/chatchat-space/Langchain-Chatchat/pull/2230
- 一些细节更新 by @zRzRzRzRzRzRzR in https://github.com/chatchat-space/Langchain-Chatchat/pull/2235
- 修复: MiniMax 和千帆在线 embedding 模型分批请求的 bug by @alanlaye617 in https://github.com/chatchat-space/Langchain-Chatchat/pull/2208
- 修复: chat 接口默认使用 memory 获取 10 条历史消息,导致最终拼接的 prompt 出错 by @liunux4odoo in https://github.com/chatchat-space/Langchain-Chatchat/pull/2247
新晋贡献者
- @VignetteApril made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2034
- @weartist made their first contribution in https://github.com/chatchat-space/Langchain-Chatchat/pull/2049
- @nathubs made
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
📃 LangChain-Chatchat (原 Langchain-ChatGLM)
基于 ChatGLM 等大语言模型与 Langchain 等应用框架实现,开源、可离线部署的 RAG 与 Agent 应用项目。
目录
概述
🤖️ 一种利用 langchain 思想实现的基于本地知识库的问答应用,目标期望建立一套对中文场景与开源模型支持友好、可离线运行的知识库问答解决方案。
💡 受 GanymedeNil 的项目 document.ai 和 AlexZhangji 创建的 ChatGLM-6B Pull Request 启发,建立了全流程可使用开源模型实现的本地知识库问答应用。本项目的最新版本中可使用 Xinference、Ollama 等框架接入 GLM-4-Chat、 Qwen2-Instruct、 Llama3 等模型,依托于 langchain 框架支持通过基于 FastAPI 提供的 API 调用服务,或使用基于 Streamlit 的 WebUI 进行操作。

✅ 本项目支持市面上主流的开源 LLM、 Embedding 模型与向量数据库,可实现全部使用开源模型离线私有部署。与此同时,本项目也支持 OpenAI GPT API 的调用,并将在后续持续扩充对各类模型及模型 API 的接入。
⛓️ 本项目实现原理如下图所示,过程包括加载文件 -> 读取文本 -> 文本分割 -> 文本向量化 -> 问句向量化 ->
在文本向量中匹配出与问句向量最相似的 top k个 -> 匹配出的文本作为上下文和问题一起添加到 prompt中 -> 提交给 LLM生成回答。
📺 原理介绍视频

从文档处理角度来看,实现流程如下:

🚩 本项目未涉及微调、训练过程,但可利用微调或训练对本项目效果进行优化。
🌐 AutoDL 镜像 中 0.3.0
版本所使用代码已更新至本项目 v0.3.0 版本。
🐳 Docker 镜像将会在近期更新。
🧑💻 如果你想对本项目做出贡献,欢迎移步开发指南 获取更多开发部署相关信息。
功能介绍
0.3.x 版本功能一览
| 功能 | 0.2.x | 0.3.x |
|---|---|---|
| 模型接入 | 本地:fastchat在线:XXXModelWorker | 本地:model_provider,支持大部分主流模型加载框架在线:oneapi所有模型接入均兼容openai sdk |
| Agent | ❌不稳定 | ✅针对ChatGLM3和Qwen进行优化,Agent能力显著提升 |
| LLM对话 | ✅ | ✅ |
| 知识库对话 | ✅ | ✅ |
| 搜索引擎对话 | ✅ | ✅ |
| 文件对话 | ✅仅向量检索 | ✅统一为File RAG功能,支持BM25+KNN等多种检索方式 |
| 数据库对话 | ❌ | ✅ |
| 多模态图片对话 | ❌ | ✅ 推荐使用 qwen-vl-chat |
| ARXIV文献对话 | ❌ | ✅ |
| Wolfram对话 | ❌ | ✅ |
| 文生图 | ❌ | ✅ |
| 本地知识库管理 | ✅ | ✅ |
| WEBUI | ✅ | ✅更好的多会话支持,自定义系统提示词... |
0.3.x 版本的核心功能由 Agent 实现,但用户也可以手动实现工具调用:
| 操作方式 | 实现的功能 | 适用场景 |
|---|---|---|
| 选中"启用Agent",选择多个工具 | 由LLM自动进行工具调用 | 使用ChatGLM3/Qwen或在线API等具备Agent能力的模型 |
| 选中"启用Agent",选择单个工具 | LLM仅解析工具参数 | 使用的模型Agent能力一般,不能很好的选择工具想手动选择功能 |
| 不选中"启用Agent",选择单个工具 | 不使用Agent功能的情况下,手动填入参数进行工具调用 | 使用的模型不具备Agent能力 |
| 不选中任何工具,上传一个图片 | 图片对话 | 使用 qwen-vl-chat 等多模态模型 |
更多功能和更新请实际部署体验.
已支持的模型部署框架与模型
本项目中已经支持市面上主流的如 GLM-4-Chat 与 Qwen2-Instruct 等新近开源大语言模型和 Embedding 模型,这些模型需要用户自行启动模型部署框架后,通过修改配置信息接入项目,本项目已支持的本地模型部署框架如下:
| 模型部署框架 | Xinference | LocalAI | Ollama | FastChat |
|---|---|---|---|---|
| OpenAI API 接口对齐 | ✅ | ✅ | ✅ | ✅ |
| 加速推理引擎 | GPTQ, GGML, vLLM, TensorRT, mlx | GPTQ, GGML, vLLM, TensorRT | GGUF, GGML | vLLM |
| 接入模型类型 | LLM, Embedding, Rerank, Text-to-Image, Vision, Audio | LLM, Embedding, Rerank, Text-to-Image, Vision, Audio | LLM, Text-to-Image, Vision | LLM, Vision |
| Function Call | ✅ | ✅ | ✅ | / |
| 更多平台支持(CPU, Metal) | ✅ | ✅ | ✅ | ✅ |
| 异构 | ✅ | ✅ | / | / |
| 集群 | ✅ | ✅ | / | / |
| 操作文档链接 | Xinference 文档 | LocalAI 文档 | Ollama 文档 | FastChat 文档 |
| 可用模型 | Xinference 已支持模型 | LocalAI 已支持模型 | Ollama 已支持模型 | FastChat 已支持模型 |
除上述本地模型加载框架外,项目中也为可接入在线 API 的 One API 框架接入提供了支持,支持包括 OpenAI ChatGPT、Azure OpenAI API、Anthropic Claude、智谱清言、百川 等常用在线 API 的接入使用。
[!Note] 关于 Xinference 加载本地模型: Xinference 内置模型会自动下载,如果想让它加载本机下载好的模型,可以在启动 Xinference 服务后,到项目 tools/model_loaders 目录下执行
streamlit run xinference_manager.py,按照页面提示为指定模型设置本地路径即可.
快速上手
pip 安装部署
0. 软硬件要求
💡 软件方面,本项目已支持在 Python 3.8-3.11 环境中进行使用,并已在 Windows、macOS、Linux 操作系统中进行测试。
💻 硬件方面,因 0.3.0 版本已修改为支持不同模型部署框架接入,因此可在 CPU、GPU、NPU、MPS 等不同硬件条件下使用。
1. 安装 Langchain-Chatchat
从 0.3.0 版本起,Langchain-Chatchat 提供以 Python 库形式的安装方式,具体安装请执行:
pip install langchain-chatchat -U
[!important] 为确保所使用的 Python 库为最新版,建议使用官方 Pypi 源或清华源。
[!Note] 因模型部署框架 Xinference 接入 Langchain-Chatchat 时需要额外安装对应的 Python 依赖库,因此如需搭配 Xinference 框架使用时,建议使用如下安装方式:
pip install "langchain-chatchat[xinference]" -U
2. 模型推理框架并加载模型
从 0.3.0 版本起,Langchain-Chatchat 不再根据用户输入的本地模型路径直接进行模型加载,涉及到的模型种类包括 LLM、Embedding、Reranker 及后续会提供支持的多模态模型等,均改为支持市面常见的各大模型推理框架接入,如 Xinference、Ollama、LocalAI、FastChat、One API 等。
因此,请确认在启动 Langchain-Chatchat 项目前,首先进行模型推理框架的运行,并加载所需使用的模型。
这里以 Xinference 举例, 请参考 Xinference文档 进行框架部署与模型加载。
[!WARNING]
为避免依赖冲突,请将 Langchain-Chatchat 和模型部署框架如 Xinference 等放在不同的 Python 虚拟环境中, 比如 conda, venv, virtualenv 等。
3. 初始化项目配置与数据目录
从 0.3.1 版本起,Langchain-Chatchat 使用本地 yaml 文件的方式进行配置,用户可以直接查看并修改其中的内容,服务器会自动更新无需重启。
- 设置 Chatchat 存储配置文件和数据文件的根目录(可选)
# on linux or macos
export CHATCHAT_ROOT=/path/to/chatchat_data
# on windows
set CHATCHAT_ROOT=/path/to/chatchat_data
若不设置该环境变量,则自动使用当前目录。
- 执行初始化
chatchat init
该命令会执行以下操作:
- 创建所有需要的数据目录
- 复制 samples 知识库内容
- 生成默认
yaml配置文件
- 修改配置文件
-
配置模型(model_settings.yaml)
需要根据步骤 2. 模型推理框架并加载模型 中选用的模型推理框架与加载的模型进行模型接入配置,具体参考model_settings.yaml中的注释。主要修改以下内容:# 默认选用的 LLM 名称 DEFAULT_LLM_MODEL: qwen1.5-chat # 默认选用的 Embedding 名称 DEFAULT_EMBEDDING_MODEL: bge-large-zh-v1.5 # 将 `LLM_MODEL_CONFIG` 中 `llm_model, action_model` 的键改成对应的 LLM 模型 # 在 `MODEL_PLATFORMS` 中修改对应模型平台信息 -
配置知识库路径(basic_settings.yaml)(可选)
默认知识库位于CHATCHAT_ROOT/data/knowledge_base,如果你想把知识库放在不同的位置,或者想连接现有的知识库,可以在这里修改对应目录即可。# 知识库默认存储路径 KB_ROOT_PATH: D:\chatchat-test\data\knowledge_base # 数据库默认存储路径。如果使用sqlite,可以直接修改DB_ROOT_PATH;如果使用其它数据库,请直接修改SQLALCHEMY_DATABASE_URI。 DB_ROOT_PATH: D:\chatchat-test\data\knowledge_base\info.db # 知识库信息数据库连接URI SQLALCHEMY_DATABASE_URI: sqlite:///D:\chatchat-test\data\knowledge_base\info.db -
配置知识库(kb_settings.yaml)(可选)
默认使用
FAISS知识库,如果想连接其它类型的知识库,可以修改DEFAULT_VS_TYPE和kbs_config。
4. 初始化知识库
[!WARNING]
进行知识库初始化前,请确保已经启动模型推理框架及对应embedding模型,且已按照上述步骤3完成模型接入配置。
chatchat kb -r
更多功能可以查看 chatchat kb --help
出现以下日志即为成功:
----------------------------------------------------------------------------------------------------
知识库名称 :samples
知识库类型 :faiss
向量模型: :bge-large-zh-v1.5
知识库路径 :/root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/data/knowledge_base/samples
文件总数量 :47
入库文件数 :42
知识条目数 :740
用时 :0:02:29.701002
----------------------------------------------------------------------------------------------------
总计用时 :0:02:33.414425
[!Note] 知识库初始化的常见问题
1. Windows 下重建知识库或添加知识文件时卡住不动
此问题常出现于新建虚拟环境中,可以通过以下方式确认:
from unstructured.partition.auto import partition如果该语句卡住无法执行,可以执行以下命令:
pip uninstall python-magic-bin # check the version of the uninstalled package pip install 'python-magic-bin=={version}'然后按照本节指引重新创建知识库即可。
5. 启动项目
chatchat start -a
出现以下界面即为启动成功:

[!WARNING]
由于 chatchat 配置默认监听地址DEFAULT_BIND_HOST为 127.0.0.1, 所以无法通过其他 ip 进行访问。如需通过机器ip 进行访问(如 Linux 系统), 需要到
basic_settings.yaml中将监听地址修改为 0.0.0.0。
其它配置
- 数据库对话配置请移步这里 数据库对话配置说明
源码安装部署/开发部署
源码安装部署请参考 开发指南
Docker 部署
docker pull chatimage/chatchat:0.3.1.3-93e2c87-20240829
docker pull ccr.ccs.tencentyun.com/langchain-chatchat/chatchat:0.3.1.3-93e2c87-20240829 # 国内镜像
[!important] 强烈建议: 使用 docker-compose 部署, 具体参考 README_docker
旧版本迁移
- 0.3.x 结构改变很大,强烈建议您按照文档重新部署. 以下指南不保证100%兼容和成功. 记得提前备份重要数据!
- 首先按照
安装部署中的步骤配置运行环境,修改配置文件 - 将 0.2.x 项目的 knowledge_base 目录拷贝到配置的
DATA目录下
项目里程碑
-
2023年4月:Langchain-ChatGLM 0.1.0发布,支持基于 ChatGLM-6B 模型的本地知识库问答。 -
2023年8月:Langchain-ChatGLM改名为Langchain-Chatchat,发布0.2.0版本,使用fastchat作为模型加载方案,支持更多的模型和数据库。 -
2023年10月:Langchain-Chatchat 0.2.5发布,推出 Agent 内容,开源项目在Founder Park & Zhipu AI & Zilliz举办的黑客马拉松获得三等奖。 -
2023年12月:Langchain-Chatchat开源项目获得超过 20K stars. -
2024年6月:Langchain-Chatchat 0.3.0发布,带来全新项目架构。 -
🔥 让我们一起期待未来 Chatchat 的故事 ···
协议
本项目代码遵循 Apache-2.0 协议。
联系我们
Telegram
项目交流群
🎉 Langchain-Chatchat 项目微信交流群,如果你也对本项目感兴趣,欢迎加入群聊参与讨论交流。
公众号
🎉 Langchain-Chatchat 项目官方公众号,欢迎扫码关注。
引用
如果本项目有帮助到您的研究,请引用我们:
@software{langchain_chatchat,
title = {{langchain-chatchat}},
author = {Liu, Qian and Song, Jinke, and Huang, Zhiguo, and Zhang, Yuxuan, and glide-the, and liunux4odoo},
year = 2024,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{https://github.com/chatchat-space/Langchain-Chatchat}}
}