You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: memory/repository/spring-ai-model-chat-memory-repository-mongodb/src/test/java/org/springframework/ai/chat/memory/repository/mongo/MongoChatMemoryRepositoryIT.java
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat-memory.adoc
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,8 @@ ChatMemoryRepository repository = new InMemoryChatMemoryRepository();
68
68
69
69
`JdbcChatMemoryRepository` is a built-in implementation that uses JDBC to store messages in a relational database. It supports multiple databases out-of-the-box and is suitable for applications that require persistent storage of chat memory.
70
70
71
+
Messages are retrieved in ascending timestamp order (oldest-to-newest), which is the expected format for LLM conversation history.
72
+
71
73
First, add the following dependency to your project:
`CassandraChatMemoryRepository` has a time-series schema, keeping record of all past chat windows, valuable for governance and auditing. Setting time-to-live to some value, for example three years, is recommended.
183
185
186
+
Messages are retrieved in ascending timestamp order (oldest-to-newest), which is the expected format for LLM conversation history.
187
+
184
188
To use `CassandraChatMemoryRepository` first, add the dependency to your project:
185
189
186
190
[tabs]
@@ -256,6 +260,8 @@ You can disable the schema initialization by setting the property `spring.ai.cha
256
260
257
261
`Neo4jChatMemoryRepository` is a built-in implementation that uses Neo4j to store chat messages as nodes and relationships in a property graph database. It is suitable for applications that want to leverage Neo4j's graph capabilities for chat memory persistence.
258
262
263
+
Messages are retrieved in ascending message index order (oldest-to-newest), which is the expected format for LLM conversation history.
264
+
259
265
First, add the following dependency to your project:
260
266
261
267
[tabs]
@@ -328,6 +334,8 @@ The Neo4j repository will automatically ensure that indexes are created for conv
328
334
329
335
`CosmosDBChatMemoryRepository` is a built-in implementation that uses Azure Cosmos DB NoSQL API to store messages. It is suitable for applications that require a globally distributed, highly scalable document database for chat memory persistence. The repository uses the conversation ID as the partition key to ensure efficient data distribution and fast retrieval.
330
336
337
+
Messages are retrieved in ascending timestamp order (oldest-to-newest), which is the expected format for LLM conversation history.
338
+
331
339
First, add the following dependency to your project:
332
340
333
341
[tabs]
@@ -412,6 +420,8 @@ You can customize the database and container names using the configuration prope
412
420
413
421
`MongoChatMemoryRepository` is a built-in implementation that uses MongoDB to store messages. It is suitable for applications that require a flexible, document-oriented database for chat memory persistence.
414
422
423
+
Messages are retrieved in ascending timestamp order (oldest-to-newest), which is the expected format for LLM conversation history. This ordering is consistent across all chat memory repository implementations.
424
+
415
425
First, add the following dependency to your project:
416
426
417
427
[tabs]
@@ -484,6 +494,8 @@ It is suitable for applications that require high-performance, low-latency chat
484
494
The repository stores messages as JSON documents and creates a search index for efficient querying.
485
495
It also provides extended query capabilities through the `AdvancedRedisChatMemoryRepository` interface for searching messages by content, type, time range, and metadata.
486
496
497
+
Messages are retrieved in ascending timestamp order (oldest-to-newest), which is the expected format for LLM conversation history.
498
+
487
499
First, add the following dependency to your project:
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/upgrade-notes.adoc
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,33 @@
4
4
[[upgrading-to-2-0-0-M2]]
5
5
== Upgrading to 2.0.0-M2
6
6
7
+
=== Breaking Changes
8
+
9
+
==== MongoDB Chat Memory Message Ordering Fixed
10
+
11
+
The `MongoChatMemoryRepository` has been fixed to return messages in the order they were sent (oldest-to-newest), matching all other chat memory repository implementations. Previously, it incorrectly returned messages in reverse order (newest-to-oldest), which broke conversation flow for LLMs.
12
+
13
+
===== Impact
14
+
15
+
If your application was using `MongoChatMemoryRepository` and working around the incorrect ordering (e.g., by reversing messages after retrieval), you will need to remove that workaround.
16
+
17
+
===== Migration
18
+
19
+
Remove any code that reverses the message order after retrieving from MongoDB chat memory:
// Messages are now correctly ordered chronologically
30
+
----
31
+
32
+
All chat memory repositories now consistently return messages in the order they were sent (oldest-to-newest), which is the expected format for LLM conversation history.
33
+
7
34
=== Development-time Services
8
35
9
36
* Docker Compose and Testcontainers support for MongoDB Atlas is now provided natively by the Spring Boot MongoDB module. The migration should be transparent and not require any code change. Regarding dependencies, you don't need to import `org.springframework.ai:spring-ai-spring-boot-testcontainers` anymore. A dependency on `org.springframework.boot:spring-boot-testcontainers` is sufficient.
0 commit comments