feat(memory): 实现记忆切片持久化并优化记忆存储结构- 新增 ChatClient 类实现与大模型的交互

- 添加了chat包,用于后续大模型对接
- 更新 MemoryGraph 类,增加用户对话缓存和当前对话压缩上下文
- 修改 MemoryNode 类,实现记忆切片的序列化和反序列化
- 更新 MemorySlice 类,增加多用户相关字段和方法,将切片内容从SliceData移动至MemorySlice
- 删除未使用的 SliceData 类
- 添加日志依赖和异常处理,新的异常类NullSliceListException
This commit is contained in:
2025-04-11 21:50:11 +08:00
parent 24d4510270
commit c28979b495
14 changed files with 413 additions and 45 deletions

View File

@@ -8,6 +8,7 @@ import work.slhaf.memory.exception.UnExistedTopicException;
import work.slhaf.memory.node.MemoryNode;
import work.slhaf.memory.node.TopicNode;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
@@ -21,7 +22,7 @@ class SearchTest {
// 初始化测试环境,模拟插入基础数据
@BeforeEach
void setUp() {
void setUp() throws IOException, ClassNotFoundException {
memoryGraph = new MemoryGraph("testGraph");
// 构建基础主题路径:根主题 -> 编程 -> Java
@@ -42,7 +43,7 @@ class SearchTest {
// 场景1查询存在的完整主题路径含相关主题
@Test
void selectMemory_shouldReturnTargetAndRelatedAndParentMemories() {
void selectMemory_shouldReturnTargetAndRelatedAndParentMemories() throws IOException, ClassNotFoundException {
// 准备相关主题数据:根主题 -> 算法 -> 排序
List<String> sortPath = new ArrayList<>();
sortPath.add("算法");
@@ -81,7 +82,7 @@ class SearchTest {
// 场景3无相关主题时仅返回目标节点和父节点记忆
@Test
void selectMemory_withoutRelatedTopics_shouldReturnTargetAndParent() {
void selectMemory_withoutRelatedTopics_shouldReturnTargetAndParent() throws IOException, ClassNotFoundException {
// 插入父级记忆:根主题 -> 编程
List<String> parentPath = new ArrayList<>();
parentPath.add("编程");
@@ -102,7 +103,7 @@ class SearchTest {
// 场景4验证日期排序应优先取最新日期的邻近记忆
@Test
void selectMemory_shouldGetLatestRelatedMemory() {
void selectMemory_shouldGetLatestRelatedMemory() throws IOException, ClassNotFoundException {
// 准备相关主题路径:根主题 -> 数据库
List<String> dbPath = new ArrayList<>();
dbPath.add("数据库");