类 GenericRAGHook
- 所有已实现的接口:
Hook
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:
- Extracts the query from user messages
- Retrieves relevant documents from the knowledge base
- Injects the retrieved knowledge as a user message
- 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)
-
构造器概要
构造器构造器说明GenericRAGHook(Knowledge knowledge) Creates a GenericRAGHook with default configuration.GenericRAGHook(Knowledge knowledge, RetrieveConfig defaultConfig) Creates a GenericRAGHook with custom configuration. -
方法概要
-
构造器详细资料
-
GenericRAGHook
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
Creates a GenericRAGHook with custom configuration.- 参数:
knowledge- the knowledge base to retrieve fromdefaultConfig- the default retrieval configuration- 抛出:
IllegalArgumentException- if knowledgeBase is null
-
-
方法详细资料
-
onEvent
从接口复制的说明:HookHandle 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:
PreReasoningEvent- Modify messages before LLM reasoningPostReasoningEvent- Modify reasoning resultsPreActingEvent- Modify tool parameters before executionPostActingEvent- Modify tool resultsPreCallEvent- Modify messages before agent startsPostCallEvent- Modify final agent response
Notification Events: Events without setters are read-only:
ReasoningChunkEvent- Streaming reasoning chunksActingChunkEvent- Streaming tool execution chunksErrorEvent- Errors during execution
-
priority
public int priority()从接口复制的说明:HookThe 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)
-
getKnowledgeBase
Gets the knowledge base used by this hook.- 返回:
- the knowledge base
-
getDefaultConfig
Gets the default retrieval configuration.- 返回:
- the default config
-