|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring AI 2.1.0! |
Migrating to Session Memory
Session memory replaces the ChatMemory API.
A session keeps the conversation as an append-only log of events, and the prompt is built from a view of it, so a window or a compaction never loses what was said and never splits a turn.
| Chat memory | Session memory |
|---|---|
|
|
|
|
|
A window on the memory advisor, |
|
|
|
|
|
|
The Cassandra, Neo4j, MongoDB and Redis repositories; the HSQLDB, Oracle and SQLite dialects |
No session counterpart yet; they are planned before 3.0.0, when these modules are removed.
Until then, a store implements |
The context key stays the same, so a request that sets ChatMemory.CONVERSATION_ID reaches the session advisors unchanged:
// Before
ChatClient chatClient = ChatClient.builder(chatModel)
.defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build())
.build();
// After
ChatClient chatClient = ChatClient.builder(chatModel)
.defaultAdvisors(SessionAdvisors.builder(sessionService).build())
.build();
chatClient.prompt()
.user("Hello")
.advisors(SessionAdvisors.session(conversationId))
.call()
.content();
With spring-ai-starter-model-session-jdbc on the classpath, the SessionService is auto-configured on the application’s DataSource.
The two stores do not share their tables: conversations kept in SPRING_AI_CHAT_MEMORY are not read by the session memory.