spring-projects / spring-projects/spring-ai
Limited Extensibility in ChatMemoryRepository Design
Nobody has claimed this yet.
- 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:
- Save Mechanism: The
saveAllmethod requires full overwrite of existing messages, preventing incremental storage of conversation history. - Query Capability:
findByConversationIdforces 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:
- Add support for incremental writes (e.g.,
addMessagemethod) - Allow paginated/parameterized message retrieval (e.g., limit/offset parameters)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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