Commit Graph

403 Commits

Author SHA1 Message Date
Mark Pollack
67a8896422 Next development version 2024-11-20 18:03:30 -05:00
Mark Pollack
33c05c399c Release version 1.0.0-M4 2024-11-20 18:02:47 -05:00
Christian Tzolov
52999b44b5 Align with the latest Chroma API
- Added Jackson annotations for JSON property handling in Chroma API request/response records.
  Use @JsonInclude(JsonInclude.Include.NON_NULL) to ignore empty fields such as null where.
  Use @JsonProperty(XYZ) to provide a strong contract with the Cohere API.
- Updated the Docker image for running Chroma locally and in tests to version 0.5.20.
- Enhanced  methods with non-null assertions for improved code safety.
- Added a simple search test to verify document similarity search functionality.

Fixes #1749
2024-11-20 10:11:41 -05:00
Ilayaperumal Gopinathan
3b95dfd87f Fix checkstyle errors 2024-11-19 23:29:36 +00:00
Mark Pollack
a4462420d8 Add support for optional keyless authentication.
Implemented a new configuration property 'useKeylessAuth' to toggle
between API key and Azure default credential authentication.

Added necessary dependencies and updated tests to reflect the new changes.

co-authored-by: mattgotteiner <mattgotteiner@users.noreply.github.com>
2024-11-19 16:15:07 -05:00
Ilayaperumal Gopinathan
de53e64bfd Fix OpenSearch vector store configuration and update mapping defaults
- Fix the embedding dimension configuration for opensearch client indices mapping
  The dimension config is obtained by the underlying embedding model's dimension
- Updated OpenSearch mapping JSON to include dynamic embedding dimension.
- Changed default mapping for OpenSearch vector store to use generic dimension placeholder.
- Fixed OpenSearchVectorStoreAutoConfiguration to fallback to new default mapping if no custom mapping is provided.
- Added test for verifying mapping configuration with OpenSearch vector store.
- Added test dependencies for Ollama integration.
- Refactored OpenSearch integration tests to use new mapping and dimension logic.

Add tests

- Verify the mappingJson field is correctly set - verify the override works fine
- Add integration tests with Ollama embedding model

Resolves #1589
2024-11-19 20:55:36 +01:00
Eddú Meléndez
6261ce02ff Add LocalStack OpenSearch Service Connection support for Docker Compose and Testcontainers
* Add property `spring.ai.vectorstore.opensearch.aws.domain-name`
* Require `AwsCredentialsProvider` to enable `AwsOpenSearchConfiguration`
* Add Testcontainers Service Connection support
* Add Docker Compose Service Connection support
2024-11-19 11:58:37 +00:00
Soby Chacko
3b430a5bee Fix Kotlin test deprecation warning 2024-11-19 11:07:41 +00:00
Soby Chacko
f5b00a027c Various checkstyle fixes 2024-11-18 19:17:09 -05:00
jitokim
a7a1804fac Rename Cassandra TTL Property for Clarity
Rename `timeToLiveSeconds` to `timeToLive` in
`CassandraChatMemoryProperties` and associated code to prevent
misleading interpretation. This change addresses issue #1728, as
the property previously suggested values in seconds but expected
milliseconds.

Improve readability and ensure accurate configuration by aligning
the name with its behavior. Include updates to test cases to
validate the new property name and verify ISO 8601 format handling.

Fixes #1728

Signed-off-by: Jihoon Kim <pigberger70@gmail.com>
2024-11-18 16:24:08 -05:00
Christian Tzolov
432954dad7 Add Supplier and Consumer function callback support in function calling
Add support for no-argument Supplier and single-argument Consumer function
callbacks in the Spring AI core module. This enhancement allows:
- Registration of Supplier<O> callbacks with no input (Void) type
- Registration of Consumer<I> callbacks with no output (Void) type
- Support for Kotlin Function0 (equivalent to Java Supplier)
- Handle empty properties for Void input types in schema generation
- Enhance FunctionCallback builder to support Supplier/Consumer patterns

Additional changes:
- Add test coverage for both Supplier and Consumer callbacks in various scenarios
- Enhance TypeResolverHelper to support Consumer input type resolution
- Support lambda-style function declarations for improved ergonomics
- Add test cases for void input/output handling in OpenAI chat model
- Include examples of function calls without return values
- Add support for parameterless functions through Supplier interface

