|
| 1 | +--- |
| 2 | +title: Integrating ApeRAG with Dify |
| 3 | +description: Quick integration of ApeRAG's Graph RAG capabilities via MCP protocol |
| 4 | +keywords: Dify, ApeRAG, MCP, Graph RAG |
| 5 | +--- |
| 6 | + |
| 7 | +# Integrating ApeRAG with Dify |
| 8 | + |
| 9 | +ApeRAG is a production-grade RAG platform with multimodal indexing, AI agents, MCP support, and scalable K8s deployment capabilities. It helps users build complex AI applications with **hybrid retrieval**, **multimodal document processing**, and **enterprise-grade management**. |
| 10 | + |
| 11 | +**Core Features**: |
| 12 | +- Unlike "standard" RAG, ApeRAG implements **Graph-RAG**, building knowledge graphs to understand deep relationships between data elements |
| 13 | +- Integrates **MinerU**, designed for complex documents, scientific papers, and financial reports, accurately extracting tables, formulas, and engineering diagrams |
| 14 | +- Full Kubernetes support with built-in **high availability**, **scalability**, and **enterprise-grade management** |
| 15 | + |
| 16 | +## Video Demo |
| 17 | + |
| 18 | +<div align="center"> |
| 19 | + <iframe src="//player.bilibili.com/player.html?bvid=BV1TRzABDEs3&page=1" |
| 20 | + scrolling="no" |
| 21 | + border="0" |
| 22 | + frameborder="no" |
| 23 | + framespacing="0" |
| 24 | + allowfullscreen="true" |
| 25 | + width="800" |
| 26 | + height="600" |
| 27 | + style="max-width: 100%;"> |
| 28 | + </iframe> |
| 29 | +</div> |
| 30 | + |
| 31 | +## Step 1: Prepare Knowledge Base |
| 32 | + |
| 33 | +Visit ApeRAG at https://rag.apecloud.com/ , register/login, and select or import a knowledge base. Here we use the Romance of the Three Kingdoms example - click subscribe. |
| 34 | + |
| 35 | +<div align="center"> |
| 36 | + <img src="/images/en-US/dify/step1-subscribe-collection.png" alt="Subscribe to Collection" width="800" /> |
| 37 | +</div> |
| 38 | + |
| 39 | +## Step 2: Configure MCP Server |
| 40 | + |
| 41 | +### 2.1 Add MCP Server |
| 42 | + |
| 43 | +Go to Dify - Tools - MCP, click Add MCP Server. |
| 44 | + |
| 45 | +<div align="center"> |
| 46 | + <img src="/images/en-US/dify/step2-add-mcp.png" alt="Add MCP Server" width="800" /> |
| 47 | +</div> |
| 48 | + |
| 49 | +### 2.2 Fill Configuration |
| 50 | + |
| 51 | +Fill in Server URL: `https://rag.apecloud.com/mcp/` and your API Key copied from ApeRAG, then click Confirm. |
| 52 | + |
| 53 | +<div align="center"> |
| 54 | + <img src="/images/en-US/dify/step2-configure-mcp.png" alt="Configure MCP" width="700" /> |
| 55 | +</div> |
| 56 | + |
| 57 | +<div align="center"> |
| 58 | + <img src="/images/en-US/dify/step2-api-key.png" alt="Fill API Key" width="700" /> |
| 59 | +</div> |
| 60 | + |
| 61 | +### 2.3 Success |
| 62 | + |
| 63 | +MCP Server added successfully. |
| 64 | + |
| 65 | +<div align="center"> |
| 66 | + <img src="/images/en-US/dify/step2-mcp-success.png" alt="MCP Configuration Success" width="800" /> |
| 67 | +</div> |
| 68 | + |
| 69 | +## Step 3: Create Agent Application |
| 70 | + |
| 71 | +### 3.1 Create App |
| 72 | + |
| 73 | +Go to Dify - Studio, click Create Application. |
| 74 | + |
| 75 | +<div align="center"> |
| 76 | + <img src="/images/en-US/dify/step3-create-app.png" alt="Create Application" width="800" /> |
| 77 | +</div> |
| 78 | + |
| 79 | +### 3.2 Select Type |
| 80 | + |
| 81 | +Click More Basic Application Types, select **Agent** type, name it, and click Create. |
| 82 | + |
| 83 | +<div align="center"> |
| 84 | + <img src="/images/en-US/dify/step3-select-agent.png" alt="Select Agent Type" width="700" /> |
| 85 | +</div> |
| 86 | + |
| 87 | +## Step 4: Configure Agent |
| 88 | + |
| 89 | +Click Agent, input Prompt, add the ApeRAG MCP tool, select the LLM in the top-right corner, click Publish to use. |
| 90 | + |
| 91 | +<div align="center"> |
| 92 | + <img src="/images/en-US/dify/step4-configure-agent.png" alt="Configure Agent" width="800" /> |
| 93 | +</div> |
| 94 | + |
| 95 | +<div align="center"> |
| 96 | + <img src="/images/en-US/dify/step4-test-agent.png" alt="Test Agent" width="800" /> |
| 97 | +</div> |
| 98 | + |
| 99 | +### Prompt Reference |
| 100 | + |
| 101 | +```markdown |
| 102 | +# ApeRAG Smart Assistant |
| 103 | + |
| 104 | +You are an advanced AI research assistant powered by ApeRAG's hybrid search capabilities. Your mission is to help users accurately and autonomously find, understand, and synthesize information from knowledge bases and the web. |
| 105 | + |
| 106 | +## Core Behaviors |
| 107 | + |
| 108 | +**Autonomous Research**: Work independently until user queries are fully resolved. Search multiple sources, analyze findings, and provide comprehensive answers without waiting for permission. |
| 109 | + |
| 110 | +**Language Intelligence**: Always respond in the language the user asks in. When users ask in Chinese, respond in Chinese regardless of source language. |
| 111 | + |
| 112 | +**Visual Thinking**: **[Critical]** You are an assistant that prefers visual explanations. For any information involving entity relationships, processes, or structures, you must prioritize visualization. |
| 113 | + |
| 114 | +**Complete Solutions**: Explore from multiple angles, cross-validate sources, and ensure comprehensive coverage before responding. |
| 115 | + |
| 116 | +## Search Strategy |
| 117 | + |
| 118 | +### Priority System |
| 119 | +1. **User-specified knowledge base** (mentioned via "@"): Strictly limit search to specified base |
| 120 | +2. **Unspecified knowledge base**: Autonomously discover and search relevant bases |
| 121 | +3. **Web search** (if enabled): Supplement information |
| 122 | +4. **Clear attribution**: Always cite sources |
| 123 | + |
| 124 | +### Search Execution |
| 125 | +- **Knowledge base search**: Use vector + graph search by default |
| 126 | +- **Result processing logic**: |
| 127 | + 1. Execute search |
| 128 | + 2. **Detect graph data**: Check if search results contain `entities` and `relationships` |
| 129 | + 3. **Mandatory visualization**: If search results contain non-empty entity or relation data, **you must** call the `create_diagram` tool |
| 130 | + 4. **Content filtering**: Ignore irrelevant results |
| 131 | + |
| 132 | +## Available Tools |
| 133 | + |
| 134 | +### Knowledge Management |
| 135 | +- `list_collections()`: Discover available knowledge sources |
| 136 | +- `search_collection(collection_id, query, ...)`: **[Primary tool]** Hybrid search in persistent knowledge bases |
| 137 | +- `search_chat_files(chat_id, query, ...)`: **[Chat only]** Search only files temporarily uploaded in current chat session |
| 138 | +- `create_diagram(content)`: **[Mandatory tool]** When search results contain structured info (entities/relations), must call this tool to generate Mermaid diagrams |
| 139 | + |
| 140 | +### Web Intelligence |
| 141 | +- `web_search(query, ...)`: Multi-engine web search |
| 142 | +- `web_read(url_list, ...)`: Extract and analyze web content |
| 143 | + |
| 144 | +## Response Format |
| 145 | + |
| 146 | +### Direct Answer |
| 147 | +[Clear, actionable answer in user's language] |
| 148 | + |
| 149 | +### Comprehensive Analysis |
| 150 | +[Detailed explanation with context and insights] |
| 151 | + |
| 152 | +### Knowledge Graph Visualization |
| 153 | +[Tool-generated diagram displayed here] |
| 154 | +*(Only show after successfully calling create_diagram. Displays entity relationships from search results.)* |
| 155 | + |
| 156 | +### Supporting Evidence |
| 157 | +- [Knowledge Base Name]: [Key Findings] |
| 158 | + |
| 159 | +**Web Sources** (if enabled): |
| 160 | +- [Title] ([Domain]) - [Key Points] |
| 161 | +``` |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +Integrating ApeRAG with Dify is very simple. Once integrated, you can not only experience Dify's platform features but also enjoy **ApeRAG's powerful Graph-RAG capabilities**! |
| 166 | + |
| 167 | +**GitHub**: https://github.com/apecloud/ApeRAG |
0 commit comments