GenericRAGHook
@Deprecated(forRemoval = true, since = "2.0.0") public class GenericRAGHook implements Hook
io/agentscope/core/rag/GenericRAGHook.java:69–236泛型 RAG 钩子,把私有文档转化为可检索的知识。位于 io.agentscope.core.rag 包,实现 Hook。核心成员包括 onEvent、priority、getKnowledgeBase、getDefaultConfig、GenericRAGHook。
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:
-
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)
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public GenericRAGHook(Knowledge knowledge) | 创建GenericRAGHook 使用默认配置。 Creates a GenericRAGHook with default configuration. |
public GenericRAGHook(Knowledge knowledge, RetrieveConfig defaultConfig) | 创建GenericRAGHook 使用自定义配置。 Creates a GenericRAGHook with custom configuration. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public T extends HookEvent Mono<T> onEvent(T event) | 处理事件事件。 Performs the on event operation. |
public int priority() | 返回优先级。 Returns the priority. |
public Knowledge getKnowledgeBase() | 获取知识库。 Gets the knowledge base used by this hook. |
public RetrieveConfig getDefaultConfig() | 获取默认检索配置。 Gets the default retrieval configuration. |
构造器详情Constructor Detail
GenericRAGHook
public GenericRAGHook(Knowledge knowledge)
创建GenericRAGHook 使用默认配置。
Creates a GenericRAGHook with default configuration.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
knowledge | Knowledge | 知识库基类到检索来自。the knowledge base to retrieve from |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if knowledgeBase is null
io/agentscope/core/rag/GenericRAGHook.java:89–91GenericRAGHook
public GenericRAGHook(Knowledge knowledge, RetrieveConfig defaultConfig)
创建GenericRAGHook 使用自定义配置。
Creates a GenericRAGHook with custom configuration.
| 名称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/GenericRAGHook.java:100–109方法详情Method Detail
onEvent
public T extends HookEvent Mono<T> onEvent(T event)
处理事件事件。
Performs the on event operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
event | T | 事件(类型 `T`)。The event. |
Mono<T>io/agentscope/core/rag/GenericRAGHook.java:111–119priority
public int priority()
返回优先级。
Returns the priority.
intio/agentscope/core/rag/GenericRAGHook.java:121–125getKnowledgeBase
public Knowledge getKnowledgeBase()
获取知识库。
Gets the knowledge base used by this hook.
Knowledgeio/agentscope/core/rag/GenericRAGHook.java:224–226getDefaultConfig
public RetrieveConfig getDefaultConfig()
获取默认检索配置。
Gets the default retrieval configuration.
RetrieveConfigio/agentscope/core/rag/GenericRAGHook.java:233–235