Add comprehensive documentation for the FunctionCallback API:
- Overview of the interface and its key methods
- Builder pattern usage with function and method invocation approaches
- Examples for different function types (Function, BiFunction, Supplier, Consumer)
- Best practices and common pitfalls
- Schema generation and customization options

Resolves #1718 , #1277 , #1118, #860
2024-11-18 15:54:21 -05:00
Christian Tzolov
0ca91b2ed9 fix: Resolve various javadoc and checkstyle issues 2024-11-16 11:06:14 +01:00
Christian Tzolov
fb0d99dc37 Revamp function callback builder API
Introduces a simplified, type-safe builder pattern for function callbacks to
improve developer experience and code reliability. The new hierarchical API
separates concerns between direct function invocation and method reflection,
while providing better compile-time safety.

This change deprecates the older FunctionCallbackWrapper in favor of a more
intuitive FunctionCallback.Builder that better handles generic types via
ParameterizedTypeReference. It also adds automatic function description
generation as a fallback when none is provided, though explicit descriptions
are still recommended.

The update standardizes function callback handling across all AI model
implementations (OpenAI, Ollama, Minimax, etc.) and improves response
handling with configurable converters.

Core API Enhancements:

- New Builder Interface: Replaced FunctionCallbackWrapper.builder() with
   FunctionCallback.builder(), introducing a hierarchical approach that improves
   customization and type safety.
- Specialized Builders: Introduced FunctionInvokerBuilder for direct Function/BiFunction
   implementations and MethodInvokerBuilder for reflection-based invocations.
- Generic Type Support: Added ParameterizedTypeReference for better handling of generic parameters.
- Unified Method Definition: Merged method() and argumentTypes() into a single method() call
   for simplicity and type safety.
- Automatic Descriptions: Implemented auto-generation of function descriptions, with warnings
   to encourage explicit descriptions.
- Configurable Response Converters: Enhanced response handling with support for custom
   converters, reducing unnecessary JSON conversions.

Architecture Improvements:

- Established common Builder interface for shared properties
- Separated function object handling from constructor
- Added method-specific configuration (name, arg types, target)
- Added JSON schema generation support for ResolvableType
- Moved to standardized schema types across AI providers
- Set OPEN_API_SCHEMA as default for Vertex AI Gemini

Builder Pattern Standardization:

- Standardized builder method ordering across implementations
- Moved function() call after description() for consistency
- Improved function callback configuration with unified patterns
- Enhanced error handling and validation in DefaultFunctionCallbackBuilder

Deprecations:

- FunctionCallbackWrapper.Builder replaced by DefaultFunctionCallbackBuilder
- Removed CustomizedTypeReference in favor of ParameterizedTypeReference
- Deprecated older ChatClient API methods for function handling

Testing & Documentation:

- Updated all AI model implementations (OpenAI, Ollama, Minimax, Moonshot, ZhiPuAI)
- Added comprehensive integration tests for static/instance methods
- Added integration tests for auto-generated descriptions
- Updated documentation to reflect new builder pattern usage
- Added Kotlin extension for inputType() support

Co-authored-by: Sébastien Deleuze <sebastien.deleuze@broadcom.com>
2024-11-15 15:32:59 -05:00
Ilayaperumal Gopinathan
72c84fe8b8 Remove deprecated code from 1.0 M2 and before
- Remove deprecated types,methods and references
 - Remove usage of "Generation(String text)" and replace with
  "Generation(AssistantMessage)"
 - Remove MiniMaxApi,MootShotApi,OpenAiApi,ZhiPuAiApi
   ChatCompletionFinishReason's FUNCTION_CALL
 - Remove OllamaApi's deprecated types
 - Remove deprecated constructors from PostgresMlEmbeddingModel
 - Remove deprecated constructor from Media
 - Remove tokenNames usage from antlr4 FiltersLexer and FiltersParser
 - Remove deprecated methods from CassandraVectorStoreProperties
 - Remove deprecated constructor and static config class from QdrantVectorStore
 - Minor cleanups on removing deprecated models and versions
 - Remove old name for mixtral models

