DifyKnowledge
public class DifyKnowledge implements Knowledge
io/agentscope/core/rag/integration/dify/DifyKnowledge.java:84–315Dify 知识库,把私有文档转化为可检索的知识。位于 io.agentscope.core.rag.integration.dify 包,实现 Knowledge。核心成员包括 addDocuments、retrieve、getClient、getConfig、builder。
Dify Cloud Knowledge Base implementation.
This class provides integration with Dify Knowledge Base service, implementing the Knowledge interface to enable seamless RAG (Retrieval-Augmented Generation) capabilities with Dify-hosted or self-hosted knowledge bases.
Key features:
-
Cloud-hosted or self-hosted Dify deployment support
-
Multiple retrieval modes (keyword, semantic, hybrid, fulltext)
-
Advanced features like reranking and score filtering
-
Conversation history support for context-aware retrieval
-
Compatible with Bailian RAG plugin (same Knowledge interface)
Functional Scope: This plugin focuses on retrieval capabilities only, similar to Bailian RAG plugin. Document management (upload/delete/update) should be performed via Dify console.
Example usage:
`// 1. Configure Dify connection
DifyRAGConfig config = DifyRAGConfig.builder()
.apiKey(System.getenv("DIFY_RAG_API_KEY"))
.datasetId("your-dataset-id") // Configure in code
.retrievalMode(RetrievalMode.HYBRID_SEARCH)
.enableRerank(true)
.build();
// 2. Create knowledge base instance
DifyKnowledge knowledge = DifyKnowledge.builder()
.config(config)
.build();
// 3. Retrieve documents
RetrieveConfig retrieveConfig = RetrieveConfig.builder()
.limit(5)
.scoreThreshold(0.5)
.build();
List<Document> results = knowledge.retrieve("query text", retrieveConfig).block();
// 4. Use with agents via built-in RAG configuration
ReActAgent agent = ReActAgent.builder()
.name("Assistant")
.model(chatModel)
.knowledge(knowledge)
.ragMode(RAGMode.AGENTIC)
.build();
`
Note: Document management is not supported via this plugin. Please use Dify console to upload, delete, and manage documents. This design ensures compatibility with Bailian RAG plugin and keeps the plugin focused.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | DifyKnowledge的构建器。 Builder for DifyKnowledge. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Mono<Void> addDocuments(List<Document> documents) | 添加文档。 Adds documents to the knowledge base. |
public Mono<List<Document>> retrieve(String query, RetrieveConfig config) | 按查询检索相关文档。 Retrieves relevant documents based on a query. |
public DifyRAGClient getClient() | 获取客户端。 Gets the Dify API client. |
public DifyRAGConfig getConfig() | 获取配置。 Gets the Dify configuration. |
public static Builder builder()static | 创建新的构建器用于 DifyKnowledge。 Creates a new builder for DifyKnowledge. |
方法详情Method Detail
addDocuments
public Mono<Void> addDocuments(List<Document> documents)
添加文档。
Adds documents to the knowledge base.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
documents | List<Document> | 文档到添加的列出。the list of documents to add |
Mono<Void>io/agentscope/core/rag/integration/dify/DifyKnowledge.java:124–132retrieve
public Mono<List<Document>> retrieve(String query, RetrieveConfig config)
按查询检索相关文档。
Retrieves relevant documents based on a query.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
query | String | 搜索查询文本。the search query text |
config | RetrieveConfig | 检索配置(限制,分数阈值)。the retrieval configuration (limit, score threshold) |
Mono<List<Document>>io/agentscope/core/rag/integration/dify/DifyKnowledge.java:164–206getClient
public DifyRAGClient getClient()
获取客户端。
Gets the Dify API client.
DifyRAGClientio/agentscope/core/rag/integration/dify/DifyKnowledge.java:213–215getConfig
public DifyRAGConfig getConfig()
获取配置。
Gets the Dify configuration.
DifyRAGConfigio/agentscope/core/rag/integration/dify/DifyKnowledge.java:222–224builder
public static Builder builder()
创建新的构建器用于 DifyKnowledge。
Creates a new builder for DifyKnowledge.
Builderio/agentscope/core/rag/integration/dify/DifyKnowledge.java:248–250嵌套类详情Nested Class Detail
Builder
public static class BuilderDifyKnowledge的构建器。位于 io.agentscope.core.rag.integration.dify 包。核心成员包括 config、client、build。
Builder for DifyKnowledge.