类 GenericRAGHook

java.lang.Object
io.agentscope.core.rag.GenericRAGHook
所有已实现的接口:
Hook

@Deprecated(forRemoval=true, since="2.0.0") public class GenericRAGHook extends Object implements Hook
已过时, 待删除: 此 API 元素将从以后的版本中删除。
since 2.0.0. The rag package is removed; integrate retrieval at the application layer.
Generic RAG Hook for automatic knowledge retrieval before reasoning.

This hook implements the Generic RAG mode, where knowledge is automatically retrieved and injected into the prompt before each reasoning step. Unlike Agentic mode (where agents decide when to retrieve), Generic mode always retrieves relevant knowledge for user queries.

This hook intercepts PreReasoningEvent and:

  1. Extracts the query from user messages
  2. Retrieves relevant documents from the knowledge base
  3. Injects the retrieved knowledge as a user message
  4. Modifies the input messages to include the knowledge context

Example usage:


 KnowledgeBase knowledgeBase = new SimpleKnowledge(embeddingModel, vectorStore);
 GenericRAGHook ragHook = new GenericRAGHook(knowledgeBase);

 ReActAgent agent = ReActAgent.builder()
     .name("Assistant")
     .model(chatModel)
     .hook(ragHook)
     .build();
 

Configuration options:

  • defaultConfig - Retrieval configuration (limit, score threshold)
  • 构造器概要

    构造器
    构造器
    说明
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Creates a GenericRAGHook with default configuration.
    GenericRAGHook(Knowledge knowledge, RetrieveConfig defaultConfig)
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Creates a GenericRAGHook with custom configuration.
  • 方法概要

    修饰符和类型
    方法
    说明
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Gets the default retrieval configuration.
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Gets the knowledge base used by this hook.
    <T extends HookEvent>
    reactor.core.publisher.Mono<T>
    onEvent(T event)
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Handle a hook event.
    int
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    The priority of this hook (lower value = higher priority).

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    从接口继承的方法 io.agentscope.core.hook.Hook

    tools
  • 构造器详细资料

    • GenericRAGHook

      public GenericRAGHook(Knowledge knowledge)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Creates a GenericRAGHook with default configuration.

      Default configuration:

      • Limit: 5 documents
      • Score threshold: 0.5
      参数:
      knowledge - the knowledge base to retrieve from
      抛出:
      IllegalArgumentException - if knowledgeBase is null
    • GenericRAGHook

      public GenericRAGHook(Knowledge knowledge, RetrieveConfig defaultConfig)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Creates a GenericRAGHook with custom configuration.
      参数:
      knowledge - the knowledge base to retrieve from
      defaultConfig - the default retrieval configuration
      抛出:
      IllegalArgumentException - if knowledgeBase is null
  • 方法详细资料

    • onEvent

      public <T extends HookEvent> reactor.core.publisher.Mono<T> onEvent(T event)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      从接口复制的说明: Hook
      Handle a hook event.

      This method is called for all agent execution events. Use pattern matching to handle specific event types.

      Modifiable Events: For events with setters, you can modify the context and the changes will affect agent execution:

      Notification Events: Events without setters are read-only:

      指定者:
      onEvent 在接口中 Hook
      类型参数:
      T - The concrete event type
      参数:
      event - The hook event
      返回:
      Mono containing the potentially modified event
    • priority

      public int priority()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      从接口复制的说明: Hook
      The priority of this hook (lower value = higher priority).

      Hooks are executed in ascending priority order. Hooks with the same priority execute in their registration order.

      Common Priority Ranges:

      • 0-50: Critical system hooks (auth, security)
      • 51-100: High priority hooks (validation, preprocessing)
      • 101-500: Normal priority hooks (business logic)
      • 501-1000: Low priority hooks (logging, metrics)
      指定者:
      priority 在接口中 Hook
      返回:
      The priority value (default: 100)
    • getKnowledgeBase

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

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