RAGFlow 知识库连接用于接入 RAGFlow 服务,为 Agent 提供基于外部知识库的数据检索能力。
适用场景
您已经部署 RAGFlow 服务。
您希望 Agent 使用 RAGFlow 数据集进行检索增强回答。
您需要通过独立 Base URL、API Key 和 Dataset ID 管理知识库访问。
前提条件
RAGFlow 服务可被 Agent 访问。
已创建并构建目标 Dataset。
已准备 RAGFlow API Key、Base URL 和 Dataset ID 列表。
创建并绑定连接
进入 Agent部署 页面。
选择 知识库 页签。
点击 创建知识库连接。
选择或填写 RAGFlow 知识库连接信息。
填写 API Key、Base URL 和 Dataset ID 列表。
创建完成后,进入 Agent 实例详情页。
打开 Agent 管理 > Agent 连接,选择 知识库。
绑定连接并验证检索效果。
RAGFlow 通常使用已有服务创建连接;如果页面没有 新建资源 入口,请先自行准备 RAGFlow 服务和 Dataset。
注入变量
变量 | 说明 |
| RAGFlow API Key。 |
| RAGFlow 服务访问地址。 |
| RAGFlow Dataset ID 列表,多个 ID 使用英文逗号分隔。 |
代码读取示例
import os
api_key = os.getenv("RAGFLOW_API_KEY")
base_url = os.getenv("RAGFLOW_BASE_URL")
dataset_ids = os.getenv("RAGFLOW_DATASET_IDS", "").split(",")代码开发接入
若通过代码创建 Agent,可以使用 computenest-agent-integrations 最新版对接 RAGFlow 知识库。该版本提供 create_knowledge_base_tools,可以根据平台注入的 RAGFlow 环境变量创建 Google ADK 可使用的检索工具。
安装依赖:
pip install -U computenest-agent-integrations参考格式:
from computenest.integrations.adk.tools.knowledge_factory import create_knowledge_base_tools
from google.adk.agents import LlmAgent
knowledge_tools = create_knowledge_base_tools()
root_agent = LlmAgent(
name="ragflow_knowledge_agent",
model=model,
instruction="你可以先检索知识库,再结合检索结果回答用户问题。",
tools=knowledge_tools,
)create_knowledge_base_tools 会读取 RAGFlow 相关环境变量。请确认 Agent 已绑定 RAGFlow 知识库连接,并且运行环境中已注入 RAGFLOW_API_KEY、RAGFLOW_BASE_URL 和 RAGFLOW_DATASET_IDS。
常见问题
检索请求失败
检查 RAGFLOW_BASE_URL 是否可访问,API Key 是否有效,Dataset ID 是否填写正确。
多个 Dataset 没有全部生效
确认 RAGFLOW_DATASET_IDS 使用英文逗号分隔,Agent 代码解析后传入了完整列表。