类 KnowledgeRetrievalTools
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();
-
构造器概要
构造器构造器说明KnowledgeRetrievalTools(Knowledge knowledge) Creates a new KnowledgeRetrievalTools instance with default configuration.KnowledgeRetrievalTools(Knowledge knowledge, RetrieveConfig defaultConfig) Creates a new KnowledgeRetrievalTools instance. -
方法概要
修饰符和类型方法说明Gets the default retrieval configuration.Gets the knowledge base used by this tool.retrieveKnowledge(String query, Integer limit, Agent agent) Retrieves relevant documents from the knowledge base.
-
构造器详细资料
-
KnowledgeRetrievalTools
Creates a new KnowledgeRetrievalTools instance with default configuration.Default configuration:
- Limit: 5 documents
- Score threshold: 0.5
- 参数:
knowledge- the knowledge base to retrieve from- 抛出:
IllegalArgumentException- if knowledgeBase is null
-
KnowledgeRetrievalTools
Creates a new KnowledgeRetrievalTools instance.- 参数:
knowledge- the knowledge base to retrieve fromdefaultConfig- the default retrieval configuration- 抛出:
IllegalArgumentException- if knowledgeBase is null
-
-
方法详细资料
-
retrieveKnowledge
@Tool(name="retrieve_knowledge", description="Retrieve relevant documents from knowledge base. Use this tool when you need to find specific information or when user asks questions about stored knowledge.") public String retrieveKnowledge(@ToolParam(name="query",description="The search query to find relevant documents in the knowledge base") String query, @ToolParam(name="limit",description="Maximum number of documents to retrieve (default: 5)",required=false) Integer limit, Agent agent) Retrieves relevant documents from the knowledge base.This tool method allows agents to search the knowledge base for information relevant to a query. The agent can specify how many documents to retrieve.
If the agent has conversation history in memory, that history will be automatically included in the retrieval configuration. Knowledge bases that support multi-turn conversation context (like Bailian) can use this history to improve retrieval accuracy.
Use this tool when:
- The user asks questions about stored knowledge
- You need to find specific information from the knowledge base
- You want to provide context-aware responses based on stored documents
- 参数:
query- the search query to find relevant documentslimit- the maximum number of documents to retrieve (default: 5)agent- the agent making the call (automatically injected by framework)- 返回:
- a formatted string containing the retrieved documents and their scores
-
getKnowledgeBase
Gets the knowledge base used by this tool.- 返回:
- the knowledge base
-
getDefaultConfig
Gets the default retrieval configuration.- 返回:
- the default config
-