Baeldung
Read post

A Guide to Short-Term Memory Sessions in Spring AI

Spring AI Session is an event-sourced short-term memory layer designed to replace the older ChatMemory API. It stores conversation history as turn-aware events (user message + all assistant replies and tool calls), ensuring compaction never splits a turn. The tutorial covers setting up the dependency with Spring AI 2.x and Spring Boot 4.x, creating and managing sessions via SessionService, wiring memory transparently into ChatClient using SessionMemoryAdvisor, and choosing among four compaction strategies: SlidingWindowCompactionStrategy, TurnWindowCompactionStrategy, TokenCountCompactionStrategy, and RecursiveSummarizationCompactionStrategy. The first three drop older events cheaply, while recursive summarization uses an LLM call to preserve condensed context. Manual compaction via compact() is also demonstrated. The API is currently incubating in the spring-ai-community project and is slated to become the default replacement for ChatMemory.

    #llm#java#spring-boot#spring-ai
Jul 30•7m read time•From feeds.feedblitz.com
Post cover image
Table of contents
1. Overview2. What Are Memory Sessions?3. Setting Up the Project4. Creating and Managing Sessions5. Using the SessionMemoryAdvisor6. Compaction Strategies7. Conclusion
1.9K Impressions
Baeldung's image
Baeldung

Baeldung offers insights into Java development, Spring framework, and software architecture, providi...

3.1K Followers

•

7.7K Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard