AS AgentScopeAPI 手册 / API Reference

GenericRAGHook

@Deprecated(forRemoval = true, since = "2.0.0") public class GenericRAGHook implements Hook
源码Source 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.

参数Parameters
名称Name类型Type说明Description
knowledgeKnowledge知识库基类到检索来自。the knowledge base to retrieve from
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if knowledgeBase is null
源码Source io/agentscope/core/rag/GenericRAGHook.java:89–91

GenericRAGHook

public GenericRAGHook(Knowledge knowledge, RetrieveConfig defaultConfig)

创建GenericRAGHook 使用自定义配置。

Creates a GenericRAGHook with custom configuration.

参数Parameters
名称Name类型Type说明Description
knowledgeKnowledge知识库基类到检索来自。the knowledge base to retrieve from
defaultConfigRetrieveConfig默认检索配置。the default retrieval configuration
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if knowledgeBase is null
源码Source 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.

参数Parameters
名称Name类型Type说明Description
eventT事件(类型 `T`)。The event.
返回Returns Mono<T>
返回Mono。Returns mono.
源码Source io/agentscope/core/rag/GenericRAGHook.java:111–119

priority

public int priority()

返回优先级。

Returns the priority.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/core/rag/GenericRAGHook.java:121–125

getKnowledgeBase

public Knowledge getKnowledgeBase()

获取知识库。

Gets the knowledge base used by this hook.

返回Returns Knowledge
知识库基类。the knowledge base
源码Source io/agentscope/core/rag/GenericRAGHook.java:224–226

getDefaultConfig

public RetrieveConfig getDefaultConfig()

获取默认检索配置。

Gets the default retrieval configuration.

返回Returns RetrieveConfig
默认配置。the default config
源码Source io/agentscope/core/rag/GenericRAGHook.java:233–235

继承成员Inherited Members

继承自Methods inherited from Hook
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.