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>
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>
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>
- 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>
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>
- 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>
- 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>
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>
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>
- 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>
* 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>
- 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>
- 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>
* 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>
- 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