从帮助文档中学习

用户或应用程序可以向 AppAgent 提供帮助文档,以增强其能力。AppAgent 可以从这些文档中检索知识,以提高其对任务的理解,生成高质量的计划,并更有效地与应用程序交互。您可以在帮助文档提供部分找到如何向 AppAgent 提供帮助文档。

机制

帮助文档以任务-解决方案对的格式提供。在收到请求后,AppAgent 通过将请求与帮助文档中的任务描述进行匹配来检索相关的帮助文档,并根据检索到的解决方案生成计划。

注意

由于检索到的帮助文档可能与请求不相关,因此 AppAgent 将仅将其作为参考来生成计划。

激活从帮助文档中学习

按照以下步骤激活从帮助文档中学习

步骤 1:提供帮助文档

请按照帮助文档提供文档中的步骤向 AppAgent 提供帮助文档。

步骤 2:配置 AppAgent

config.yaml 文件中配置以下参数以激活从帮助文档中学习

配置选项 描述 类型 默认值
RAG_OFFLINE_DOCS 是否使用离线 RAG 布尔值 False
RAG_OFFLINE_DOCS_RETRIEVED_TOPK 离线检索文档的 topk 整数 1

参考

基类:Retriever

用于创建离线检索器的类。

创建一个新的 OfflineDocRetriever。:appname: 应用程序的名称。

源代码位于 rag/retriever.py
83
84
85
86
87
88
89
90
def __init__(self, app_name: str) -> None:
    """
    Create a new OfflineDocRetriever.
    :appname: The name of the application.
    """
    self.app_name = app_name
    indexer_path = self.get_offline_indexer_path()
    self.indexer = self.get_indexer(indexer_path)

get_indexer(path)

加载检索器。

参数
  • path (str) –

    加载检索器的路径。

返回
  • 加载的检索器。

源代码位于 rag/retriever.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def get_indexer(self, path: str):
    """
    Load the retriever.
    :param path: The path to load the retriever from.
    :return: The loaded retriever.
    """

    if path:
        print_with_color(
            "Loading offline indexer from {path}...".format(path=path), "cyan"
        )
    else:
        return None

    try:
        db = FAISS.load_local(
            path, get_hugginface_embedding(), allow_dangerous_deserialization=True
        )
        return db
    except Exception as e:
        print_with_color(
            "Warning: Failed to load experience indexer from {path}, error: {error}.".format(
                path=path, error=e
            ),
            "yellow",
        )
        return None

get_offline_indexer_path()

获取离线索引器的路径。

返回
  • 离线索引器的路径。

源代码位于 rag/retriever.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def get_offline_indexer_path(self):
    """
    Get the path to the offline indexer.
    :return: The path to the offline indexer.
    """
    offline_records = get_offline_learner_indexer_config()
    for key in offline_records:
        if key.lower() in self.app_name.lower():
            return offline_records[key]

    return None