类 KnowledgeRetrievalTools

java.lang.Object
io.agentscope.core.rag.KnowledgeRetrievalTools

@Deprecated(forRemoval=true, since="2.0.0") public class KnowledgeRetrievalTools extends Object
已过时, 待删除: 此 API 元素将从以后的版本中删除。
since 2.0.0. The rag package is removed; integrate retrieval at the application layer.
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();
 
  • 构造器详细资料

    • KnowledgeRetrievalTools

      public KnowledgeRetrievalTools(Knowledge knowledge)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      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

      public KnowledgeRetrievalTools(Knowledge knowledge, RetrieveConfig defaultConfig)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Creates a new KnowledgeRetrievalTools instance.
      参数:
      knowledge - the knowledge base to retrieve from
      defaultConfig - 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, RuntimeContext ctx)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      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 documents
      limit - 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

      public Knowledge getKnowledgeBase()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Gets the knowledge base used by this tool.
      返回:
      the knowledge base
    • getDefaultConfig

      public RetrieveConfig getDefaultConfig()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Gets the default retrieval configuration.
      返回:
      the default config