[fix][chat]Memory enabled by the review task should be stored in embedding store.

This commit is contained in:
jerryjzhang
2024-12-26 00:11:12 +08:00
parent 214d90772d
commit 265e51c429
6 changed files with 45 additions and 18 deletions

View File

@@ -26,4 +26,8 @@ public class ChatMemoryUpdateReq {
private MemoryReviewResult humanReviewRet;
private String humanReviewCmt;
private MemoryReviewResult llmReviewRet;
private String llmReviewCmt;
}

View File

@@ -3,11 +3,13 @@ package com.tencent.supersonic.chat.server.memory;
import com.tencent.supersonic.chat.api.pojo.enums.MemoryReviewResult;
import com.tencent.supersonic.chat.api.pojo.enums.MemoryStatus;
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryFilter;
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryUpdateReq;
import com.tencent.supersonic.chat.server.agent.Agent;
import com.tencent.supersonic.chat.server.pojo.ChatMemory;
import com.tencent.supersonic.chat.server.service.AgentService;
import com.tencent.supersonic.chat.server.service.MemoryService;
import com.tencent.supersonic.common.pojo.ChatApp;
import com.tencent.supersonic.common.pojo.User;
import com.tencent.supersonic.common.pojo.enums.AppModule;
import com.tencent.supersonic.common.util.ChatAppManager;
import com.tencent.supersonic.headless.server.utils.ModelConfigHelper;
@@ -123,7 +125,13 @@ public class MemoryReviewTask {
if (MemoryReviewResult.POSITIVE.equals(m.getLlmReviewRet())) {
m.setStatus(MemoryStatus.ENABLED);
}
memoryService.updateMemory(m);
ChatMemoryUpdateReq memoryUpdateReq = ChatMemoryUpdateReq.builder()
.id(m.getId())
.status(m.getStatus())
.llmReviewRet(m.getLlmReviewRet())
.llmReviewCmt(m.getLlmReviewCmt())
.build();
memoryService.updateMemory(memoryUpdateReq, User.getDefaultUser());
}
}
}

View File

@@ -14,8 +14,6 @@ public interface MemoryService {
void updateMemory(ChatMemoryUpdateReq chatMemoryUpdateReq, User user);
void updateMemory(ChatMemory memory);
void batchDelete(List<Long> ids);
PageInfo<ChatMemory> pageMemories(PageMemoryReq pageMemoryReq);

View File

@@ -1,6 +1,7 @@
package com.tencent.supersonic.chat.server.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tencent.supersonic.chat.api.pojo.enums.MemoryReviewResult;
@@ -9,6 +10,7 @@ import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryFilter;
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryUpdateReq;
import com.tencent.supersonic.chat.api.pojo.request.PageMemoryReq;
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
import com.tencent.supersonic.chat.server.persistence.mapper.ChatMemoryMapper;
import com.tencent.supersonic.chat.server.persistence.repository.ChatMemoryRepository;
import com.tencent.supersonic.chat.server.pojo.ChatMemory;
import com.tencent.supersonic.chat.server.service.MemoryService;
@@ -16,7 +18,6 @@ import com.tencent.supersonic.common.config.EmbeddingConfig;
import com.tencent.supersonic.common.pojo.Text2SQLExemplar;
import com.tencent.supersonic.common.pojo.User;
import com.tencent.supersonic.common.service.ExemplarService;
import com.tencent.supersonic.common.util.BeanMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -34,6 +35,9 @@ public class MemoryServiceImpl implements MemoryService {
@Autowired
private ChatMemoryRepository chatMemoryRepository;
@Autowired
private ChatMemoryMapper chatMemoryMapper;
@Autowired
private ExemplarService exemplarService;
@@ -57,20 +61,33 @@ public class MemoryServiceImpl implements MemoryService {
ChatMemoryDO chatMemoryDO = chatMemoryRepository.getMemory(chatMemoryUpdateReq.getId());
boolean hadEnabled =
MemoryStatus.ENABLED.toString().equals(chatMemoryDO.getStatus().trim());
chatMemoryDO.setUpdatedBy(user.getName());
chatMemoryDO.setUpdatedAt(new Date());
BeanMapper.mapper(chatMemoryUpdateReq, chatMemoryDO);
if (MemoryStatus.ENABLED.equals(chatMemoryUpdateReq.getStatus()) && !hadEnabled) {
enableMemory(chatMemoryDO);
} else if (MemoryStatus.DISABLED.equals(chatMemoryUpdateReq.getStatus()) && hadEnabled) {
disableMemory(chatMemoryDO);
}
chatMemoryRepository.updateMemory(chatMemoryDO);
}
@Override
public void updateMemory(ChatMemory memory) {
chatMemoryRepository.updateMemory(getMemoryDO(memory));
LambdaUpdateWrapper<ChatMemoryDO> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(ChatMemoryDO::getId, chatMemoryDO.getId());
if (Objects.nonNull(chatMemoryUpdateReq.getStatus())) {
updateWrapper.set(ChatMemoryDO::getStatus, chatMemoryUpdateReq.getStatus());
}
if (Objects.nonNull(chatMemoryUpdateReq.getLlmReviewRet())) {
updateWrapper.set(ChatMemoryDO::getLlmReviewRet, chatMemoryUpdateReq.getLlmReviewRet().toString());
}
if (Objects.nonNull(chatMemoryUpdateReq.getLlmReviewCmt())) {
updateWrapper.set(ChatMemoryDO::getLlmReviewCmt, chatMemoryUpdateReq.getLlmReviewCmt());
}
if (Objects.nonNull(chatMemoryUpdateReq.getHumanReviewRet())) {
updateWrapper.set(ChatMemoryDO::getHumanReviewRet, chatMemoryUpdateReq.getHumanReviewRet().toString());
}
if (Objects.nonNull(chatMemoryUpdateReq.getHumanReviewCmt())) {
updateWrapper.set(ChatMemoryDO::getHumanReviewCmt, chatMemoryUpdateReq.getHumanReviewCmt());
}
updateWrapper.set(ChatMemoryDO::getUpdatedAt, new Date());
updateWrapper.set(ChatMemoryDO::getUpdatedBy, user.getName());
chatMemoryMapper.update(updateWrapper);
}
@Override

View File

@@ -90,10 +90,10 @@ CREATE TABLE IF NOT EXISTS `s2_chat_memory` (
`db_schema` TEXT ,
`s2_sql` TEXT ,
`side_info` TEXT ,
`status` char(10) ,
`llm_review` char(10) ,
`status` varchar(10) ,
`llm_review` varchar(10) ,
`llm_comment` TEXT,
`human_review` char(10) ,
`human_review` varchar(10) ,
`human_comment` TEXT ,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,

View File

@@ -80,10 +80,10 @@ CREATE TABLE IF NOT EXISTS `s2_chat_memory` (
`agent_id` INT COMMENT '助理ID' ,
`db_schema` TEXT COMMENT 'Schema映射' ,
`s2_sql` TEXT COMMENT '大模型解析SQL' ,
`status` char(10) COMMENT '状态' ,
`llm_review` char(10) COMMENT '大模型评估结果' ,
`status` varchar(10) COMMENT '状态' ,
`llm_review` varchar(10) COMMENT '大模型评估结果' ,
`llm_comment` TEXT COMMENT '大模型评估意见' ,
`human_review` char(10) COMMENT '管理员评估结果',
`human_review` varchar(10) COMMENT '管理员评估结果',
`human_comment` TEXT COMMENT '管理员评估意见',
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,