<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="/rss/stylesheet/" type="text/xsl"?>
<rss xmlns:content='http://purl.org/rss/1.0/modules/content/' xmlns:taxo='http://purl.org/rss/1.0/modules/taxonomy/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:itunes='http://www.itunes.com/dtds/podcast-1.0.dtd' xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:podbridge='http://www.podbridge.com/podbridge-ad.dtd' version='2.0'>
<channel>
  <title>奇诺分享 | blog.ccino.cc - 重在分享</title>
  <language>zh-cn</language>
  <generator>microfeed.org</generator>
  <itunes:type>episodic</itunes:type>
  <itunes:explicit>false</itunes:explicit>
  <atom:link rel="self" href="https://blog-ccino-cc.pages.dev/rss/" type="application/rss+xml"/>
  <link>https://blog.ccino.cc</link>
  <itunes:author>奇诺分享</itunes:author>
  <itunes:image href="https://cdn-blog-ccino-cc.ccino.cc/blog-ccino-cc/production/images/channel-6ebae07c242a357bee27d74ca3e4b3ce.png"/>
  <image>
    <title>奇诺分享 | blog.ccino.cc - 重在分享</title>
    <url>https://cdn-blog-ccino-cc.ccino.cc/blog-ccino-cc/production/images/channel-6ebae07c242a357bee27d74ca3e4b3ce.png</url>
    <link>https://blog.ccino.cc</link>
  </image>
  <copyright>©2024</copyright>
  <item>
    <title>实现本地 RAG 服务：整合 Open WebUI、Ollama 和 Qwen2.5</title>
    <guid>j-lAtZ2gXyq</guid>
    <pubDate>Wed, 09 Oct 2024 05:33:06 GMT</pubDate>
    <itunes:explicit>false</itunes:explicit>
    <description>
      <![CDATA[<h2>引言</h2><p><br></p><p>在构建信息检索和生成式 AI 应用时，Retrieval-Augmented Generation (RAG) 模型凭借其能够从知识库中检索相关信息并生成准确答案的强大能力，受到越来越多开发者的青睐。然而，实现端到端的本地 RAG 服务，需求的不只是合适的模型，还需要集成强大的用户界面和高效的推理框架。</p><p>在构建本地 RAG 服务时，利用易于部署的 Docker 方式，可以极大简化模型管理和服务集成。这里我们依赖 Open WebUI 提供的用户界面与模型推理服务，再通过 Ollama 来引入&nbsp;bge-m3&nbsp;embedding 模型以实现文档向量化方式的检索功能，从而帮助 Qwen 2.5 完成更精准的答案生成。</p><p>本文我们将讨论如何通过 Docker 快速启动 Open WebUI，同步 Ollama 的 RAG 能力，并结合 Qwen 2.5 模型实现高效的文档检索与生成系统。</p><h2><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e9%a1%b9%e7%9b%ae%e6%a6%82%e8%a7%88" rel="noopener noreferrer" target="_blank">#</a>&nbsp;项目概览</h2><p><br></p><p>该项目将使用以下关键工具：</p><ol><li><strong>Open WebUI</strong>&nbsp;: 提供用户与模型交互的 web 界面。</li><li><strong>Ollama</strong>&nbsp;: 用于管理 embedding 和大语言模型的模型推理任务。其中 Ollama 中的&nbsp;bge-m3&nbsp;模型将用于文档检索，Qwen 2.5 将负责回答生成。</li><li><strong>Qwen 2.5</strong>&nbsp;: 模型部分使用阿里推出的 Qwen 2.5 系列，为检索增强生成服务提供自然语言生成。</li></ol><p>为了实现 RAG 服务，我们需要以下步骤：</p><ol><li>部署 Open WebUI 作为用户交互界面。</li><li>配置 Ollama 以高效调度 Qwen 2.5 系列模型。</li><li>使用 Ollama 配置的名为&nbsp;bge-m3&nbsp;的 embedding 模型实现检索向量化处理。</li></ol><h2><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e9%83%a8%e7%bd%b2-open-webui" rel="noopener noreferrer" target="_blank">#</a>&nbsp;部署 Open WebUI</h2><p><br></p><p>Open WebUI 提供了一个简洁的 Docker 化解决方案，用户无需手动配置大量依赖，直接通过 Docker 启动 Web 界面。</p><p>首先，服务器上需要确保已经安装了&nbsp;<a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer" target="_blank">Docker</a>&nbsp;，如果没有安装，可以通过以下命令进行快速安装：</p><p>然后创建一个目录用于保存 Open WebUI 的数据，这样数据不会在项目更新后丢失：</p><p>接下来，我们可以通过以下命令来启动 Open WebUI ：</p><p>如果想要运行支持 Nvidia GPU 的 Open WebUI ，可以使用以下命令：</p><p>这里我们将 Open WebUI 的服务暴露在机器的 3000 端口，可以通过浏览器访问&nbsp;http://localhost:3000&nbsp;即可使用（远程访问则使用公网 ip ，开放 3000 端口）。/DATA/open-webui 是数据存储目录，你可以根据需要调整这个路径。</p><p>当然除了 Docker 安装方式外，你也可以通过 pip 、源码编译、Podman 等方式安装 Open WebUI 。更多安装方式请参考&nbsp;<a href="https://docs.openwebui.com/getting-started" rel="noopener noreferrer" target="_blank">Open WebUI 官方文档</a>&nbsp;。</p><h3><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae" rel="noopener noreferrer" target="_blank">#</a>&nbsp;基础设置</h3><ol><li>输入要注册的账号信息，<strong>设置强密码！！！</strong></li></ol><p><br></p><p>重要</p><p>第一个注册的用户将被自动设置为系统管理员，所以请确保你是第一个注册的用户。</p><ol><li>点击左下角头像，选择管理员面板</li><li>点击面板中的设置</li><li>关闭允许新用户注册（可选）</li><li>点击右下角保存</li></ol><p><img src="https://cuterwrite-1302252842.file.myqcloud.com/img/2024-09-21_openwebui_admin.webp"></p><h2><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e9%85%8d%e7%bd%ae-ollama-%e5%92%8c-qwen25" rel="noopener noreferrer" target="_blank">#</a>&nbsp;配置 Ollama 和 Qwen 2.5</h2><h3><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e9%83%a8%e7%bd%b2-ollama" rel="noopener noreferrer" target="_blank">#</a>&nbsp;部署 Ollama</h3><p><br></p><p>在本地服务器上安装 Ollama。目前 Ollama 提供多种安装方式，请参考 Ollama 的<a href="https://ollama.com/" rel="noopener noreferrer" target="_blank">官方文档</a>&nbsp;下载安装最新的&nbsp;0.3.11&nbsp;版本（Qwen 2.5 在该版本才开始支持）。安装细节可以参考我之前写的一篇文章：<a href="https://cuterwrite.top/p/ollama/" rel="noopener noreferrer" target="_blank">Ollama：从入门到进阶</a>&nbsp;。</p><p>启动 Ollama 服务（如果是 Docker 方式启动则不需要，但必须暴露 11434 端口）：</p><p>Ollama 服务启动后，可以通过访问地址&nbsp;http://localhost:11434&nbsp;连接到 Ollama 服务。</p><p><a href="https://ollama.com/library" rel="noopener noreferrer" target="_blank">Ollama Library</a>&nbsp;提供了语义向量模型 (&nbsp;bge-m3&nbsp;) 以及各大文本生成模型（包括 Qwen 2.5）。下一步我们将配置 Ollama 以适应本项目对文档检索和问答生成的需求。</p><h3><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e4%b8%8b%e8%bd%bd-qwen25-%e6%a8%a1%e5%9e%8b" rel="noopener noreferrer" target="_blank">#</a>&nbsp;下载 Qwen 2.5 模型</h3><p><br></p><p>通过 Ollama 安装 Qwen 2.5，你可以直接在命令行中运行&nbsp;ollama pull&nbsp;命令来下载 Qwen 2.5 模型，比如要下载 Qwen 2.5 的 72 B 模型，可以使用以下命令：</p><p>该命令将从 Ollama 的模型仓库抓取 Qwen 2.5 模型，并准备运行环境。</p><p>Qwen 2.5 提供了多种模型尺寸，包括 72 B、32 B、14 B、7 B、3 B、1.5 B、0.5 B 等，你可以根据自己的需求和 GPU 显存大小选择合适的模型。我采用的是 4 x V 100 的服务器，所以可以直接选择 72 B 模型。如果要求吐字速度快且能接收微小的性能损失的话，可以使用&nbsp;q4_0&nbsp;量化版本&nbsp;qwen2.5:72b-instruct-q4_0&nbsp;；如果能接受吐字速度慢一些，可以使用&nbsp;qwen2.5:72b-instruct-q5_K_M&nbsp;。对于 4 x V 100 的服务器，虽然&nbsp;q5_K_M&nbsp;模型的 token 生成明显卡顿，但是为了试验一下 Qwen 2.5 的性能，我还是选择了&nbsp;q5_K_M&nbsp;模型。</p><p>对于显存较少的个人电脑，推荐使用 14 B 或 7 B 模型，通过以下命令下载：</p><p>或者</p><p>如果你同时启动好了 Open WebUI 和 Ollama 服务，那么也可以在管理员面板中下载模型。</p><p><img src="https://cuterwrite-1302252842.file.myqcloud.com/img/2024-09-21_download_qwen2-5-7b.webp"></p><h3><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e4%b8%8b%e8%bd%bd-bge-m3-%e6%a8%a1%e5%9e%8b" rel="noopener noreferrer" target="_blank">#</a>&nbsp;下载 bge-m 3 模型</h3><p><br></p><p>在 Ollama 中下载&nbsp;bge-m3&nbsp;模型，该模型用于文档向量化处理。在命令行中运行以下命令下载模型（或者在 Open WebUI 界面下载）：</p><p>到这里，我们已经完成了 Ollama 的配置，接下来我们将在 Open WebUI 中配置 RAG 服务。</p><h2><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#rag-%e9%9b%86%e6%88%90%e4%b8%8e%e9%85%8d%e7%bd%ae" rel="noopener noreferrer" target="_blank">#</a>&nbsp;RAG 集成与配置</h2><h3><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e5%9c%a8-open-webui-%e4%b8%ad%e9%85%8d%e7%bd%ae-ollama-%e7%9a%84-rag-%e6%8e%a5%e5%8f%a3" rel="noopener noreferrer" target="_blank">#</a>&nbsp;在 Open WebUI 中配置 Ollama 的 RAG 接口</h3><h4><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e8%ae%bf%e9%97%ae-open-webui-%e7%ae%a1%e7%90%86%e7%95%8c%e9%9d%a2" rel="noopener noreferrer" target="_blank">#</a>&nbsp;访问 Open WebUI 管理界面</h4><p><br></p><p>启动 Open WebUI 之后，你可以直接通过 Web 浏览器访问服务地址，登录你的管理员账户，然后进入管理员面板。</p><h4><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e8%ae%be%e7%bd%ae-ollama-%e6%8e%a5%e5%8f%a3" rel="noopener noreferrer" target="_blank">#</a>&nbsp;设置 Ollama 接口</h4><p><br></p><p>在 Open WebUI 的管理员面板中，点击<strong>设置</strong>，你会看到外部连接的选项，确保 Ollama API 的地址为&nbsp;host.docker.internal:11434&nbsp;，然后点击右边的&nbsp;<strong>verify connection</strong>&nbsp;按钮确认 Ollama 服务是否正常连接。</p><p><img src="https://cuterwrite-1302252842.file.myqcloud.com/img/2024-09-21_ollama_api.webp"></p><h4><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e8%ae%be%e7%bd%ae%e8%af%ad%e4%b9%89%e5%90%91%e9%87%8f%e6%a8%a1%e5%9e%8b" rel="noopener noreferrer" target="_blank">#</a>&nbsp;设置语义向量模型</h4><p><br></p><p>在 Open WebUI 的管理员面板中，点击<strong>设置</strong>，接着点击<strong>文档</strong>，依次完成以下步骤：</p><ol><li>设置语义向量模型引擎为 Ollama 。</li><li>设置语义向量模型为&nbsp;bge-m3:latest&nbsp;。</li><li>其余设置可以保持默认，这里我设置了文件最大上传大小为 10 MB，最大上传数量为 3，Top K 设置为 5，块大小和块重叠分别设置为 1500 和 100 ，并开启 PDF 图像处理。</li><li>点击右下角保存。</li></ol><p><img src="https://cuterwrite-1302252842.file.myqcloud.com/img/2024-09-21_openwebui_embedding.webp"></p><h3><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e6%b5%8b%e8%af%95-rag-%e6%9c%8d%e5%8a%a1" rel="noopener noreferrer" target="_blank">#</a>&nbsp;测试 RAG 服务</h3><p><br></p><p>现在，你已经实现了完整的本地 RAG 系统。你可以在 Open WebUI 的主界面中输入任意自然语言问题，然后上传响应文档，系统会调用语义向量模型向量化文档，再使用 Qwen 2.5 模型检索文档生成答案并返回给用户。</p><p>在 Open WebUI 的用户聊天界面，上传你要检索的文档，然后输入你的问题，点击发送，Open WebUI 将会调用 Ollama 的&nbsp;bge-m3&nbsp;模型进行文档向量化处理，然后调用 Qwen 2.5 模型进行问答生成。</p><p>这里我上传了一个简单的&nbsp;txt&nbsp;文件（由 GPT 生成的文本），内容如下：</p><p>然后分别提了三个问题：</p><ol><li>艾文在森林中遇到的奇异生物是什么？</li><li>艾文在洞穴中找到的古老石板上刻的是什么？</li><li>艾文在祭坛中心发现了什么宝藏？</li></ol><p>下图是回答结果：</p><p><img src="https://cuterwrite-1302252842.file.myqcloud.com/img/2024-09-21_qwen2-5-QA.webp"></p><h2><a href="https://blog.ccino.org/p/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/#%e6%80%bb%e7%bb%93" rel="noopener noreferrer" target="_blank">#</a>&nbsp;总结</h2><p><br></p><p>借助 Open WebUI 和 Ollama，我们可以轻松搭建一个高效、直观的本地 RAG 系统。通过将&nbsp;bge-m3&nbsp;语义向量模型用于文本向量化，再结合 Qwen 2.5 生成模型，用户可以在一个统一的 Web 界面中进行文档检索与增强生成任务的高效互动。不但保护了数据隐私，还大幅提升了生成式 AI 的本地化应用能力。</p><p>本文出自：<a href="https://cuterwrite.top/p/integrate-open-webui-ollama-qwen25-local-rag/" rel="noopener noreferrer" target="_blank">实现本地 RAG 服务：整合 Open WebUI、Ollama 和 Qwen2.5</a></p>]]>
    </description>
    <link>https://blog.ccino.cc/i/implementing-local-rag-services-integrating-open-webui-ollama-and-qwen2.5/</link>
    <itunes:image href="https://cdn-blog-ccino-cc.ccino.cc/blog-ccino-cc/production/images/item-2ac21fca3291605b72ada659246e0e8b.png"/>
    <itunes:episodeType>full</itunes:episodeType>
    <enclosure url="https://cuterwrite.top/p/integrate-open-webui-ollama-qwen25-local-rag/" type="text/html"/>
  </item>
</channel>
</rss>