Resolves #1599
2024-11-15 14:28:21 -05:00
Mark Pollack
1d540a6dd1 CI Actions imporvements 2024-11-12 15:24:23 -05:00
Soby Chacko
5e1f681da2 Fix Ollama Kotlin function callback integration tests
- Add default values to KotlinRequest data class to fix Jackson deserialization
- Replace hardcoded model name with OllamaModel.LLAMA3_2 for consistency
- Extract common test setup into companion objects for Ollama tests
- Replace var with val using when expression in weather service
- Clean up imports and remove unused annotations
- Standardize property access using Kotlin conventions
2024-11-08 21:24:28 -05:00
Mark Pollack
11d8591d84 Remove old @DisabledIf on KotlinIT Ollama tests 2024-11-08 15:54:19 -05:00
Mark Pollack
21fc653464 Improve Ollama test container management
This change simplifies how we manage Ollama containers in tests by moving
from manual toggles to environment variables for better control. Instead of
scattered container configuration, we now have:

- OLLAMA_WITH_REUSE: Toggle reuse of existing containers between tests
- OLLAMA_TESTS_ENABLED: Control test execution globally

The motivation is to make tests more reliable and easier to maintain.
Previously, developers had to modify code to run tests locally vs CI. Now
they can control this via environment variables.

We also introduce thread-safe API access and consistent default settings
across all test classes, removing duplicated configuration and potential
resource leaks.

This makes the test infrastructure more maintainable and provides clearer
separation between local development and CI environments.

Checkstyle fixes.

Make buildOllamaApiWithModel in BaseOllamaIT public and the related test changes.
2024-11-08 12:59:50 -05:00
Sébastien Deleuze
c3c95a82c1 Add Kotlin support and documentation
- Add support for proper Kotlin functions handling by adapting
  `kotlin.jvm.functions.Function1` to `java.util.function.Function` and
  `kotlin.jvm.functions.Function2` to `java.util.function.BiFunction`.
- Removes the dependency on Spring Cloud Function and
  `net.jodah:typetools` which are replaced by leveraging
  Spring Framework `ResolvableType` capabilities.
- Add a Kotlin extension function for
  `FunctionCallbackWrapper.Builder.withInputType` allowing to
  specify `withInputType<T>()` instead of `withInputType(T::class.java)`.
- Add Kotlin documentation.
2024-11-08 18:32:47 +01:00
Soby Chacko
865d429451 Checkstyle changes 2024-11-08 15:18:35 +00:00
Christian Tzolov
9fa89a2fd6 fix: Improve error resilience of the Bedrock stream handling
The changes include:

- Refactor the emitting of next, error, and complete events in the Bedrock stream handling to use a default EmitFailureHandler that retries for 10 seconds before failing.
  This helps improve the error resilience of the stream processing.
- Disable a couple of integration tests related to the COHERE_COMMAND_V14 model, as that model version is no longer supported.
- Adjust some configuration options in the Jurassic2 chat model integration test.

Also resolves #1679
2024-11-08 13:40:57 +00:00
Christian Tzolov
83f7164bff Extract ResponseFormat to standalone class
- Extracts ResponseFormat from being a nested record in OpenAiApi to
   a dedicated class with builder pattern support.
 - Resolve the issue with constructor bindings for the Boog property
   binding.
 - Re-enables previously disabled response format integration tests.

 - Add checkstyle changes
 - Add schema field in ResponseFormat and set jsonSchema via the setter for schema,
   this way schema set via a Boot property also sets the correct JsonSchema
 - Add default constructors in ResponseFormat and JsonSchema

 Resolves #1681
2024-11-06 17:50:23 -05:00
Anders Swanson
fb65ed01bd Add OCI GenAI Cohere Chat integration
Adds Oracle Cloud Infrastructure (OCI) Generative AI's Cohere chat model support
to expand Spring AI's cloud provider capabilities. This allows developers to use
OCI's managed Cohere models through both dedicated and on-demand serving modes.

The integration provides auto-configuration for simple setup while allowing full
customization of model parameters through OCICohereChatOptions. Teams can now
use OCI's Cohere models alongside other providers in Spring AI applications.

