Dify External Datasets Service is a service that implements Dify's external knowledge base API, integrating with RagFlow knowledge base.
- Document retrieval based on knowledge base ID
- Configurable retrieval parameters (top_k, score_threshold)
- Bearer token authentication
- Error handling and standardized response format
- Create .env file
- Configure environment variables
# RagFlow API server address API_URL=http://127.0.0.1:12180 - Start the service using docker-compose
docker-compose up -d
- The service will be available at
URL_ADDRESS:18121
- Clone the repository
- Create .env file
- Configure environment variables
# RagFlow API server address API_URL=http://127.0.0.1:12180 - Start the service
go run main.go
- The service will be available at
URL_ADDRESS:8080
-
URL:
/retrieval -
Method: POST
-
Headers:
- Content-Type: application/json
- Authorization: Bearer
-
Request Body:
{
"knowledge_id": "your-knowledge-base-id",
"query": "your search query",
"retrieval_setting": {
"top_k": 5,
"score_threshold": 0.7
}
}- Response:
{
"records": [
{
"metadata": {
"path": "document-url",
"description": "document-name"
},
"score": 0.85,
"title": "document-title",
"content": "matched-content"
}
]
}- Connect to External Knowledge Bases
- How to get knowledge_id
Dify External Datasets Service 是一个实现了 Dify 外部知识库 API 的服务,实现了接入 RagFlow 知识库。
- 基于知识库 ID 的文档检索
- 可配置的检索参数(top_k, score_threshold)
- Bearer token 认证
- 错误处理和标准化响应格式
- 创建 .env 文件
- 配置环境变量
# RagFlow Api 服务器地址 API_URL=http://127.0.0.1:12180 - 使用 docker-compose 启动服务
docker-compose up -d
- 服务将在
URL_ADDRESS:18121上可用
- 克隆代码仓库
- 创建 .env 文件
- 配置环境变量
# RagFlow Api 服务器地址 API_URL=http://127.0.0.1:12180 - 启动服务
go run main.go
- 服务将在
URL_ADDRESS:8080上可用
-
接口地址:
/retrieval -
请求方法:POST
-
请求头:
- Content-Type: application/json
- Authorization:
Bearer <your-token>
-
请求体:
{
"knowledge_id": "知识库ID",
"query": "检索查询语句",
"retrieval_setting": {
"top_k": 5,
"score_threshold": 0.7
}
}- 响应示例:
{
"records": [
{
"metadata": {
"path": "文档URL",
"description": "文档名称"
},
"score": 0.85,
"title": "文档标题",
"content": "匹配内容"
}
]
}- 连接外部知识库 见文档: 连接外部知识库
- 如何获取 knowledge_id

