[improvement][chat]Do not create duplication memory for exactly the same question.

This commit is contained in:
jerryjzhang
2024-10-09 18:12:44 +08:00
parent dd40e6c14f
commit 5fcec320ba

View File

@@ -36,7 +36,13 @@ public class MemoryServiceImpl implements MemoryService {
@Override
public void createMemory(ChatMemoryDO memory) {
chatMemoryRepository.createMemory(memory);
// do not save duplicate memory for exactly the same question
List<ChatMemoryDO> memories = getMemories(ChatMemoryFilter.builder()
.agentId(memory.getAgentId())
.question(memory.getQuestion()).build());
if (memories.size() == 0) {
chatMemoryRepository.createMemory(memory);
}
}
@Override