当前位置: 首页 > ds >正文

Dify LLM节点的记忆功能深度探究

Dify LLM节点的记忆功能深度探究

  • 0. 引言
  • 1. 不开启记忆功能
  • 2. 开启记忆功能,不开启记忆窗口
  • 3. 开启记忆功能,记忆窗口设置为1
  • 4. 开启记忆功能,记忆窗口设置为2
  • 5. 开启记忆功能,记忆窗口设置为3
  • 7. 开启记忆功能,记忆窗口设置为4
  • 8. 总结

0. 引言

Dify 的LLM节点中,我们可以开启和关闭记忆功能,下面这段是官方文档的说明,

高级功能
记忆: 开启记忆后问题分类器的每次输入将包含对话中的聊天历史,以帮助 LLM 理解上文,提高对话交互中的问题理解能力。记忆窗口: 记忆窗口关闭时,系统会根据模型上下文窗口动态过滤聊天历史的传递数量;打开时用户可以精确控制聊天历史的传递数量(对数)。

来源:Dify LLM节点说明

实际功能到底怎么样,今天我们一起深度探究探究。

1. 不开启记忆功能

在这里插入图片描述
我们连续问5个问题,

  1. 1+1等于几?
  2. 1+2等于几?
  3. 1+3等于几?
  4. 1+4等于几?
  5. 1+5等于几?

接下来,我们查看工作流中的LLM的数据处理,5个问题每次的LLM数据处理都只有当前的对话内容,也就是没有任何记忆。

  1. 1+1等于几?

在这里插入图片描述
2. 1+2等于几?

(略)

  1. 1+3等于几?

(略)

  1. 1+4等于几?

(略)

  1. 1+5等于几?

在这里插入图片描述
总结:

不开启记忆功能时,每次和LLM对话不回包括任何聊天历史。

2. 开启记忆功能,不开启记忆窗口

为了方便测试,我们将最大标记设置为100。

在这里插入图片描述
我们连续问20几个问题,

  1. 1+1等于几?
  2. 1+2等于几?
  3. 1+3等于几?
  4. 1+4等于几?
  5. 1+5等于几?

下面是 “1+21等于几?” 的LLM的数据处理的内容,发现LLM的数据处理中都包括聊天历史,所以最大标记设置为100,并不是"模型上下文窗口"的设置。

{"model_mode": "chat","prompts": [{"role": "user","text": "1+1等于几?","files": []},{"role": "assistant","text": "1 + 1 等于 2。\n\n这是一个基本的数学事实。","files": []},{"role": "user","text": "1+2等于几?","files": []},{"role": "assistant","text": "1 + 2 等于 3。\n\n这是一个简单的加法运算。","files": []},{"role": "user","text": "1+3等于几?","files": []},{"role": "assistant","text": "1 + 3 等于 4。\n\n这是一个简单的加法运算。","files": []},{"role": "user","text": "1+4等于几?","files": []},{"role": "assistant","text": "1 + 4 等于 5。","files": []},{"role": "user","text": "1+5等于几?","files": []},{"role": "assistant","text": "1 + 5 等于 6。","files": []},{"role": "user","text": "1+6等于几?","files": []},{"role": "assistant","text": "1 + 6 等于 7。","files": []},{"role": "user","text": "1+7等于几?\n\n","files": []},{"role": "assistant","text": "1 + 7 等于 8。","files": []},{"role": "user","text": "1+8等于几?\n\n","files": []},{"role": "assistant","text": "1 + 8 等于 9。","files": []},{"role": "user","text": "1+9等于几?\n\n","files": []},{"role": "assistant","text": "1 + 9 等于 10。","files": []},{"role": "user","text": "1+10等于几?\n\n","files": []},{"role": "assistant","text": "1 + 10 等于 11。","files": []},{"role": "user","text": "1+11等于几?\n\n","files": []},{"role": "assistant","text": "1 + 11 等于 12。","files": []},{"role": "user","text": "1+12等于几?\n\n","files": []},{"role": "assistant","text": "1 + 12 等于 13。","files": []},{"role": "user","text": "1+13等于几?\n\n","files": []},{"role": "assistant","text": "1 + 13 等于 14。","files": []},{"role": "user","text": "1+14等于几?\n\n","files": []},{"role": "assistant","text": "1 + 14 等于 15。","files": []},{"role": "user","text": "1+15等于几?\n\n","files": []},{"role": "assistant","text": "1 + 15 等于 16。","files": []},{"role": "user","text": "1+16等于几?\n\n","files": []},{"role": "assistant","text": "1 + 16 等于 17。","files": []},{"role": "user","text": "1+17等于几?\n\n","files": []},{"role": "assistant","text": "1 + 17 等于 18。","files": []},{"role": "user","text": "1+18等于几?\n\n","files": []},{"role": "assistant","text": "1 + 18 等于 19。","files": []},{"role": "user","text": "1+19等于几?\n\n","files": []},{"role": "assistant","text": "1 + 19 等于 20。","files": []},{"role": "user","text": "1+20等于几?\n\n","files": []},{"role": "assistant","text": "1 + 20 等于 21。","files": []},{"role": "user","text": "1+21等于几?\n\n","files": []}],"model_provider": "langgenius/openai_api_compatible/openai_api_compatible","model_name": "gpt-4o"
}

