spring-projects / spring-projects/spring-ai

Limited Extensibility in ChatMemoryRepository Design

Open
#3,288 5 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Issue Title: Limited Extensibility in ChatMemoryRepository Design

Description:
In the latest Spring AI 1.0.0 release, the ChatMemory interface and its default MessageWindowChatMemory implementation (using fixed-window conversation history) provide good extensibility for custom implementations. However, there appears to be tight coupling between the storage mechanism and windowed memory implementation through the ChatMemoryRepository interface.

The current ChatMemoryRepository interface:

public interface ChatMemoryRepository {
    List<String> findConversationIds();
    List<Message> findByConversationId(String conversationId);
    void saveAll(String conversationId, List<Message> messages); // Overwrites existing messages
    void deleteByConversationId(String conversationId);
}

Presents two key limitations:

  1. Save Mechanism: The saveAll method requires full overwrite of existing messages, preventing incremental storage of conversation history.
  2. Query Capability: findByConversationId forces retrieval of all messages, making it impossible to implement partial retrieval patterns (e.g., top-N messages).

This design essentially binds ChatMemoryRepository implementations to work exclusively with the windowed memory approach used by MessageWindowChatMemory. Developers cannot implement alternative strategies like:

  • Storing complete conversation history while only loading recent messages
  • Implementing custom message retrieval logic (e.g., time-based or relevance-based sampling)

The current architecture forces complete reimplementation of both ChatMemory and storage mechanisms for non-windowed use cases, negating the interface's intended extensibility benefits. Could we reconsider this design to better separate storage concerns from memory management strategies?

Suggested Improvements:

  1. Add support for incremental writes (e.g., addMessage method)
  2. Allow paginated/parameterized message retrieval (e.g., limit/offset parameters)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the ChatMemoryRepository interface and its relationship to MessageWindowChatMemory and the ChatMemory interface. Review how saveAll and findByConversationId constrain storage and retrieval strategies. Done means the design supports incremental writes and parameterized or partial retrieval without forcing custom memory implementations to reimplement storage concerns.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
ai, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.