Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.

Expected Behavior

Memory can be incrementally forgotten and added

Current Behavior

ChatMemoryRepository API:

Memory can only extract and overwrite as a whole.

    List<Message> findByConversationId(String conversationId);

    /**
     * Replaces all the existing messages for the given conversation ID with the provided
     * messages.
     */
    void saveAll(String conversationId, List<Message> messages);

    void deleteByConversationId(String conversationId);

Context

Adding incremental operations?

For example:

void refresh(String conversationId, List<Message> deletes, List<Message> adds)

Comment From: daniel38192

I had the same issue with JdbcChatMemoryRepository, due to lack of appropriated methods provided by ChatMemoryRepository interface, the JdbcChatMemoryRepository deletes all previous messages on my database, then add the same messages including a new message, which is inefficient, there is no point of delete all messages and add the same messages again.

My solution was create my custom MessageWindowChatMemory and ChatMemoryRepository, and just save last messages and fetching the last messages available on the database with a limit, since I want to maintain all generated messages with their timestamp (the unnecessary deletion add the older messages with other timestamp).