Add session-memory module: Spring AI 2.1 Session API (event log, turn-aware windows, compaction with summarizer, SessionAdvisors, JDBC on PostgreSQL 16) with 14 transcripts and the 2.0 ChatMemory deprecation warnings from javac. Spring Boot 4.1.1, Spring AI 2.1.0, Java 25.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b6jDW7zqoKDMTRrCyq
This commit is contained in:
Claude
2026-11-22 18:39:32 +05:30
parent 0006167c24
commit 7612fca082
39 changed files with 1149 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
# session-memory
Companion code for [Chat Memory to Session Memory in Spring AI 2.1](https://ankurm.com/spring-ai-2-0-chat-memory-jdbc-redis-windowed-conversations/), part of the [Spring AI series](../README.md) on ankurm.com.
The Spring AI 2.1 Session API that replaces `ChatMemory` (deprecated for removal in 3.0): an append-only event log, turn-aware windows, compaction with an optional summarizer, `SessionAdvisors` on a `ChatClient`, and the JDBC repository on PostgreSQL. Every claim in the article is a test that writes its own transcript under [`output/`](output).
There is no live model anywhere: `FixedReplyModel` and `ScriptedChatModel` (under `src/test`) record the prompts they are sent, which is what a memory test has to prove -- *which messages reached the model*. The database is a real PostgreSQL 16.
## Versions
| Component | Version |
|---|---|
| Spring Boot | 4.1.1 |
| Spring AI | 2.1.0 (modules `spring-ai-session`, `spring-ai-session-advisor`, `spring-ai-session-jdbc`, starter `spring-ai-starter-model-session-jdbc`) |
| PostgreSQL | 16.15 |
| Java | 25 (LTS) |
## Quickstart
```bash
scripts/services-up.sh # PostgreSQL 16 (apt) on :5440 -- only for outputs 10 and 11
scripts/run-all.sh # runs the tests and regenerates output/01 .. 14
```
Tests that need PostgreSQL are **skipped with a message**, not failed, when nothing listens on 5440. Two consecutive full runs produce byte-identical files.
## What's here
| File | What it shows |
|---|---|
| [`SessionWiring.java`](src/main/java/com/ankurm/sessionmemory/SessionWiring.java) | The one-call replacement for `ChatMemory` + `MessageChatMemoryAdvisor` |
| [`ExpiredSessionCleaner.java`](src/main/java/com/ankurm/sessionmemory/ExpiredSessionCleaner.java) | The scheduler `deleteExpiredSessions` requires |
| [`src/broken/LegacyChatMemory.java`](src/broken/LegacyChatMemory.java) | The 2.0 setup; not part of the build, `scripts/capture-deprecations.sh` compiles it with `-Xlint:deprecation` |
| `src/test/.../*Test.java` | One test class per transcript in `output/` |