This change complements the existing OCI embedding support, offering a complete
set of GenAI capabilities for Oracle Cloud users.

Signed-off-by: Anders Swanson <anders.swanson@oracle.com>
2024-11-06 17:43:48 -05:00
zhaojy
99d9864972 Fix RetryAutoConfiguration class condition
Changes the @ConditionalOnClass condition from RetryTemplate to RetryUtils to
ensure proper conditional loading of retry functionality. This prevents the
auto-configuration from being enabled when spring-retry is present but
spring-ai-retry is not, which was causing issues with modules like
spring-ai-azure-openai that don't include spring-ai-retry.
2024-11-06 15:40:52 -05:00
Mark Pollack
f111aaea04 Revert "Add support for Kotlin functions"
This reverts commit 9cf66333b5.
2024-11-06 12:58:52 -05:00
Christian Tzolov
3fbc310ff4 Allow null or empty userText if request contains Tool Response message
- Add a new test case for testing function call with advisor in BedrockConverseChatClientIT
- Add a new test case for testing tool proxy function call in OpenAiChatClientProxyFunctionCallsIT
- Remove unused model property from BedrockConverseProxyChatProperties
2024-11-06 18:20:29 +01:00
Sébastien Deleuze
9cf66333b5 Add support for Kotlin functions
Add support for proper Kotlin functions handling
by adapting kotlin.jvm.functions.Function1 to
java.util.function.Function and kotlin.jvm.functions.Function2 to
java.util.function.BiFunction.

It also removes the dependency on Spring Cloud Function and
net.jodah:typetools which are replaced by leveraging
Spring Framework ResolvableType capabilities.

Added withInputType Kotlin extension

- Add a Kotlin extension function for
FunctionCallbackWrapper.Builder.withInputType allowing
to specify withInputType<T>() instead of
withInputType(T::class.java).

- Add Kotlin documentation
2024-11-05 17:26:04 -05:00
Soby Chacko
66f58d2d70 Change default build setting to disable Checkstyle enforcement
- Disable project-wide Checkstyle checks to unblock development
- Add documentation for enabling Checkstyle locally
- Fix remaining checkstyle violations in current codebase

