AS AgentScopeAPI 手册 / API Reference

DifyKnowledge

public class DifyKnowledge implements Knowledge
源码Source io/agentscope/core/rag/integration/dify/DifyKnowledge.java:84–315

Dify 知识库,把私有文档转化为可检索的知识。位于 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.

参数Parameters
名称Name类型Type说明Description
documentsList<Document>文档到添加的列出。the list of documents to add
返回Returns Mono<Void>
返回Mono。a Mono that completes with an error indicating the operation is not supported
源码Source io/agentscope/core/rag/integration/dify/DifyKnowledge.java:124–132

retrieve

public Mono<List<Document>> retrieve(String query, RetrieveConfig config)

按查询检索相关文档。

Retrieves relevant documents based on a query.

参数Parameters
名称Name类型Type说明Description
queryString搜索查询文本。the search query text
configRetrieveConfig检索配置(限制,分数阈值)。the retrieval configuration (limit, score threshold)
返回Returns Mono<List<Document>>
返回Mono>。a Mono that emits a list of relevant Document objects, sorted by relevance
源码Source io/agentscope/core/rag/integration/dify/DifyKnowledge.java:164–206

getClient

public DifyRAGClient getClient()

获取客户端。

Gets the Dify API client.

返回Returns DifyRAGClient
客户端。the client
源码Source io/agentscope/core/rag/integration/dify/DifyKnowledge.java:213–215

getConfig

public DifyRAGConfig getConfig()

获取配置。

Gets the Dify configuration.

返回Returns DifyRAGConfig
返回DifyRAGConfig。the configuration, or null if not available
源码Source io/agentscope/core/rag/integration/dify/DifyKnowledge.java:222–224

builder

public static Builder builder()
static

创建新的构建器用于 DifyKnowledge。

Creates a new builder for DifyKnowledge.

返回Returns Builder
一种新的构建器实例。a new Builder instance
源码Source io/agentscope/core/rag/integration/dify/DifyKnowledge.java:248–250

嵌套类详情Nested Class Detail

Builder

public static class Builder

DifyKnowledge的构建器。位于 io.agentscope.core.rag.integration.dify 包。核心成员包括 config、client、build。

Builder for DifyKnowledge.

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.