接下来,我们将模型设置的"模型上下文长度"设置为100,测试一下。

在这里插入图片描述

我们连续问20几个问题,

  1. 1+1等于几?
  2. 1+2等于几?
  3. 1+3等于几?
  4. 1+4等于几?
  5. 1+5等于几?

下面是 “1+21等于几?” 的LLM的数据处理的内容,发现LLM的数据处理中都包括聊天历史,所以模型上下文长度设置为100,并不是"模型上下文窗口"的设置。

{"model_mode": "chat","prompts": [{"role": "user","text": "1+1等于几?","files": []},{"role": "assistant","text": "1 + 1 等于 2。\n\n这种简单的数学问题是基础运算的一部分,通常在早期的数学教育中就已经学到。如果你有其他更复杂的问题或需要进一步的解释,请告诉我!","files": []},{"role": "user","text": "1+2等于几?","files": []},{"role": "assistant","text": "1 + 2 等于 3。\n\n这是基本的加法运算,如果你有其他问题或需要进一步的帮助,请告诉我!","files": []},{"role": "user","text": "1+3等于几?","files": []},{"role": "assistant","text": "1 + 3 等于 4。\n\n希望这能帮到你!如果你有其他问题或需要进一步的帮助,请告诉我。","files": []},{"role": "user","text": "1+4等于几?","files": []},{"role": "assistant","text": "1 + 4 等于 5。\n\n如果你还有其他问题,欢迎继续提问!","files": []},{"role": "user","text": "1+5等于几?","files": []},{"role": "assistant","text": "1 + 5 等于 6。\n\n如果你还有其他问题,随时问我!","files": []},{"role": "user","text": "1+6等于几?","files": []},{"role": "assistant","text": "1 + 6 等于 7。\n\n如果你还有其他问题,随时告诉我!","files": []},{"role": "user","text": "1+7等于几?","files": []},{"role": "assistant","text": "1 + 7 等于 8。\n\n如果还有其他问题,欢迎继续提问!","files": []},{"role": "user","text": "1+8等于几?","files": []},{"role": "assistant","text": "1 + 8 等于 9。\n\n如果你还有其他问题,随时问我!","files": []},{"role": "user","text": "1+9等于几?","files": []},{"role": "assistant","text": "1 + 9 等于 10。\n\n如果你有其他问题,欢迎继续提问!","files": []},{"role": "user","text": "1+10等于几?","files": []},{"role": "assistant","text": "1 + 10 等于 11。\n\n如果你还有其他问题,随时告诉我!","files": []},{"role": "user","text": "1+11等于几?","files": []},{"role": "assistant","text": "1 + 11 等于 12。\n\n如果你还有其他问题,随时问我!","files": []},{"role": "user","text": "1+12等于几?","files": []},{"role": "assistant","text": "1 + 12 等于 13。\n\n如果你还有其他问题,随时告诉我!","files": []},{"role": "user","text": "1+13等于几?","files": []},{"role": "assistant","text": "1 + 13 等于 14。\n\n如果你还有其他问题,随时问我!","files": []},{"role": "user","text": "1+14等于几?","files": []},{"role": "assistant","text": "1 + 14 等于 15。\n\n如果你还有其他问题,随时告诉我!","files": []},{"role": "user","text": "1+15等于几?","files": []},{"role": "assistant","text": "1 + 15 等于 16。\n\n如果你还有其他问题,随时问我!","files": []},{"role": "user","text": "1+16等于几?","files": []},{"role": "assistant","text": "1 + 16 等于 17。","files": []},{"role": "user","text": "1+17等于几?","files": []},{"role": "assistant","text": "1 + 17 等于 18。","files": []},{"role": "user","text": "1+18等于几?","files": []},{"role": "assistant","text": "1 + 18 等于 19。","files": []},{"role": "user","text": "1+19等于几?","files": []},{"role": "assistant","text": "1 + 19 等于 20。\n\n如果你还有其他问题,随时问我!","files": []},{"role": "user","text": "1+20等于几?","files": []},{"role": "assistant","text": "1 + 20 等于 21。\n\n如果你还有其他问题,随时问我!","files": []},{"role": "user","text": "1+21等于几?","files": []}],"model_provider": "langgenius/openai_api_compatible/openai_api_compatible","model_name": "gpt-4o"
}

