(improvement)(chat)Enable memory directly if the review result by LLM is positive.

This commit is contained in:
jerryjzhang
2024-07-12 09:56:51 +08:00
parent 41ad1ada6c
commit 37da1ac2ae
6 changed files with 25 additions and 17 deletions

View File

@@ -66,6 +66,10 @@ public class MemoryReviewTask {
if (matcher.find()) {
m.setLlmReviewRet(MemoryReviewResult.valueOf(matcher.group(1)));
m.setLlmReviewCmt(matcher.group(2));
// directly enable memory if the LLM determines it positive
if (MemoryReviewResult.POSITIVE.equals(m.getLlmReviewRet())) {
memoryService.enableMemory(m);
}
memoryService.updateMemory(m);
}
} else {

View File

@@ -16,6 +16,10 @@ public interface MemoryService {
void updateMemory(ChatMemoryDO memory);
void enableMemory(ChatMemoryDO memory);
void disableMemory(ChatMemoryDO memory);
PageInfo<ChatMemoryDO> pageMemories(PageMemoryReq pageMemoryReq);
List<ChatMemoryDO> getMemories(ChatMemoryFilter chatMemoryFilter);

View File

@@ -96,7 +96,9 @@ public class MemoryServiceImpl implements MemoryService {
return chatMemoryRepository.getMemories(queryWrapper);
}
private void enableMemory(ChatMemoryDO memory) {
@Override
public void enableMemory(ChatMemoryDO memory) {
memory.setStatus(MemoryStatus.ENABLED);
exemplarService.storeExemplar(embeddingConfig.getMemoryCollectionName(memory.getAgentId()),
SqlExemplar.builder()
.question(memory.getQuestion())
@@ -105,7 +107,9 @@ public class MemoryServiceImpl implements MemoryService {
.build());
}
private void disableMemory(ChatMemoryDO memory) {
@Override
public void disableMemory(ChatMemoryDO memory) {
memory.setStatus(MemoryStatus.DISABLED);
exemplarService.removeExemplar(embeddingConfig.getMemoryCollectionName(memory.getAgentId()),
SqlExemplar.builder()
.question(memory.getQuestion())