← 返回 Skills 市场
xiaowenzhou

Dify Knowledge Base Search

作者 xiaowenzhou · GitHub ↗ · v1.1.1
cross-platform ✓ 安全检测通过
1197
总下载
0
收藏
2
当前安装
2
版本数
在 OpenClaw 中安装
/install dify-kb-search
功能描述
Search Dify Knowledge Base (Dataset) to get accurate context for RAG-enhanced answers.
使用说明 (SKILL.md)

Dify Knowledge Base Search Skill

🔍 Search your Dify Knowledge Base to get accurate, contextual answers

This skill enables AI agents to query Dify datasets for RAG (Retrieval-Augmented Generation) context retrieval. Perfect for knowledge base Q&A, documentation search, and contextual AI responses.

Dify Knowledge Base

✨ Features

  • List Knowledge Bases - Discover all available Dify datasets
  • Smart Search - Query datasets with hybrid, semantic, or keyword search
  • Auto-Discovery - Automatically find available datasets if ID not provided
  • Configurable Results - Adjust top-k, search method, and reranking
  • Error Handling - Graceful error messages for debugging
  • Zero Hardcoding - All configuration via environment variables

🚀 Quick Start

1. Configure Environment Variables

Set up in openclaw.json:

{
  "env": {
    "vars": {
      "DIFY_API_KEY": "${DIFY_API_KEY}",
      "DIFY_BASE_URL": "https://dify.example.com/v1"
    }
  }
}

Environment Variables:

Variable Required Default Description
DIFY_API_KEY ✅ Yes - Your Dify API Key (from Settings → API)
DIFY_BASE_URL ❌ No http://localhost/v1 Your Dify instance base URL

2. Install Dependencies

pip3 install requests

🛠️ Tools

dify_list

Lists all available knowledge bases (datasets) in your Dify instance.

Invocation: dify_list tool

Example Response:

{
  "status": "success",
  "count": 2,
  "datasets": [
    {
      "id": "dataset-abc123",
      "name": "Product Documentation",
      "doc_count": 42,
      "description": "All product guides and tutorials"
    },
    {
      "id": "dataset-xyz789",
      "name": "API Reference",
      "doc_count": 156,
      "description": "REST API documentation"
    }
  ]
}

Usage:

{}

dify_search

Searches a Dify Dataset for relevant context chunks.

Invocation: dify_search tool (mapped to python3 scripts/search.py)

Parameters:

Parameter Type Required Default Description
query string ✅ Yes - Search query or question
dataset_id string ❌ No Auto-discover Specific dataset ID to search
top_k integer ❌ No 3 Number of results to return
search_method string ❌ No hybrid_search Search strategy
reranking_enable boolean ❌ No false Enable reranking for better results

Search Methods:

  • hybrid_search - Combine semantic + keyword search (recommended)
  • semantic_search - Meaning-based similarity search
  • keyword_search - Exact keyword matching

Example Usage:

{
  "query": "How do I configure OpenClaw?",
  "top_k": 5
}
{
  "query": "API authentication methods",
  "dataset_id": "dataset-xyz789",
  "search_method": "semantic_search",
  "reranking_enable": true
}

Example Response:

{
  "status": "success",
  "query": "How do I configure OpenClaw?",
  "dataset_id": "dataset-abc123",
  "count": 3,
  "results": [
    {
      "content": "To configure OpenClaw, edit the openclaw.json file...",
      "score": 0.8923,
      "title": "Installation Guide",
      "document_id": "doc-001"
    },
    {
      "content": "OpenClaw supports environment variables via...",
      "score": 0.8451,
      "title": "Configuration Options",
      "document_id": "doc-002"
    }
  ]
}

📋 Complete Workflow Example

[
  {
    "tool": "dify_list",
    "parameters": {}
  },
  {
    "tool": "dify_search",
    "parameters": {
      "query": "What are the system requirements?",
      "top_k": 5,
      "search_method": "hybrid_search"
    }
  }
]

🔧 Troubleshooting

Common Errors

Error Solution
Missing DIFY_API_KEY Set DIFY_API_KEY in environment variables
Connection refused Check DIFY_BASE_URL is correct and accessible
No datasets found Verify dataset exists in your Dify workspace
API request failed Check network connectivity and API key permissions

Debug Mode

Run manually to see detailed errors:

DIFY_API_KEY=your-key python3 scripts/search.py \x3C\x3C\x3C '{"query":"test"}'

📚 Integration Tips

RAG Pipeline Integration

# Example: Use search results in AI response
results = dify_search(query, top_k=5)
context = "\
".join([r["content"] for r in results["results"]])
final_prompt = f"Answer based on context:\
\
{context}\
\
Question: {query}"

