KnowledgeRetrievalTools
@Deprecated(forRemoval = true, since = "2.0.0") public class KnowledgeRetrievalTools
io/agentscope/core/rag/KnowledgeRetrievalTools.java:56–216知识库检索工具,封装可被智能体调用的能力。位于 io.agentscope.core.rag 包。核心成员包括 retrieveKnowledge、getKnowledgeBase、getDefaultConfig、KnowledgeRetrievalTools。
Knowledge retrieval tools for Agentic RAG mode.
This class provides tool methods that can be registered with agents to enable autonomous knowledge retrieval. Agents can call these tools to search the knowledge base when they need information.
This is the Agentic mode implementation - agents decide when and how to retrieve knowledge from the knowledge base.
Example usage:
`KnowledgeBase knowledgeBase = new SimpleKnowledge(embeddingModel, vectorStore);
KnowledgeRetrievalTools tools = new KnowledgeRetrievalTools(knowledgeBase, RetrieveConfig.builder().build());
Toolkit toolkit = new Toolkit();
toolkit.registerObject(tools);
ReActAgent agent = ReActAgent.builder()
.name("Assistant")
.model(chatModel)
.toolkit(toolkit)
.build();
`
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public KnowledgeRetrievalTools(Knowledge knowledge) | 创建新的KnowledgeRetrievalTools 实例使用默认配置。 Creates a new KnowledgeRetrievalTools instance with default configuration. |
public KnowledgeRetrievalTools(Knowledge knowledge, RetrieveConfig defaultConfig) | 创建新的KnowledgeRetrievalTools 实例。 Creates a new KnowledgeRetrievalTools instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public String retrieveKnowledge(String query, Integer limit, Agent agent, RuntimeContext ctx) | 检索知识库。 Retrieves relevant documents from the knowledge base. |
public Knowledge getKnowledgeBase() | 获取知识库。 Gets the knowledge base used by this tool. |
public RetrieveConfig getDefaultConfig() | 获取默认检索配置。 Gets the default retrieval configuration. |
构造器详情Constructor Detail
KnowledgeRetrievalTools
public KnowledgeRetrievalTools(Knowledge knowledge)
创建新的KnowledgeRetrievalTools 实例使用默认配置。
Creates a new KnowledgeRetrievalTools instance with default configuration.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
knowledge | Knowledge | 知识库基类到检索来自。the knowledge base to retrieve from |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if knowledgeBase is null
io/agentscope/core/rag/KnowledgeRetrievalTools.java:75–77KnowledgeRetrievalTools
public KnowledgeRetrievalTools(Knowledge knowledge, RetrieveConfig defaultConfig)
创建新的KnowledgeRetrievalTools 实例。
Creates a new KnowledgeRetrievalTools instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
knowledge | Knowledge | 知识库基类到检索来自。the knowledge base to retrieve from |
defaultConfig | RetrieveConfig | 默认检索配置。the default retrieval configuration |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if knowledgeBase is null
io/agentscope/core/rag/KnowledgeRetrievalTools.java:86–95方法详情Method Detail
retrieveKnowledge
public String retrieveKnowledge(String query, Integer limit, Agent agent, RuntimeContext ctx)
检索知识库。
Retrieves relevant documents from the knowledge base.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
query | String | 查询文本(类型 `String`)。the search query to find relevant documents |
limit | Integer | 数量上限(类型 `Integer`)。the maximum number of documents to retrieve (default: 5) |
agent | Agent | 智能体(类型 `Agent`)。the agent making the call (automatically injected by framework) |
ctx | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The ctx. |
Stringio/agentscope/core/rag/KnowledgeRetrievalTools.java:119–167getKnowledgeBase
public Knowledge getKnowledgeBase()
获取知识库。
Gets the knowledge base used by this tool.
Knowledgeio/agentscope/core/rag/KnowledgeRetrievalTools.java:204–206getDefaultConfig
public RetrieveConfig getDefaultConfig()
获取默认检索配置。
Gets the default retrieval configuration.
RetrieveConfigio/agentscope/core/rag/KnowledgeRetrievalTools.java:213–215