Files
spring-ai/session-memory/README.md
T

35 lines
2.0 KiB
Markdown

# 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/` |