改善Discourse AI中搜索筛选器的质量

首先,这真是太棒了——非常感谢!:heart_eyes:

我有一个关于我创建的具有以下启用命令的角色的问题:搜索、类别、读取、标签。

我还上传了一个 .txt 文件。我创建这个角色的目标是让它始终搜索我的论坛上传的内容,并对两者都执行 RAG。

上传 .txt 文件后,我注意到它停止搜索我的论坛了。这是我的基础搜索查询中的内容: #docs #faqs #anking-wiki
#docs#faqs 是类别,而 #anking-wiki 是一个标签。

问题:

  • 我真的需要类别和标签命令吗?我看到这些命令只是列出了我实例中的标签和类别。似乎搜索命令就足够了。
  • 我的基础搜索查询可以吗?
  • 为什么机器人停止搜索我的论坛了?
    • 解决方案仅仅是调整我的提示以明确它应该始终使用搜索功能吗?

这是调试信息中看到的提示:

你是 AnkiHub 用户的一个有用的 Discourse 助手。
你_理解_并生成 Discourse Markdown。
你生活在一个 Discourse 论坛消息中。
你生活在以下 URL 的论坛中:https://community.ankihub.net
你的网站标题:AnkiHub Community
描述是:AnkiHub 和 AnKing 项目的社区论坛
此对话的参与者是:gpt4o_bot, andrew
现在日期是:2024-06-07 23:32:13 UTC,自你训练以来已经发生了很大变化。
你是基于旧数据训练的,请依赖搜索来获取有关此论坛的最新信息。
搜索时尽量简化搜索词。
Discourse 搜索会将所有词语用 AND 连接。减少和简化词语以找到更多结果。

以下文本将为你提供额外的指导。 我们将其包含在内,因为我们认为它们与此对话主题相关。 文本:

我尝试在我的提示中添加“确保始终使用搜索功能”。这确实导致它使用了搜索功能,但结果不佳:Missing Images After AnkiHub Version Update Issue - AI Conversation - AnkiHub Community

它似乎进行了 3 次搜索,并错误地报告“找到 0 个结果”,这三次都是如此。如果你点击搜索结果链接,你会发现实际上是有结果的。此外,你可以看到我的“基础搜索查询”中的参数没有被使用,所以它搜索了整个论坛而不是特定的类别。

我认为这里部分问题在于我们的搜索有点令人困惑:

https://meta.discourse.org/search?q=%23bug%20%23feature%20test

搜索 Bug AND Feature - test

你想要的是:

https://meta.discourse.org/search?q=categories%3Abug%2Cfeature%20test

2 个赞

我很困惑。这并没有按我期望的那样工作。我期望搜索结果仅限于指定的类别。然而,搜索结果却来自任何类别。此搜索的第一个结果来自 Theme component 类别。

2 个赞

确实,这看起来有些问题,哦不,我会看看的。

1 个赞

已修复,请参阅:

我同意支持 #bug #feature something 是直观的,但这目前还不完全支持,还需要一些讨论。

categories:bug,feature something 现在可以工作,category:bug,feature something 也可以。

1 个赞

太棒了!感谢您如此迅速地发布了修复程序。:bowing_man:

虽然搜索现在可以正常工作了,但 Discourse AI Bot 似乎仍然无法按预期工作。以下是我在使用 3.3.0.beta3-dev (a1d881f625) 时的一些观察结果:

  • 不使用 base_query 选项
  • 搜索结果未添加到 RAG 的上下文中
    • 当调用搜索工具时(尽管没有 base_query),结果似乎没有在 LLM 调用中使用。
    • 我是否误解了这个工具应该如何工作?我期望它能进行 Discourse 搜索并使用搜索结果(即找到的主题内容)来进行 RAG。
      例如,请看这个请求:
