Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@ConfigurationProperties(Neo4jChatMemoryRepositoryProperties.CONFIG_PREFIX)
public class Neo4jChatMemoryRepositoryProperties {

public static final String CONFIG_PREFIX = "spring.ai.chat.memory.neo4j";
public static final String CONFIG_PREFIX = "spring.ai.chat.memory.repository.neo4j";

private String sessionLabel = Neo4jChatMemoryRepositoryConfig.DEFAULT_SESSION_LABEL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void setCustomConfiguration() {
final String toolResponseLabel = "LabelToolResponse";
final String mediaLabel = "LabelMedia";

final String propertyBase = "spring.ai.chat.memory.neo4j.%s=%s";
final String propertyBase = "spring.ai.chat.memory.repository.neo4j.%s=%s";
this.contextRunner
.withPropertyValues("spring.neo4j.uri=" + neo4jContainer.getBoltUrl(),
propertyBase.formatted("sessionlabel", sessionLabel),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Maven::
----
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-chat-memory-jdbc</artifactId>
<artifactId>spring-ai-starter-model-chat-memory-repository-jdbc</artifactId>
</dependency>
----

Expand All @@ -87,7 +87,7 @@ Gradle::
[source,groovy]
----
dependencies {
implementation 'org.springframework.ai:spring-ai-starter-model-chat-memory-jdbc'
implementation 'org.springframework.ai:spring-ai-starter-model-chat-memory-repository-jdbc'
}
----
======
Expand All @@ -105,13 +105,13 @@ ChatMemory chatMemory = MessageWindowChatMemory.builder()
.build();
----

If you'd rather create the `JdbcChatMemoryRepository` manually, you can do so by providing a `JdbcTemplate` instance and optionally a custom `JdbcChatMemoryRepositoryDialect`:
If you'd rather create the `JdbcChatMemoryRepository` manually, you can do so by providing a `JdbcTemplate` instance and a `JdbcChatMemoryRepositoryDialect`:

[source,java]
----
ChatMemoryRepository chatMemoryRepository = JdbcChatMemoryRepository.builder()
.jdbcTemplate(jdbcTemplate)
.dialect(new PostgresChatMemoryDialect()) // Optional: custom dialect, auto-detected by default
.dialect(new PostgresChatMemoryDialect())
.build();

ChatMemory chatMemory = MessageWindowChatMemory.builder()
Expand All @@ -129,7 +129,7 @@ Spring AI supports multiple relational databases via a dialect abstraction. The
- SQL Server
- HSQLDB

The correct dialect is auto-detected from the JDBC URL. You can extend support for other databases by implementing the `JdbcChatMemoryRepositoryDialect` interface.
The correct dialect can be auto-detected from the JDBC URL when using `JdbcChatMemoryRepositoryDialect.from(DataSource)`. You can extend support for other databases by implementing the `JdbcChatMemoryRepositoryDialect` interface.

==== Configuration Properties

Expand All @@ -138,6 +138,7 @@ The correct dialect is auto-detected from the JDBC URL. You can extend support f
|Property | Description | Default Value
| `spring.ai.chat.memory.repository.jdbc.initialize-schema` | Controls when to initialize the schema. Values: `embedded` (default), `always`, `never`. | `embedded`
| `spring.ai.chat.memory.repository.jdbc.schema` | Location of the schema script to use for initialization. Supports `classpath:` URLs and platform placeholders. | `classpath:org/springframework/ai/chat/memory/repository/jdbc/schema-@@platform@@.sql`
| `spring.ai.chat.memory.repository.jdbc.platform` | Platform to use in initialization scripts if the @@platform@@ placeholder is used. | _auto-detected_
|===

==== Schema Initialization
Expand Down Expand Up @@ -189,7 +190,7 @@ Maven::
----
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-chat-memory-cassandra</artifactId>
<artifactId>spring-ai-starter-model-chat-memory-repository-cassandra</artifactId>
</dependency>
----

Expand All @@ -198,7 +199,7 @@ Gradle::
[source,groovy]
----
dependencies {
implementation 'org.springframework.ai:spring-ai-starter-model-chat-memory-cassandra'
implementation 'org.springframework.ai:spring-ai-starter-model-chat-memory-repository-cassandra'
}
----
======
Expand Down Expand Up @@ -239,6 +240,7 @@ ChatMemory chatMemory = MessageWindowChatMemory.builder()
| `spring.cassandra.localDatacenter` | Cassandra datacenter to connect to | `datacenter1`
| `spring.ai.chat.memory.cassandra.time-to-live` | Time to live (TTL) for messages written in Cassandra |
| `spring.ai.chat.memory.cassandra.keyspace` | Cassandra keyspace | `springframework`
| `spring.ai.chat.memory.cassandra.messages-column` | Cassandra column name for messages | `springframework`
| `spring.ai.chat.memory.cassandra.table` | Cassandra table | `ai_chat_memory`
| `spring.ai.chat.memory.cassandra.initialize-schema` | Whether to initialize the schema on startup. | `true`
|===
Expand All @@ -263,7 +265,7 @@ Maven::
----
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-chat-memory-neo4j</artifactId>
<artifactId>spring-ai-starter-model-chat-memory-repository-neo4j</artifactId>
</dependency>
----

Expand All @@ -272,7 +274,7 @@ Gradle::
[source,groovy]
----
dependencies {
implementation 'org.springframework.ai:spring-ai-starter-model-chat-memory-neo4j'
implementation 'org.springframework.ai:spring-ai-starter-model-chat-memory-repository-neo4j'
}
----
======
Expand Down Expand Up @@ -309,12 +311,12 @@ ChatMemory chatMemory = MessageWindowChatMemory.builder()
[cols="2,5,1",stripes=even]
|===
|Property | Description | Default Value
| `spring.ai.chat.memory.neo4j.sessionLabel` | The label for the nodes that store conversation sessions | `Session`
| `spring.ai.chat.memory.neo4j.messageLabel` | The label for the nodes that store messages | `Message`
| `spring.ai.chat.memory.neo4j.toolCallLabel` | The label for nodes that store tool calls (e.g. in Assistant Messages) | `ToolCall`
| `spring.ai.chat.memory.neo4j.metadataLabel` | The label for nodes that store message metadata | `Metadata`
| `spring.ai.chat.memory.neo4j.toolResponseLabel` | The label for the nodes that store tool responses | `ToolResponse`
| `spring.ai.chat.memory.neo4j.mediaLabel` | The label for the nodes that store media associated with a message | `Media`
| `spring.ai.chat.memory.repository.neo4j.sessionLabel` | The label for the nodes that store conversation sessions | `Session`
| `spring.ai.chat.memory.repository.neo4j.messageLabel` | The label for the nodes that store messages | `Message`
| `spring.ai.chat.memory.repository.neo4j.toolCallLabel` | The label for nodes that store tool calls (e.g. in Assistant Messages) | `ToolCall`
| `spring.ai.chat.memory.repository.neo4j.metadataLabel` | The label for nodes that store message metadata | `Metadata`
| `spring.ai.chat.memory.repository.neo4j.toolResponseLabel` | The label for the nodes that store tool responses | `ToolResponse`
| `spring.ai.chat.memory.repository.neo4j.mediaLabel` | The label for the nodes that store media associated with a message | `Media`
|===

==== Index Initialization
Expand Down Expand Up @@ -352,7 +354,7 @@ String conversationId = "007";

chatClient.prompt()
.user("Do I have license to code?")
.advisors(a -> a.param(AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY, conversationId))
.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, conversationId))
.call()
.content();
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ ChatClient.builder(chatModel)
.build()
.prompt()
.advisors(
new MessageChatMemoryAdvisor(chatMemory),
new QuestionAnswerAdvisor(vectorStore)
MessageChatMemoryAdvisor.builder(chatMemory).build(),
QuestionAnswerAdvisor.builder(vectorStore).build()
)
.user(userText)
.call()
Expand Down Expand Up @@ -611,13 +611,12 @@ TIP: Be cautious about logging sensitive information in production environments.

== Chat Memory

The interface `ChatMemory` represents a storage for chat conversation history. It provides methods to add messages to a conversation, retrieve messages from a conversation, and clear the conversation history.
The interface `ChatMemory` represents a storage for chat conversation memory. It provides methods to add messages to a conversation, retrieve messages from a conversation, and clear the conversation history.

There is currently one implementation: `MessageWindowChatMemory`.
There is currently one built-in implementation: `MessageWindowChatMemory`.

`MessageWindowChatMemory` is a chat memory implementation that maintains a window of messages up to a specified maximum size (default: 20 messages). When the number of messages exceeds this limit, older messages are evicted, but system messages are preserved. If a new system message is added, all previous system messages are removed from memory. This ensures that the most recent context is always available for the conversation while keeping memory usage bounded.

The `MessageWindowChatMemory` is backed by the `ChatMemoryRepository` abstraction which provides storage implementations for the chat conversation memory. There are several implementations available, including the `InMemoryChatMemoryRepository`, `JdbcChatMemoryRepository`, `CassandraChatMemoryRepository` and `Neo4jChatMemoryRepository`.

The `MessageWindowChatMemory` is backed by the `ChatMemoryRepository` abstraction which provides storage implementations for the chat conversation history. There are several implementations available, including the `InMemoryChatMemoryRepository`, `JdbcChatMemoryRepository`, `CassandraChatMemoryRepository` and `Neo4jChatMemoryRepository`.

This implementation is the default for conversation history management in Spring AI. For more details and usage examples, see the xref:api/chat-memory.adoc[Chat Memory] section.
For more details and usage examples, see the xref:api/chat-memory.adoc[Chat Memory] documentation.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For details, refer to:
[[upgrading-to-1-0-0-RC1]]
== Upgrading to 1.0.0-RC1

=== Chat ClientAnd Advisors
=== Chat Client and Advisors

* When building a `Prompt` from the ChatClient input, the `SystemMessage` built from `systemText()` is now placed first in the message list. Before, it was put last, resulting in errors with several model providers.
* `MessageAggregator` has a new method to aggregate messages from `ChatClientRequest`. The previous method aggregating messages from the old `AdvisedRequest` has been removed, since it was already marked as deprecated in M8.
Expand Down Expand Up @@ -60,6 +60,7 @@ If you were providing custom templates for the following advisors, you'll need t
** a `long_term_memory` placeholder to receive the retrieved conversation memory.

=== Breaking Changes

The Watson AI model was removed as it was based on the older text generation that is considered outdated as there is a new chat generation model available.
Hopefully Watson will reappear in a future version of Spring AI

Expand All @@ -82,6 +83,7 @@ In 1.0.0-RC1, the chat memory modules, starters, and autoconfiguration classes f

- Java packages now use `.repository.` (e.g., `org.springframework.ai.chat.memory.repository.jdbc.JdbcChatMemoryRepository` and `org.springframework.ai.model.chat.memory.repository.jdbc.autoconfigure.JdbcChatMemoryRepositoryAutoConfiguration`).
- Main autoconfiguration classes are now named `JdbcChatMemoryRepositoryAutoConfiguration`, `CassandraChatMemoryRepositoryAutoConfiguration`, etc.
- Properties have also been renamed to reflect the new naming convention, from `spring.ai.chat.memory.<storage>...` to `spring.ai.chat.memory.repository.<storage>...`.

**Migration Required:**
- Update your Maven/Gradle dependencies to use the new artifact IDs.
Expand Down