Fixes #1669
2024-11-05 10:43:38 -05:00
Christian Tzolov
fd8cac57bb Revert "Revert "Convert API records to POJOs and fix failing autconfig tests""
This reverts commit 3e9a3fd3b0.
2024-11-05 11:52:41 +01:00
Christian Tzolov
3e9a3fd3b0 Revert "Convert API records to POJOs and fix failing autconfig tests"
This reverts commit 4184af5341.
2024-11-05 10:00:57 +01:00
jito
efc392394c Add Cosmos Vector Store configuration to AutoConfiguration imports (#1658)
Signed-off-by: jitokim <pigberger70@gmail.com>
2024-11-04 17:37:54 -05:00
Ilayaperumal Gopinathan
d44a6aff7c GH-924 Remove PaLM API support
https://github.com/spring-projects/spring-ai/pull/1664

  - As a follow up to decommission the PaLM API, the PaLM API support is removed.
  - Remove the model and vector store classes
  - Remove the documentation entries
  - Reference: https://ai.google.dev/palm_docs/deprecation

Resolves #924
2024-11-04 15:22:50 -05:00
Mark Pollack
ff41a1a529 Disable OracleVectorStore and Ollama IT tests 2024-11-03 18:55:09 -05:00
Christian Tzolov
0d2d4b7385 Add Bedrock Converse API chat model support
Introduces support for Amazon Bedrock Converse API through a new BedrockProxyChatModel
implementation. This enables integration with Bedrock's conversation models with features
including:
- Support for sync/async chat completions
- Stream response handling
- Tool/function calling capabilities
- System message support
- Image input support
- Observation and metrics integration
- Configurable model parameters and AWS credentials

Adds core support classes:
- BedrockUsage: Implements Usage interface for token tracking
- ConverseApiUtils: Utility class for handling Bedrock API responses including:
  - Tool use event aggregation and processing
  - Chat response transformation from stream outputs
  - Model options conversion
  - Support for metadata aggregation
- URLValidator: Utility for URL validation and normalization with support for:
  - Basic and strict URL validation
  - URL normalization
  - Multimodal input handling
- Enhanced FunctionCallingOptionsBuilder with merge capabilities for both ChatOptions
  and FunctionCallingOptions
- Added BEDROCK_CONVERSE to AiProvider enum for metrics tracking
- Extended AWS credentials support with session token capability
- Added configurable session token property to BedrockAwsConnectionProperties

Adds new auto-configuration support:
- BedrockConverseProxyChatAutoConfiguration for automatic setup of the Bedrock Converse chat model
- BedrockConverseProxyChatProperties for configuration including:
  - Model selection (defaults to Claude 3 Sonnet)
  - Timeout settings (defaults to 5 minutes)
  - Temperature and token control
  - Top-K and Top-P sampling parameters
- Integration with existing BedrockAwsConnectionConfiguration for AWS credentials

Updates to testing infrastructure:
- Adds comprehensive test suite for Bedrock Converse properties and auto-configuration
- Integration tests for chat completion and streaming scenarios
- Property validation tests for configuration options
- Temporarily disabled other Bedrock tests due to AWS quota limitations
- Added ObjectMapper configuration for proper JSON handling

Added new spring-ai-bedrock-converse-spring-boot-starter module

Updates module configuration in parent POM and BOM to include new bedrock-converse
modules and starters. Adds necessary auto-configuration imports for seamless integration
with Spring Boot applications.

Unrelated changes:
- Disabled several Bedrock model tests (Jurassic2, Llama, Titan) due to AWS quota limitations
- Disabled PaLM2 tests due to API decommissioning by Google

Resolves #809, #802

Add docs and fix configs

- Move timeout configuration from chat properties to connection properties
- Add comprehensive documentation for Bedrock Converse API usage and configuration
- Update tests to reflect configuration changes

Co-authored-by: maxjiang153 <maxjiang153@users.noreply.github.com>

Standardize AWS credential handling in integration tests

- Improve how we manage AWS credentials across our integration test
suite and ensures consistent test configuration. We're replacing individual
environment variable checks with @RequiresAwsCredentials
annotation and standardizing the use of BedrockTestUtils for context creation
in tests

We also align all AWS regions to US_EAST_1 for consistency and add missing
dependency versioning for Oracle Free.

These changes make our AWS tests more easier to maintain.

Key changes:
- Replace @EnabledIfEnvironmentVariable with @RequiresAwsCredentials
- Standardize context creation via BedrockTestUtils
- Set AWS region to US_EAST_1
- Add Oracle Free dependency version in pom.xml
2024-11-03 17:10:24 -05:00
Mark Pollack
0c07edc2e7 Revert back to previous OpenAiApi implementation and disable config prop tests 2024-11-02 16:16:22 -04:00
Soby Chacko
4184af5341 Convert API records to POJOs and fix failing autconfig tests
Following removal of Spring Boot's ConstructorBinding, convert record types
to regular POJOs to maintain JSON serialization. Update API classes:

- Convert FunctionTool and Function records to standard Java classes with
 getters/setters
- Update test assertions to use getter methods instead of record accessors
- Fix failing tests in MiniMax, OpenAi and ZhiPu API implementations

This keeps core API models independent of Spring Boot while ensuring proper
serialization through standard Java beans.

- MistralAIApi FunctionTool ConstructorBinding removal changes
2024-11-02 15:04:06 -04:00
Soby Chacko
254239cfe0 More checkstyle fixes 2024-11-01 12:25:19 -04:00
Soby Chacko
e72ab6ba25 Addressing more checkstyle violations
- Enable checkstyle on more modules and adressing violations
review
2024-10-31 01:04:41 -04:00
Ilayaperumal Gopinathan
d8f7ddb72c GH-513 fix: Support custom field names for Milvus VectorStore collection (#1616)
* GH-513 fix: Support custom field names for Milvus VectorStore collection

- Add configuration properties to override the default field names for doc_id, content, metadata and embedding
- Add support to allow auto-id when enabled
- Add tests

Resolves #513

* Fix package modifier
2024-10-30 14:44:50 -04:00
Soby Chacko
94ddefc73f Remove Spring Boot dependencies from core modules
- Remove @NestedConfigurationProperty and @ConstructorBinding annotations from model options classes
- Remove spring-boot dependency from spring-ai-openai module
- Add exclusion for spring-boot-autoconfigure in spring-cloud-function-context dependency
- Move configuration metadata to spring-ai-spring-boot-autoconfigure module

This change decouples the core AI model implementations from Spring Boot,
making the core modules more lightweight and allowing them to be used in
non-Spring Boot applications. Configuration properties are now handled by
the spring-ai-spring-boot-autoconfigure module instead.

Fixes #1540
2024-10-30 11:58:18 -04:00
Mark Pollack
ca1949c825 Replace static initalization block in BaseOllamaIT
The static block was introducing side effects when doing scans of classpath
for AOT and seems to have been the cause of a failing test.

Updated github actions to use ~/.testcontainers.properties to enable
container resuse
2024-10-29 13:58:09 -04:00
Mark Pollack
c02d13647e Add createExtension option for PostgresML config
The PostgresMLEmbeddingModel autoconfiguration previously always executed
"CREATE EXTENSION IF NOT EXISTS pgml" on startup. This could cause issues
for users without superuser privileges or those who manage extensions
through other means.

Added a new configuration property 'createExtension' (default false) to
make this behavior optional. Users can now explicitly enable extension
creation when needed.

Updated documentation to explain the new configuration option and its
implications for deployment.
2024-10-28 12:42:59 -04:00
Christian Tzolov
9c7af5641f Increase the timeout/retry for auto-conf BaseOllamaIT
Add ModelManagementOptions configuration to BaseOllamaIT
  with 2 max retries and 10 minute timeout
2024-10-25 15:43:21 +02:00
Soby Chacko
8e758dbd00 Introduce checkstyle plugin
- Based on https://github.com/spring-io/spring-javaformat
- In this iteration, checkstyles are only enabled for spring-ai-core
2024-10-24 16:43:59 -04:00
Christian Tzolov
12f2f9d0e0 Fix ChromaVectorStoreAutoConfigurationIT configuration 2024-10-24 11:38:32 +02:00
Sébastien Deleuze
f21b8a42b5 Refine Jackson ObjectMapper handling
ObjectMapper instantiation is costly, so unless its usage
is one-shot, it is better to create a reusable instance
for upcoming usage.

Also, before this commit, serialization of most Kotlin
classes was not supported due to the lack of proper
Jackson KotlinModule detection.

This commit:
 - Avoids per invocation ObjectMapper instantiation when
   relevant
 - Automatically detects and enables well-known Jackson
   modules including the Kotlin one
 - Removes org.springframework.ai.vectorstore.JsonUtils
   which looks not needed anymore

More optimizations are possible like reusing more
ObjectMapper instances, but this could introduce more breaking
changes so this commit intends to be a good first step.

Kotlin tests will be provided in a follow-up commit.

Additional changes:
 - Update ModelOptionsUtils to use JacksonUtils.instantiateAvailableModules()
 - Add missing license headers
 - Add missing author Javadoc comments
2024-10-24 09:20:47 +02:00
Christian Tzolov
c544d0c0a9 Add support for BiFunction class type resolution in TypeResolverHelper
- Adds special handling for BiFunction class types
- Adds test cases to verify BiFunction class type resolution
- Removes deprecated AbstractFunctionCallSupport class
- Cleans up unused imports in FunctionCallback

Resolves #1576
2024-10-23 15:29:15 +01:00
Christian Tzolov
c979238993 Adding nav entry for Azure Cosmos DB documentation
- Minor code sytle fixes.
2024-10-23 07:45:49 +02:00
Soby Chacko
c979d1c606 CosmosDB vector store auto configuration changes
- Configurable BatchingStrategy via auto configuraiton
- Minor code cleanup
2024-10-22 17:08:31 -04:00
Theo van Kraay
7b06fcf98b Add Azure CosmosDB vector store support
- Implement core vector store module for CosmosDB integration
- Add Spring Boot auto-configuration capabilities
- Integrate batch processing strategy for optimized operations
- Include comprehensive tests for core and auto-config modules
- Add reference docs for the CosmosDB vector store support
2024-10-22 15:50:16 -04:00