总结:

“记忆窗口关闭时,系统会根据模型上下文窗口动态过滤聊天历史的传递数量;”,这个"模型上下文窗口"具体指的是什么,需要查看代码(ToDo事项)。

3. 开启记忆功能,记忆窗口设置为1

在这里插入图片描述
我们连续问5个问题,

  1. 1+1等于几?
  2. 1+2等于几?
  3. 1+3等于几?
  4. 1+4等于几?
  5. 1+5等于几?

接下来,我们查看工作流中的LLM的数据处理,5个问题每次的LLM数据处理都只有当前的对话内容,也就是没有任何记忆。

  1. 1+1等于几?

在这里插入图片描述

  1. 1+2等于几?

(略)

  1. 1+3等于几?

(略)

  1. 1+4等于几?

(略)

  1. 1+5等于几?

在这里插入图片描述

4. 开启记忆功能,记忆窗口设置为2

在这里插入图片描述

我们连续问5个问题,

  1. 1+1等于几?
  2. 1+2等于几?
  3. 1+3等于几?
  4. 1+4等于几?
  5. 1+5等于几?

接下来,我们查看工作流中的LLM的数据处理,从第2个问题开始,每个问题里面包括上一个问题的user/assistant的对话。

  1. 1+1等于几?
{"model_mode": "chat","prompts": [{"role": "user","text": "1+1等于几?","files": []}],"model_provider": "langgenius/openai_api_compatible/openai_api_compatible","model_name": "gpt-4o"
}
  1. 1+2等于几?
{"model_mode": "chat","prompts": [{"role": "user","text": "1+1等于几?","files": []},{"role": "assistant","text": "1 + 1 等于 2。这是一个基本的算术运算。如果你有其他问题或需要进一步的解释,请告诉我!","files": []},{"role": "user","text": "1+2等于几?","files": []}],"model_provider": "langgenius/openai_api_compatible/openai_api_compatible","model_name": "gpt-4o"
}
  1. 1+3等于几?
{"model_mode": "chat","prompts": [{"role": "user","text": "1+2等于几?","files": []},{"role": "assistant","text": "1 + 2 等于 3。\n\n如果你有其他问题或需要进一步的帮助,请告诉我!","files": []},{"role": "user","text": "1+3等于几?","files": []}],"model_provider": "langgenius/openai_api_compatible/openai_api_compatible","model_name": "gpt-4o"
}
  1. 1+4等于几?
{"model_mode": "chat","prompts": [{"role": "user","text": "1+3等于几?","files": []},{"role": "assistant","text": "1 + 3 等于 4。\n\n如果你有其他问题或需要进一步的帮助,请告诉我!","files": []},{"role": "user","text": "1+4等于几?","files": []}],"model_provider": "langgenius/openai_api_compatible/openai_api_compatible","model_name": "gpt-4o"
}
  1. 1+5等于几?
{"model_mode": "chat","prompts": [{"role": "user","text": "1+4等于几?","files": []},{"role": "assistant","text": "1 + 4 等于 5。\n\n如果你有其他问题或需要进一步的帮助,请告诉我!","files": []},{"role": "user","text": "1+5等于几?","files": []}],"model_provider": "langgenius/openai_api_compatible/openai_api_compatible","model_name": "gpt-4o"
}

5. 开启记忆功能,记忆窗口设置为3

在这里插入图片描述

我们连续问5个问题,

  1. 1+1等于几?
  2. 1+2等于几?
  3. 1+3等于几?
  4. 1+4等于几?
  5. 1+5等于几?

接下来,我们查看工作流中的LLM的数据处理,我们直接查看第5个问题,这个问题里面包括上2个问题的user/assistant的对话。

  1. 1+5等于几?
{"model_mode": "chat","prompts": [{"role": "user","text": "1+3等于几?","files": []},{"role": "assistant","text": "1 + 3 等于 4。\n\n这是一个基本的加法运算,可以通过数数或其他方法来验证。","files": []},{"role": "user","text": "1+4等于几?","files": []},{"role": "assistant","text": "1 + 4 等于 5。\n\n这是一个简单的加法运算。如果你有任何其他问题或需要进一步的帮助,请告诉我!","files": []},{"role": "user","text": "1+5等于几?","files": []}],"model_provider": "langgenius/openai_api_compatible/openai_api_compatible","model_name": "gpt-4o"
}