请求 JSON
{"model":"gpt-4","messages":[{"role":"system","content":"You are a friendly and helpful assistant for Anki users specializing in the AnkiHub add-on and web app.\nYou _understand_ and **generate** Discourse Markdown.\nYou live in a Discourse Forum Message.\n\nYou live in the forum with the URL: https://community.ankihub.net\nYou answer questions specifically about using Anki with AnkiHub.\nThe title of your site: AnkiHub Community\nThe description is: A community forum for the AnkiHub and AnKing projects\nThe participants in this conversation are: gpt4_bot, andrew\nThe date now is: 2024-06-13 18:29:19 UTC, much has changed since you were\ntrained.\nYou were trained on OLD data, lean on search to get up to date information about this forum\nWhen searching try to SIMPLIFY search terms\nDiscourse search joins all terms with AND. Reduce and simplify terms to find more results."},{"role":"user","content":"Can I purchase accounts for other users and automatically subscribe them to my private decks?","name":"andrew"},{"role":"assistant","content":null,"tool_calls":[{"type":"function","function":{"arguments":"{\"search_query\":\"purchase accounts for other users subscribe private decks\"}","name":"search"},"id":"call_fmzwIbU4ravFRKWRsOQlqGBq"}]},{"role":"tool","tool_call_id":"call_fmzwIbU4ravFRKWRsOQlqGBq","content":"{\"column_names\":[\"title\",\"url\",\"username\",\"excerpt\",\"created\",\"category\",\"likes\",\"topic_views\",\"topic_likes\",\"topic_replies\",\"tags\"],\"rows\":[[39;1;m\"👪 Organizations\"0;m,\"39;/t/organizations/166454/1\"0;m,\"39;andrew\"0;m,\"39;\\u003ca name=\\\\\\\"what-are-ankihub-organizations-1\\\\\\\" class=\\\\\\\"anchor\\\\\\\" href=\\\\\\\"#what-are-ankihub-organizations-1\\\\\\\"\\\\u003e\\\\u003c/a\\\\u003eWhat are AnkiHub Organizations\\\\nAnkiHub Organizations allow Organization Owners to purchase AnkiHub for other users and invite those users to the Organization. \\\\nAnkiHub organizations work like this and have the following features: \\\\n\\\\u003ca name=\\\\\\\"linked-decks-2\\\\\\\" class=\\\\\\\"anchor\\\\\\\" href=\\\\\\\"#linked-decks-2\\\\\\\"\\\\u003e\\\\u003c/a\\\\u003eLinked Decks\\\\nUsers in your organization can automatically get access \\\\u0026hellip;\"0;m,\"39;2024-02-08T17:44:27.842Z\"0;m,\"39;🎓 Docs \\\\u003e 🤝 Create \\\\u0026 Collaborate\"0;m,1,166,1,1],[39;1;m\"How can I get my school to buy AnkiHub for my class?\"0;m,\"39;/t/how-can-i-get-my-school-to-buy-ankihub-for-my-class/228569/1\"0;m,\"39;andrew\"0;m,\"39;Some students have successfully gotten their schools to sponsor AnkiHub memberships for their students. To do so, your school must create an AnkiHub Organization: \\\\n\\\\n\\\\n:bulb: Here are some tips for getting your school to purchase AnkiHub: \\\\n\\\\nConnect with your school’s student government people or med e\\\\u0026hellip;\"0;m,\"39;2024-05-23T21:40:37.477Z\"0;m,\"39;❓ FAQs\"0;m,0,50,0,1],[39;1;m\"What happens after my AnkiHub subscription ends?\"0;m,\"39;/t/what-happens-after-my-ankihub-subscription-ends/167190/1\"0;m,\"39;Ahmed7\"0;m,\"39;If your subscription to AnkiHub runs out and you do not wish to renew. \\\\nAll your decks will stay, nothing will be removed. However, you will no longer be able to sync with AnkiHub and receive new changes to your decks, nor will you be able to suggest new changes or notes to any pre-existing decks yo\\\\u0026hellip;\"0;m,\"39;2024-02-10T06:14:53.787Z\"0;m,\"39;❓ FAQs\"0;m,0,307,0,1],[39;1;m\"What if I can't afford AnkiHub?\"0;m,\"39;/t/what-if-i-cant-afford-ankihub/167280/1\"0;m,\"39;Ahmed7\"0;m,\"39;AnkiHub has a scholarship program to get access at a decreased price. Apply \\\\u003ca href=\\\\\\\"https://www.ankihub.net/scholarships\\\\\\\"\\\\u003ehere \\\\u003c/a\\\\u003e. (You must \\\\u003ca href=\\\\\\\"https://app.ankihub.net/accounts/signup/\\\\\\\"\\\\u003esign up \\\\u003c/a\\\\u003efor an AnkiHub account before applying).\"0;m,\"39;2024-02-10T13:58:24.842Z\"0;m,\"39;❓ FAQs \\\\u003e AnKing Decks\"0;m,0,445,0,1,\\\"anking-wiki\\\"],[39;1;m\"Does AnkiHub offer discounts?\"0;m,\"39;/t/does-ankihub-offer-discounts/228564/1\"0;m,\"39;andrew\"0;m,\"39;The are currently two ways to get a discount on AnkiHub: \\\\n\\\\nPurchase our \\\\u003ca href=\\\\\\\"https://app.ankihub.net/memberships/plans/\\\\\\\"\\\\u003eannual billing option\\\\u003c/a\\\\u003e for one free month per year\\\\n\\\\nAnkiHub is available at $4.58/user/month with an annual billing discount. We can’t afford to discount AnkiHub any further, unfortunately.\\\\n\\\\n\\\\nParticipate in an Ambassador program\\\\n\\\\n\\\\u0026hellip;\"0;m,\"39;2024-05-23T21:34:32.829Z\"0;m,\"39;❓ FAQs\"0;m,0,90,0,1]],\"args\":{\"search_query\":\"purchase accounts for other users subscribe private decks\"}}}\",\"name\":\"search\"}],\"stream\":true,\"stream_options\":{\"include_usage\":true},\"tools\":[{\"type\":\"function\",\"function\":{\"name\":\"search\",\"description\":\"Will search topics in the current discourse instance, when rendering always prefer to link to the topics you find\",\"parameters\":{\"type\":\"object\",\"properties\":{\"search_query\":{\"description\":\"Specific keywords to search for, space separated (correct bad spelling, remove connector words)\",\"type\":\"string\"},\"user\":{\"description\":\"Filter search results to this username (only include if user explicitly asks to filter by user)\",\"type\":\"string\"},\"order\":{\"description\":\"search result order\",\"type\":\"string\",\"enum\":[\"latest\",\"latest_topic\",\"oldest\",\"views\",\"likes\"]},\"limit\":{\"description\":\"limit number of results returned (generally prefer to just keep to default)\",\"type\":\"integer\"},\"max_posts\":{\"description\":\"maximum number of posts on the topics (topics where lots of people posted)\",\"type\":\"integer\"},\"tags\":{\"description\":\"list of tags to search for. Use + to join with OR, use , to join with AND\",\"type\":\"string\"},\"category\":{\"description\":\"category name to filter to\",\"type\":\"string\"},\"before\":{\"description\":\"only topics created before a specific date YYYY-MM-DD\",\"type\":\"string\"},\"after\":{\"description\":\"only topics created after a specific date YYYY-MM-DD\",\"type\":\"string\"},\"status\":{\"description\":\"search for topics in a particular state\",\"type\":\"string\",\"enum\":[\"open\",\"closed\",\"archived\",\"noreplies\",\"single_user\"]}},\"required\":[]}}},{\"type\":\"function\",\"function\":{\"name\":\"read\",\"description\":\"Will read a topic or a post on this Discourse instance\",\"parameters\":{\"type\":\"object\",\"properties\":{\"topic_id\":{\"description\":\"the id of the topic to read\",\"type\":\"integer\"},\"post_numbers\":{\"description\":\"the post numbers to read (optional)\",\"type\":\"array\",\"items\":{\"type\":\"integer\"}}},\"required\":[\"topic_id\"]}}}]}\n```

您可以看到搜索工具已被调用,但其中不包含 base_query

您还可以看到 content 只包含默认系统提示,没有任何搜索结果。

  • 未显示正确的搜索结果数量
    • 它显示 0,但有很多结果,或者显示 5,但实际上是 0。
    • 似乎与正常搜索结果或语义相似性结果都不相关。
  • Bot 会添加无效的查询参数
    • 例如,它在查询末尾添加了 category:non-existent-category

:pleading_face: 请求

  • 如果有一个选项可以为 discourse-ai 启用详细日志记录,那将非常有帮助,这样我们这些不懂 Ruby 的人(我正在学习!:nerd_face:)就可以通过访问 /logs 来快速了解幕后发生的事情。
  • 使用搜索工具时,将前几条结果添加到 RAG 的上下文中。
  • 关于如何确保 base_query 被使用的建议。

我是否正确地理解,根据这个链接,函数调用应该将工具调用的结果推送到提示中?

那么,也许它正在更新提示,但这从调试工具显示的请求中并不清楚?

如果不是这样,我是否不应该期望在那里看到所有的上下文?如果是这样,那很令人困惑,因为在使用进行上传的 RAG 的 Persona 时,整个提示上下文都是可见的。

我仍然对报告的结果数量感到困惑。

话虽如此,在向系统提示中添加以下内容后,我得到了更好的结果!

  • 始终同时调用 search 和 read 函数。
  • 调用 search 函数的次数不超过 3 次。
  • 调用 search 函数时,始终为此 category 参数使用此值:“docs,faqs”

一旦我正确配置了这些,这将是一个巨大的改变。

我不知道您是否知道,但您实际上赋予了我们比 Intercom 试图实现的功能更强大的能力。

我已经在尝试劫持 Intercom 的信使,直接将用户引导至 Discourse AI :nerd_face: :

AnkiHub AI 链接打开了一个与 AI Bot 的私信,链接如下:/new-message?username=ankihubai_bot

是的,调试工具会显示我们发送给 LLM 的所有内容。

我刚刚修复了结果数量的问题:

我们之前没有正确链接到过滤后的查询。

不建议这样做,使用 base_query,我刚刚测试过它工作正常:categories:docs,faqs


我确实不建议现在使用 GPT4,请务必使用 GPT4o 或 Turbo,它们更便宜、更快。

只是再次确认……您是否启用了

ai_bot_debugging_allowed_groups 因此您可以看到调试按钮?

2 个赞

是的。我将通过私信给你进行快速屏幕共享,以显示 read 函数调用结果未在提示中使用。

我还注意到,除非我在系统提示中添加“始终调用 read 函数”,否则 read 函数永远不会被调用。如果我们能更好地控制函数调用就好了。例如,在 OpenAI 的情况下,设置 tool_choice: "required"

我刚再次尝试使用这个 base query,并且使用了正确的搜索参数。这是我第一次看到它奏效。 :person_shrugging:

我知道,我只是在试验不同的模型 :smile: 想知道 GPT4 是否会决定进行不同的函数调用。Haiku 听起来很有希望。

1 个赞

非常感谢

哦,那是正确的,系统提示注入仅在 persona 具有上传功能时才会发生。如果没有上传,我们就不会注入任何内容。

在没有上传的情况下,我们不使用无条件的系统提示注入,而是依赖于带有工具调用结果的工具调用,您可以在滚动时看到它们。

针对主题的无工具模式当然很有趣,它会消耗大量的 token,但挑战在于从主题中钓出正确的内容。

例如,如果一个主题有 5000 个 token,我们会选择哪些 token?我们如何选择正确的 token?

目前,我们每个主题只嵌入 N 个 token,具体取决于您使用的嵌入模型。

因此,我们需要开始为每个主题嵌入更多块,或者提出一种算法来确定主题中最有趣的部分。

2 个赞

我感到困惑。如果调用 read 工具的结果不用于 RAG,那么调用 read 工具有什么用呢?我看到 read 工具调用的结果被放入了 原始上下文,但它似乎并没有被 LLM 以任何方式使用。

我期望的用例很简单:根据 base_query 在主题的子集上启用 RAG。

我认为最好不要依赖 Discourse 来处理将我的主题分割成多个块,每个块都有自己的嵌入。相反,我想负责制作我的文档和 FAQ,使它们针对 RAG 进行优化。也就是说,主题的主帖的整体都可以嵌入。我说的是 wiki 主题,其回复可以而且应该被忽略。

ada-002 有一个 最大 token 输入为 8191,这对于任何编写良好的文档或 FAQ 主题来说都绰绰有余。这样的主题应该远低于此限制。voyage ai 的上下文长度要长得多,为 16000。

有没有像这样的简单方法:

  • (系统提示中的 token - 用户消息中的 token) = 可用的总剩余 token
  • 根据 可用的总剩余 token 将尽可能多的主题注入提示
    • 只使用找到的主题中的第一个帖子

我想近期的解决方法可能是这样的:

  • 创建一个使用搜索工具的 Persona
  • 导出使用搜索工具可以找到的所有主题
    • 我不需要分割这些文档,因为
      • 我不关心主题回复
      • 主 wiki 主题已经足够小,可以嵌入整个内容。
  • 将这些文档上传到 Persona 以进行 RAG

这样,Persona 实际上将使用搜索结果进行 RAG。

希望这有道理!如果有什么不清楚的地方,请告诉我。

1 个赞

当你读取内容时,它会被注入到对话流中。

例如:

  • 你能读取 X 吗
  • 工具调用读取 X
  • 工具结果“页面内容”
  • LLM 回复

RAG 是一个非常笼统的术语,但最终读取一个主题会将其添加到上下文中,LLM 最终负责如何使用它,不同的 LLM 可能会更好地或更差地利用它。

例如:[Untitled AI bot PM] - AI Conversation - Discourse Meta

搜索工具已经插入了主题的摘录,让它和 RAG 处理相同的内容没有意义。

我猜你说的是“搜索提供了上下文,但上下文不够”。

所以一个变通的方法是将所有重要主题导出到一个文件中,然后将其用作 RAG。不要使用搜索工具。


目前最简单的方法是:

categories:cat1,cat2,cat3 in:first

这将把搜索工具限制在仅第一帖。

它非常有效,请参阅:

这是有效的,因为搜索工具会将以下内容注入到上下文中:


我还想要一个无条件的“rag”模式,你可以选择注入更多数据(例如:查找排名前 5 的文档并为每个文档注入最多 5000 个 token,尝试查找最相关的部分)

这是一个复杂的更改,我们会实现的,但目前……搜索 + 读取可以让你走得很远。

2 个赞

我只是想说……你们非常接近需要介绍如何使用人工智能的基本规则的那个点了。我的意思是,你们已经有了一个类似的关于 CSS 和其他一些东西的规则。

2 个赞

我明白了。这说得通。从 OpenAI 关于函数调用的文档 中:

函数调用的基本步骤如下:

  1. 使用用户查询和 functions 参数 中定义的函数集调用模型。
  2. 模型可以选择调用一个或多个函数;如果这样做,内容将是一个字符串化的 JSON 对象,符合您的自定义模式(注意:模型可能会虚构参数)。
  3. 在代码中将字符串解析为 JSON,如果存在参数,则使用提供的参数调用您的函数。
  4. 通过将函数响应作为新消息附加到模型,再次调用模型,让模型将结果总结给用户。

至关重要的是,我不知道 #4。我没有意识到调用工具的结果被附加为消息。我以为是否将结果用于后续调用完全取决于客户端!因此,当我没有在提示本身中看到工具调用结果时,我感到很困惑。 :facepalm: 现在这一切都说得通了。谢谢!

:+1: :pray: 听起来这里唯一的缺点是机器人回复将不包括那些漂亮的搜索结果。您是否会强烈建议出于任何原因使用文档上传 搜索工具,即使它会有点冗余?我想知道在对话中获取搜索结果的好处是否值得。

您需要对其进行测试,它可能会奏效,也可能会给您带来惊喜的结果,而且这在很大程度上取决于您使用的 LLM。

1 个赞