Commit Graph

39 Commits

Author SHA1 Message Date
Yanming Zhou
769cf10326 JdbcChatMemoryRepository should use the provided JdbcTemplate
Before this commit, the underlying `JdbcTemplate` is created like `new JdbcTemplate(providedJdbcTemplate.getDataSource())`, it means that settings on provided `JdbcTemplate` will lose.

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
2025-05-17 11:51:55 -04:00
Yanming Zhou
b83a162506 JdbcChatMemoryRepository should use the provided JdbcTemplate
Before this commit, the underlying `JdbcTemplate` is created like `new JdbcTemplate(providedJdbcTemplate.getDataSource())`, it means that settings on provided `JdbcTemplate` will lose.

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
2025-05-17 11:50:39 -04:00
Yanming Zhou
bbc2bbf661 Improve JdbcChatMemoryRepository to simplify findConversationIds()
Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
2025-05-17 11:11:13 -04:00
Christian Tzolov
5d6bbd9368 refactor: update dependencies to use spring-ai-model and spring-ai-commons
Replace spring-ai-client-chat dependency with spring-ai-model in model implementations
and memory repositories, and with spring-ai-commons in document readers. This change
improves the dependency structure by having components depend on the appropriate
abstraction level.

Additional changes:
- Add slf4j-api dependency to pdf-reader and spring-ai-retry
- Move spring-ai-client-chat to test scope in spring-ai-ollama
- Fix XML formatting in some pom.xml files

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-16 19:58:11 +02:00
Yanming Zhou
eba7bde870 Polish dependencies (#3198)
Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
2025-05-16 12:23:26 +01:00
Soby Chacko
368be3a04f Fixing miscellaneous checkstyle errors
Enabling checkstyle by default in the project build

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-05-16 11:08:33 +01:00
Ilayaperumal Gopinathan
31feb4319b Remove duplicate dependency from spring-ai-model-chat-memory-repository-jdbc POM
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-16 11:00:09 +01:00
Mark Pollack
008a760fa7 Add dataSource() method to JdbcChatMemoryRepository.Builder and improve dialect detection
- Added a dataSource(DataSource) method to the builder
- Now, if no dialect is specified, the implementation will attempt to detect it from the effective DataSource (either set directly or obtained from the JdbcTemplate).
- Updated builder logic to default to the DataSource from the JdbcTemplate if dataSource() is not called, ensuring dialect detection works out-of-the-box.
- The builder now prefers a directly provided DataSource, but remains backwards compatible with JdbcTemplate-based configuration.
- Added tests

Fixes #3148

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-15 16:44:56 -04:00
Sun Yuhan
31da8f3dbb fix: Fixed the incorrect SQL in getSelectMessagesSql of MysqlChatMemoryRepositoryDialect
- Added tests

Signed-off-by: Sun Yuhan <1085481446@qq.com>
2025-05-15 16:14:53 -04:00
Sun Yuhan
0e1bb52ab7 fix: Added transaction support for saveAll in JdbcChatMemoryRepository
- Add optional PlatformTransactionManager
- Add tests

Signed-off-by: Sun Yuhan <1085481446@qq.com>
2025-05-15 14:23:00 -04:00
Ilayaperumal Gopinathan
f2940cffce Next development version 2025-05-13 19:06:16 +01:00
Ilayaperumal Gopinathan
30a9638de8 Release version 1.0.0-RC1 2025-05-13 19:05:52 +01:00
mck
87b680af7c Optimise CassandraChatMemoryRepository for MessageWindowChatMemory usage pattern
Time-series each chat window in Cassandra, keeping past (and deleted) windows still in the db.
Add ability to store different MessageTypes.

Signed-off-by: mck <mck@apache.org>
2025-05-13 10:13:44 +01:00
Ilayaperumal Gopinathan
2d517eec5c Refactor chat memory repository artifacts for clarity
- Rename the artifact ID of the chat memory repository artifacts:

    - `spring-ai-model-chat-memory-jdbc` -> `spring-ai-model-chat-memory-repository-jdbc`
    - `spring-ai-model-chat-memory-cassandra` -> `spring-ai-model-chat-memory-repository-cassandra`
    - `spring-ai-model-chat-memory-neo4j` -> `spring-ai-model-chat-memory-repository-neo4j`

 - Rename the package names to include "repository". Example: org.springframework.ai.chat.memory.repository.jdbc.JdbcChatMemoryRepository
    - This package renaming also requires to change the default schema location for the jdbc repository to include "repository"
      - Update the docs

 - Update the artifact IDs in the parent POM, BOM, autoconfiguration and starters
 - Update upgrade notes and docs to describe the changes

Fix JdbcChatMemoryRepositoryPostgresqlIT
 - Make sure to set the dialect via datasource

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-12 13:02:26 -04:00
Mark Pollack
11e3c8f9a6 refactor(cassandra): Remove CassandraChatMemory implementation
- Removed the CassandraChatMemory class and its usages, now using CassandraChatMemoryRepository.
- Updated configuration, repository, and test classes to rely on CassandraChatMemoryRepository.
- Cleaned up related configuration and integration tests.
- Minor doc update to reflect the removal.

Fixes #3090

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-10 17:34:13 -04:00
mck
2450ae592e Implement CassandraChatMemoryRepository
ref: https://github.com/spring-projects/spring-ai/issues/2998
Signed-off-by: mck <mck@apache.org>
2025-05-09 16:44:29 -04:00
Mark Pollack
08958af670 Add flexible support for multiple database variations in JdbcChatMemory
Add SQL Server dialect support with new SqlServerChatMemoryDialect class

Create schema-sqlserver.sql script for SQL Server table creation

Refactor database schema initialization with new JdbcChatMemorySchemaInitializer

Standardize table names across databases to SPRING_AI_CHAT_MEMORY

Implement ChatMemoryDialect abstraction for database-specific operations

Add dialect implementations for PostgreSQL, MySQL/MariaDB, HSQLDB

Update configuration properties with more flexible schema initialization options

Enhance documentation with detailed information about dialect support and configuration

Add integration tests for HSQLDB and SQL Server

Signed-off-by: Mark Pollack <247466+markpollack@users.noreply.github.com>
2025-05-09 20:30:53 +01:00
Michael Simons
1c06d7ccd9 Polish Neo4jChatMemoryRepository.
This change turns all the labels into parameters, avoiding the possibility of Cypher injection as the config does not do any sanitization.
In addition, the interaction with the driver is changed so that it uses transactional functions, which are retried when any communication with the Neo4j DBMS fails.
We can do this here as the repository is not subject to application wide transactions.

An alternative to the parameters for labels would be using Cypher-DSL as we did in other parts of this project to sanitize labels proper.

Signed-off-by: Michael Simons <michael@simons.ac>
2025-05-09 15:56:25 +01:00
enricorampazzo
43aa8939d2 Enhance Neo4jChatMemoryRepository, expand integration tests, improve configuration, and update documentation
- Enhanced Neo4jChatMemoryRepository to correctly restore custom metadata for SystemMessage using SystemMessage.Builder.
- Refactored and clarified Neo4jChatMemoryRepository implementation code.
- Added comprehensive integration tests for Neo4jChatMemoryConfig and Neo4jChatMemoryRepository, including:
-- Index creation verification
-- Custom label support
-- Getter validation for all configuration properties
-- Tests for saving and retrieving SystemMessage metadata
-- Tests ensuring saveAll(conversationId, Collections.emptyList()) clears all messages and removes the conversation node
-- Tests for handling of messages with empty content and empty metadata
-- Improved overall test coverage for Neo4j persistence and configuration edge cases
- Fixed resource management bugs in test classes (ensured proper driver/session closure).
- Improved index creation logic in Neo4jChatMemoryConfig for reliability and logging.
- Updated documentation to include Neo4jChatMemoryRepository usage and configuration

Signed-off-by: enricorampazzo <enrico.rampazzo@live.com>
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-06 15:31:11 -04:00
enricorampazzo
4ec067641b updates from spring-ai
Signed-off-by: enricorampazzo <enrico.rampazzo@live.com>
2025-05-06 15:31:11 -04:00
Thomas Vitale
356a68f15e Remove deprecations in JdbcChatMemory
* Remove deprecated APIs for JdbcChatMemory.
* Improve documentation about chat memory vs. chat history.
* Fix mismatch between docs vs code for max messages in MessageWindowChatMemory.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-05-06 00:40:08 -04:00
Ilayaperumal Gopinathan
228ef10bfb Remove deprecated methods from Media
- Remove deprecated constructor method Media(MimeType mimeType, URL url) from Media
 - Remove deprecated builder method data(URL url) from Media builder
 - Update references to use the builder and the data(URI) methods

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-05 01:47:45 +01:00
Ilayaperumal Gopinathan
06edee4069 Remove deprecated UserMessage constructors
- Remove deprecated constructor methods
 - Replace them with the builder methods

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-05 01:06:21 +01:00
Ilayaperumal Gopinathan
3acc206eb2 Next development version 2025-04-30 17:51:20 +01:00
Ilayaperumal Gopinathan
b657cf3bae Release version 1.0.0-M8 2025-04-30 17:51:07 +01:00
Linar Abzaltdinov
a1db00ab1e Fixed message order for JDBC Chat Memory
- set timestamp manually to prevent saving equal timestamps while batch insert
- return DESC order into get query (in `JdbcChatMemory`)
- Update similar changes for JdbcChatMemoryRepository

This PR solves some problems with message ordering:

JdbcChatMemory fetches rows in DESC order, and MessageChatMemoryAdvisor get and add all messages in that order - from last to first. So messages list needs to be reversed.
After batch insert without specifying timestamp manually all rows have the same timestamp (because database sets current_timestamp by default). Sooo after fetching rows from database the message order is unpredictable - they have same timestamp.

Signed-off-by: Linar Abzaltdinov <abzaltdinov@gmail.com>
2025-04-29 16:04:32 +01:00
Linar Abzaltdinov
1bf5787865 Fix message order in Cassandra chat memory after retrieving from db
Fixes: https://github.com/spring-projects/spring-ai/issues/2815

Added integration tests

Replaced deprecated CassandraContainer test-container by actual one

Reordered imports in CassandraChatMemoryIT

Signed-off-by: Linar Abzaltdinov <abzaltdinov@gmail.com>

Fixing CassandraChatMemoryAutoConfigurationIT for the correct ordering

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-28 20:20:10 -04:00
Eddú Meléndez Gonzales
22c778f8cc Switch CassandraContainer implementation (#2663)
`org.testcontainers.containers.CassandraContainer` is deprecated.

Signed-off-by: Eddú Meléndez <eddu.melendez@gmail.com>
2025-04-28 17:08:27 +01:00
Thomas Vitale
0024e4dd49 Chat Memory Enhancements
* ChatMemory will become a generic interface to implement different memory management strategies. It’s been moved from the “”spring-ai-client-chat” package to “spring-ai-model” package while retaining the same package, so it’s transparent to users.
* A MessageWindowChatMemory has been introduced to provide support for a chat memory that keeps at most N messages in the memory.
* A ChatMemoryRepository interface has been introduced to support different storage strategies for the chat memory. It’s meant to be used as part of a ChatMemory implementation. This is different than before, where the storage-specific implementation was directly tied to the ChatMemory. This design is familiar to Spring users since it’s used already in the ecosystem. The goal was to use a programming model similar to Spring Session and Spring Data.
* The JdbcChatMemory has been supersed by JdbcChatMemoryRepository.
* A ChatMemory bean is auto-configured for you whenever using one of the Spring AI Model starters. By default, it uses the MessageWindowChatMemory implementation and stores the conversation history in memory. If a different repository is already configured (e.g., Cassandra, JDBC, or Neo4j), Spring AI will use that instead.
* First-class documentation has been introduced to describe the ChatMemory API and related features.
* All the changes introduced in this PR are backward-compatible.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-04-25 15:53:20 -04:00
Soby Chacko
d9e7ace996 Miscellaneous checkstyle fixes
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-14 09:48:03 +01:00
Ilayaperumal Gopinathan
853d478bca Add SCM URL to the chat memory POM files
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-10 22:34:38 +01:00
Ilayaperumal Gopinathan
442b2e9156 Update project URL in the POM files for chat memory modules
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-10 22:34:29 +01:00
Ilayaperumal Gopinathan
bda702e8e1 Next development version 2025-04-10 20:23:38 +01:00
Ilayaperumal Gopinathan
584138af28 Release version 1.0.0-M7 2025-04-10 20:23:07 +01:00
leijendary
4be10028b0 feat: JDBC implementation of ChatMemory
Signed-off-by: leijendary <jonathanleijendekker@gmail.com>

Remove references to spring-ai-core module in jdbc chat memory
2025-04-07 15:08:58 -04:00
Ilayaperumal Gopinathan
b4fa31188a Refactoring cleanup
- Update Spring AI BOM with the newly added modules
 - Remove unnecessary dependencies from the modules' POM file
2025-04-04 12:43:22 -04:00
Soby Chacko
717e419515 Rename spring-ai parent from spring-ai to spring-ai-parent
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-04 12:43:22 -04:00
Soby Chacko
f7f00328a1 Migrate Cassandra chat memory implementation to its own module
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-04 11:44:38 -04:00
Mark Pollack
d45ff8e984 Refactorings
- Avoid overlapping package names
  Changed in spring-ai-commons package from org.sf.ai.model to org.sf.ai.content
  Refactor advisor module name to be spring-ai-advisors-vector-store
    Moved advisors into org.springframework.ai.chat.client.advisor.vectorstore

- Created top level memory directory
- Create new module spring-ai-model-chat-memory-neo4j and moved neo4j memory classes out of the vectorstore module
  Updated neo4j autoconfiguation
2025-04-04 11:44:38 -04:00