7. 开启记忆功能,记忆窗口设置为4

在这里插入图片描述
我们连续问5个问题,

  1. 1+1等于几?
  2. 1+2等于几?
  3. 1+3等于几?
  4. 1+4等于几?
  5. 1+5等于几?

接下来,我们查看工作流中的LLM的数据处理,我们直接查看第5个问题,这个问题里面包括上3个问题的user/assistant的对话。

  1. 1+5等于几?
{"model_mode": "chat","prompts": [{"role": "user","text": "1+2等于几?","files": []},{"role": "assistant","text": "1 + 2 等于 3。\n\n如果你有其他问题或需要进一步的帮助,请告诉我!","files": []},{"role": "user","text": "1+3等于几?","files": []},{"role": "assistant","text": "1 + 3 等于 4。\n\n如果你有其他数学问题或需要进一步的帮助,请随时告诉我!","files": []},{"role": "user","text": "1+4等于几?","files": []},{"role": "assistant","text": "1 + 4 等于 5。\n\n如果你有其他问题或需要进一步的帮助,请告诉我!","files": []},{"role": "user","text": "1+5等于几?","files": []}],"model_provider": "langgenius/openai_api_compatible/openai_api_compatible","model_name": "gpt-4o"
}

8. 总结

本文探讨了Dify LLM节点的记忆功能,通过实验验证了其不同配置下的表现。以下是主要内容的总结:

  1. 记忆功能概述

    • Dify的LLM节点提供了记忆功能,可以开启或关闭。开启记忆功能后,系统会在每次输入中包含对话历史,以帮助模型理解上下文。
    • 记忆窗口设置允许用户控制聊天历史的传递数量。
  2. 不开启记忆功能

    • 每次对话只包含当前问题,没有任何记忆功能。
  3. 开启记忆功能,不开启记忆窗口

    • 系统根据模型上下文窗口动态过滤聊天历史的传递数量。然而,具体的“模型上下文窗口”设置需要进一步查看代码才能确定。
  4. 记忆窗口设置为1

    • 每次对话只包含当前问题,没有记忆。
  5. 记忆窗口设置为2

    • 每次对话包含当前问题和上一个问题的对话。
  6. 记忆窗口设置为3

    • 每次对话包含当前问题和上两个问题的对话。
  7. 记忆窗口设置为4

    • 每次对话包含当前问题和上三个问题的对话。

完结!

http://www.xdnf.cn/news/3462.html

相关文章:

  • 滚珠丝杆怎么选型?
  • 《解锁LibTorch:开启C++深度学习新征程》
  • Windows 系统中安装 flash - attn
  • 智慧校园综合整体解决方案-8PPT(58页)
  • AI 知识库:企业知识管理的利器
  • 【C++】频繁进行动态内存分配和释放可能导致多方面的问题
  • 深入探讨互联网大厂Java核心技术与架构设计
  • windbg调试dump文件
  • 信号与系统-风中醉风
  • 2025 RSAC|自主式 GenAI 安全智能体(Agent)开启防御新纪元
  • Splunk 使用Role 实现数据隔离
  • firecrawl的docker安装和api调用
  • Linux安装MySQL详细教程
  • 视觉标记token:解锁AI视觉理解新维度的钥匙
  • 强化学习之基于无模型的算法之基于值函数的深度强化学习算法
  • DeepSeek-V3 解析第二篇:DeepSeekMoE
  • 数据库的死锁相关(一)
  • 动态规划 -- 子数组问题
  • nginx 配置要领
  • 客户服务升级:智能语音外呼系统在多领域的场景应用解析
  • 大模型时代的新燃料:大规模拟真多风格语音合成数据集
  • 面经很简单的
  • 机器学习_KNN算法
  • 【SpringBoot】基于mybatisPlus的博客管理系统(2)
  • 汽车电子 专栏文章汇总
  • python+echart绘制一个听力图
  • 常用电机类型及其特点对比
  • 如何用fiddler进行弱网测试(工作常用篇)
  • sd webui 安装插件sd-webui-EasyPhoto依赖安装失败解决办法
  • 基于深度强化学习训练一个会走迷宫的ai