Multiple Datasets

For searching across multiple datasets, loop through them:

{
  "query": "Find information about authentication",
  "dataset_id": "dataset-api-docs"
}

Then query another dataset separately.

🔒 Security

  • Never commit API keys - Use environment variables or .env files
  • Rotate keys regularly - Generate new keys in Dify Settings
  • Restrict access - Limit API key permissions where possible

📖 Implementation Details

This skill uses the Dify Dataset API:

  • List Datasets: GET /v1/datasets
  • Search: POST /v1/datasets/{id}/retrieve

For API documentation, see: https://docs.dify.ai/reference/api-reference

📝 Changelog

v1.1.0 (2026-02-08):

  • ✅ Added search method selection (hybrid/semantic/keyword)
  • ✅ Added reranking support
  • ✅ Auto-discovery of datasets
  • ✅ Improved error handling
  • ✅ Removed hardcoded URLs (fully configurable)
  • ✅ Added detailed logging

v1.0.0 (2026-02-06):

  • Initial release
  • Basic list and search functionality
安全使用建议
This skill appears to do exactly what it says: query a Dify instance using DIFY_BASE_URL and DIFY_API_KEY. Before installing: 1) Ensure the DIFY_API_KEY you provide has least privilege (restrict access/permissions and rotate keys regularly). 2) Confirm DIFY_BASE_URL points to a trusted, TLS-enabled endpoint (https). 3) Double-check the platform's install step because the registry metadata shows an unexpected 'node' kind for Python packages — ensure the installer will use your system's python3 and pip3 and will not fetch arbitrary binaries. 4) Do not commit API keys into source control and consider running the skill in an environment with restricted network access if you want to limit blast radius.
功能分析
Type: OpenClaw Skill Name: dify-kb-search Version: 1.1.1 The OpenClaw skill 'dify-kb-search' is designed to interact with the Dify Knowledge Base API for RAG purposes. The `SKILL.md` clearly defines the skill's purpose, required environment variables (`DIFY_API_KEY`, `DIFY_BASE_URL`), and installation steps (`pip3 install requests`). The Python scripts (`scripts/list_datasets.py`, `scripts/search.py`) correctly implement the stated functionality, reading API keys from environment variables and making HTTP requests only to the configured Dify API endpoint. There is no evidence of data exfiltration to unauthorized endpoints, malicious execution, persistence mechanisms, prompt injection attempts against the agent, or obfuscation. All actions are aligned with the skill's stated purpose and follow secure coding practices for API integration.
能力评估
Purpose & Capability
Name/description match the actual behavior: both scripts list datasets and call Dify endpoints (/v1/datasets and /v1/datasets/{id}/retrieve). The required env vars (DIFY_API_KEY, DIFY_BASE_URL) are exactly what the code uses.
Instruction Scope
SKILL.md and the scripts limit actions to constructing HTTP requests to the Dify API, parsing responses, and printing JSON. The scripts only read the two declared environment variables and stdin parameters; they do not access other system files, credentials, or external endpoints.
Install Mechanism
Dependencies are minimal (python3 runtime + requests). SKILL.md instructs pip3 install requests and the code runs with python3. The registry install spec oddly labels these as kind: 'node' (for python3 and requests), which is inconsistent but appears to be a metadata/packaging quirk rather than malicious behavior. Verify that the platform's installer will run pip3 (not fetch arbitrary remote code).
Credentials
Only DIFY_API_KEY and DIFY_BASE_URL are required and used. This is proportionate for a Dify integration. No unrelated secrets or system credentials are requested.
Persistence & Privilege
always:false and standard tool invocation. The skill does not request permanent presence or modify other agents' configs. Autonomous invocation is allowed (platform default) but not combined with broad privileges.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install dify-kb-search
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /dify-kb-search 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.1
Security: Full deprecation - removed all example URLs
v1.1.0
Enhanced: Multiple search methods, auto-discovery, better error handling, full deprecation
元数据
Slug dify-kb-search
版本 1.1.1
许可证
累计安装 2
当前安装数 2
历史版本数 2
常见问题

Dify Knowledge Base Search 是什么?

Search Dify Knowledge Base (Dataset) to get accurate context for RAG-enhanced answers. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1197 次。

如何安装 Dify Knowledge Base Search?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install dify-kb-search」即可一键安装,无需额外配置。

Dify Knowledge Base Search 是免费的吗?

是的,Dify Knowledge Base Search 完全免费(开源免费),可自由下载、安装和使用。

Dify Knowledge Base Search 支持哪些平台?

Dify Knowledge Base Search 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Dify Knowledge Base Search?

由 xiaowenzhou(@xiaowenzhou)开发并维护,当前版本 v1.1.1。

💬 留言讨论