Commit Graph

83 Commits

Author SHA1 Message Date
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
Jonatan Ivanov
3fb66928f5 Add missing observability tests
Some tests were missing from gh-3003, this change adds them

See gh-3003
2025-05-15 10:09:31 +02:00
Yanming Zhou
0bcb2e138b Fix outdated configuration key include-completion and include-query-response
Fixes GH-3151

Follow-up of commit ca843e85887aa1da6300c77550c379c103500897,`includeCompletion` is renamed to `logCompletion`.

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
2025-05-15 09:30:45 +02: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
Thomas Vitale
9ff6d3b364 Update memory docs and ensure consistent naming
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-05-13 11:33:44 -04: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
Yanming Zhou
e10fbde7a1 Align JdbcChatMemoryRepositoryProperties with other modules in Spring Boot
Such as `BatchProperties.Jdbc`, `IntegrationProperties.Jdbc`, `JdbcSessionProperties` and `QuartzProperties.Jdbc`

1. Reuse Spring Boot's `DatabaseInitializationMode`
2. Allow to customize platform
3. add `OnJdbcChatMemoryRepositoryDatasourceInitializationCondition` for `JdbcChatMemoryRepositorySchemaInitializer`

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
2025-05-12 16:18:11 +01:00
Tran Ngoc Nhan
7aa440e6bc Fix typos
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
2025-05-12 13:31:40 +01:00
HYUNSANG HAN (한현상, Travis)
49209d1d76 Enable auto complete for 'spring.ai.vertex.ai.gemini.chat.options' (#3101)
Signed-off-by: Hyunsang Han <gustkd3@snu.ac.kr>
2025-05-12 13:10:39 +01:00
lambochen
7739e1e54c OpenAiImageModel support configure imagesPath
Signed-off-by: lambochen <lambochen@yeah.net>
2025-05-12 17:31:49 +08:00
Thomas Vitale
30eb3ce3f2 Micrometer instrumentation for tool calling
Introduce instrumentation for tool calling using the Micrometer Observation API.

By default, metadata about tool calling are exported as metrics and traces.
Optionally, the actual tool call input and result can be exported as well by enabling the dedicated feature flag.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-05-11 07:26:44 +02: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
Ilayaperumal Gopinathan
f6dba1bf08 Refactor chat memory repository autoconfigurations and Spring Boot starters for clarity
- Rename chat memory repository autoconfiguration modules to include the "repository" suffix:
    - spring-ai-autoconfigure-model-chat-memory-cassandra -> spring-ai-autoconfigure-model-chat-memory-repository-cassandra
    - spring-ai-autoconfigure-model-chat-memory-jdbc -> spring-ai-autoconfigure-model-chat-memory-repository-jdbc
    - spring-ai-autoconfigure-model-chat-memory-neo4j -> spring-ai-autoconfigure-model-chat-memory-repository-neo4j
- Update Spring Boot starter modules to match the new naming convention.
- Rename packages to include `.repository.` for improved clarity and consistency.
- Rename configuration and related classes to use the `ChatMemoryRepository` suffix.
- Update Spring AI BOM and parent POM files to reference the new artifact names.
- Update all imports, references, and configuration to use the new package and class names.

BREAKING CHANGE:
These changes require users to update their dependencies, imports, and configuration to use the new artifact, package, and class names. See the upgrade notes for migration instructions.

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-10 14:56:08 -04:00
Jonatan Ivanov
ca843e8588 feat(observability): refactor content observation to use logging instead of tracing
This removes the possible large amount of data that was attached
to spans and it logs the data out. This change also removes the direct
dependency on the OTel SDK. approach for content in Spring AI.

Refactors the observability approach for content in Spring AI:

- Replace content observation filters with logging handlers
- Rename configuration properties to better reflect their purpose:
  - `include-prompt` → `log-prompt`
  - `include-completion` → `log-completion`
  - `include-query-response` → `log-query-response`
- Add TracingAwareLoggingObservationHandler for trace-aware logging
- Replace micrometer-tracing-bridge-otel with micrometer-tracing
- Remove event-based tracing in favor of direct logging
- Update documentation to reflect these changes (add breaking-changes section)
- Rename includePrompt to logPrompt in observation properties. Updated in ChatClientBuilderProperties, ChatObservationProperties, and ImageObservationProperties.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-10 19:36:11 +02:00
PSriVarshan
a36c70976c Add observability to Bedrock Titan Embedding model
Signed-off-by: PSriVarshan <psvvarshan@gmail.com>
2025-05-10 16:38:37 +01:00
Mark Pollack
0bd0cddc29 Fix CassandraChatMemoryAutoConfigurationIT
Added .repository to property name in test
2025-05-10 10:55:29 -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
Mark Pollack
ebfa5b9b2c refactor: remove inter package dependency cycles in spring-ai-model
Remove circular dependencies:

Move utility classes from various packages to dedicated support packages:
- Move ToolCallbacks from ai.tool to ai.support
- Move UsageUtils to UsageCalculator in ai.support
- Move tool.util to tool.support
- Create new ToolDefinitions utility class

Support packages for the classes in question is more idomatic in spring than util packages.

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-08 12:20:27 +01:00
Christian Tzolov
e010899fbe fix(tool): handle non-existing tool callbacks gracefully
- Add error handling to SpringBeanToolCallbackResolver to return null
  instead of throwing exceptions when resolving non-existing tools.
  This make is consitent with other tool resolver implementations
  and centralize the error handling in the tool calling manager.
- Add test to verify that the ToolCallbackResolver correctly
  returns null for non-existing tools.

Related to #2667

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-08 10:24:47 +01:00
GR
c54dfd35d5 feat: add deepseek starter and docs - fix pom module ordering
- Add remaining deepseek modules
- Fix build order to put autoconfig modules after model modules to fix javadoc build

Signed-off-by: GR <gr@fastball.dev>
2025-05-07 23:38:07 -04:00
Dariusz Jędrzejczyk
97f90b19d6 Fix mutating global RestClient and WebClient builders (#3020)
Since the builders for HTTP clients are mutable and shared, they should
only be configured with globally applicable settings. The current use
leaks specific details into other usages and affects newly instantiated
clients. This PR applies the clone() method right before mutation
happens as it probably is the strategy that avoids multiple unnecessary
copies.

feat: improve RestClient and WebClient instantiation and configuration across AI modules

- Ensure RestClient.Builder and WebClient.Builder are properly cloned before setting base URLs and headers in Mistral, OpenAI, and Ollama API classes to prevent side effects.
- Add WebClientAutoConfiguration to auto-configuration classes for Anthropic and Mistral AI modules.
- Update Mistral AI auto-configuration to inject and use WebClient.Builder.
- Clean up test and annotation usage (remove unnecessary @Nullable, fix test builder usage in AnthropicApiIT).
- Improve consistency and reliability of HTTP client configuration across model integrations.

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-07 18:15:55 +02: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
4fe74d886e Remove deprecations in ChatClient and Advisors
* Update remaining Advisors and related classes to use the new APIs.
* In AbstractChatMemoryAdvisor, the “doNextWithProtectFromBlockingBefore()” protected method has been changed from accepting AdvisedRequest to ChatClientRequest. It’s a breaking change since the alternative was not part of M8.
* MessageAggregator has a new method to aggregate messages from ChatClientRequest. The previous method aggregating messages from AdvisedRequest has been removed. Warning since it wasn’t marked as deprecated in M8.
* In SimpleLoggerAdvisor, the “requestToString” input argument needs to be updated to use ChatClientRequest. It’s a breaking change since the alternative was not part of M8. Same thing about the constructor.
* The “getTemplateRenderer” method has been removed from BaseAdvisorChain. Each Advisor is encouraged to accept a PromptTemplate to achieve self-contained prompt augmentation operations.
* Remove deprecations in ChatClient and Advisors, and update tests accordingly.
* When building a Prompt from the ChatClient input, the SystemMessage passed via systemText() is placed first in the message list. Before, it was put last, resulting in errors with several model providers.

Relates to gh-2655

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-05-06 09:58:06 +01: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
Mark Heckler
3dc86d33ce Added Entra ID identity management for Azure OpenAI, clean autoconfiguration, and updated docs to reflect changes.
Signed-off-by: Mark Heckler <mark.heckler@gmail.com>
2025-05-05 21:03:43 -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
46be8987d6 Remove deprecations from OllamApi and AnthropicApi
- Remove deprecated constructors from OllamaApi and AnthropicApi
 - Modify AnthropicApi's public constructor to be private so that only the builder method can use it to construct
 - Update OllamApiAutoConfiguration and AnthropicChatAutoconfiguration to use the builder methods to construct the respective
 Apis
 - Fix other constructor usages to builder methods

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-05 00:21:34 +01:00
Mark Pollack
9e71b163e3 Remove Waston text generation model 2025-05-03 18:36:02 -04:00
Mark Pollack
6ffbb3acc6 Add simple hello world test to reproduce issue #2957 with qwen/ollama 2025-05-03 18:22:05 -04:00
Mark Pollack
bfcaad7b54 Second pass to remove qianfan code 2025-05-03 17:15:18 -04: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
Mark Pollack
091fca2d16 refactor(client): rename overloaded tools methods in prompt builder
Renames the ambiguous overloaded `tools` methods in `ChatClient.PromptRequestSpec`
to `toolNames` and `toolCallbacks` respectively. This improves clarity
and prevents potential issues with method dispatching based on argument types.

Updates relevant code examples and adds documentation to upgrade notes.

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-04-30 10:42:46 -04:00
“claudio-code”
d7eb9bb32e Added the possibility to configure the path together with the base-url
Signed-off-by: “claudio-code” <suporte2424@outlook.com>
2025-04-29 17:39:16 +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
Changho Kim
2e0017db49 fix: Typo at the codebase
fix: correct name typo from 'AsynClients' to 'AsyncClients'

fix: correct name typo from 'Autoconfiguration' to 'AutoConfiguration', 'optoins' to 'options'

fix: correct name typo from 'Differnt' to 'Different'

fix: correct name typo from 'Compatability' to 'Compatibility'

fix: correct name typo from 'Evalutaor' to 'Evaluator'

fix: correct name typo from 'Empyt' to 'Empty'

fix: correct name typo from 'Chroma Vecor Store' to 'Chroma Vector Store'

fix: correct name typo from 'Specificaiton' to 'Specification'

fix: correct name typo from 'applicaiton' to 'application'

fix: correct name typo from 'apropriate' to 'appropriate'

fix: correct name typo from 'asigned' to 'assigned'

fix: correct name typo from 'capabilitity' to 'capability'

fix: correct name typo from 'configuraiton' to 'configuration'

fix: correct name typo from 'conntection' to 'connection'

fix: correct name typo from 'curent' to 'current'

fix: correct name typo from 'customised' to 'customized'

Signed-off-by: Changho Kim <dukso4885@gmail.com>
2025-04-29 10:13:21 +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
Thomas Vitale
688eab19f9 Add missing metadata for spring.ai.model.* properties
* The new spring.ai.model.* properties introduced in M7 were missing Spring Boot configuration metadata.

* Furthermore, the breaking change was not documented as the previous properties have been completely removed. Documentation has been added in the upgrade notes for this change.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-04-28 17:49:31 -04:00
Thomas Vitale
faa8778b6a Make ChatClient and Advisor APIs more robust - Part 2
* ChatClient observations now include the full prompt content instead of just the userText and systemText. Furthermore, they include consistent telemetry for the tools passed via the ChatClient and a first-class conversation ID when using memory advisors. Incomplete or unsafe attributes have been deprecated.
* Adopted the new robust Advisor APIs for BaseAdvisor and RetrievalAugmentationAdvisor.
* Improved the prompt augmentation facilities in ChatClientRequest and Prompt for performance and immutability.
* Fixed integration test racing condition.
* Updated the documentation for ChatClient and Observability accordingly.
* Documented changes in upgrade notes.
* Introduced `prompt.augmentUserMessage(String text)` to directly replace the user message content.
* Added `prompt.augmentUserMessage(Function<UserMessage, UserMessage> augmenter)` for more granular updates using the `userMessage.mutate()` pattern, allowing modification of text, media, and metadata.

Relates to gh-2655

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-04-28 17:35:55 -04:00
Ilayaperumal Gopinathan
f0702c343b Remove deprecated FunctionCallback references
- Remove the deprecated FunctionCallback related classes, references
 - Replace them with the corresponding ToolCallback usage

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-28 12:19:52 -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
Ilayaperumal Gopinathan
8deb23afe1 Removing deprecated constructors and methods
- VectorStoreChatMemoryAdvisor constructors
- "withX" methods in AnthropicApi
- Deprecated function methods in VertexAiGeminiChatOptions
- Deprecated test methods
- Removed deprecation from Document.getContentFormatter
- Removed withEmbedding method in SimpleVectorStoreContent")

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-28 10:28:22 -04:00
Łukasz Jernaś
c726005a5b Add autoconfiguration processor for autoconfigure modules
Signed-off-by: Łukasz Jernaś <lukasz.jernas@allegro.com>
2025-04-28 12:49:53 +01:00
Ilayaperumal Gopinathan
7f0a97d4a7 Remove FunctionCallbackResolver from chat model autoconfigurations
- FunctionCallbackResolver is deprecated and replaced by ToolCallingManager's ToolCallbackResolver

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-28 08:01:59 +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