Commit Graph

580 Commits

Author SHA1 Message Date
Soby Chacko
2d3bdcddbd Add builder pattern to MongoDBAtlasVectorStore and refactor package name
The MongoDBAtlasVectorStore implementation has been enhanced with a builder
pattern to provide a more flexible and type-safe way to configure the vector
store. This change improves the developer experience by making the API more
intuitive and less error-prone.

The old constructors and configuration classes have been deprecated in favor
of the builder pattern. This aligns with Spring's best practices for
configuration APIs.

Additionally, the package has been refactored to
org.springframework.ai.vectorstore.mongodb.atlas to avoid having
multiple vector store modules share the same package name.

Documentation has been updated to reflect these changes and provide
examples of using the new builder pattern.review
2024-12-14 17:19:25 -05:00
Soby Chacko
fc1f92d11c Add builder pattern and refactor Elasticsearch store package
The changes introduce a fluent builder pattern for ElasticsearchVectorStore
configuration, making it easier to create and customize instances with
optional parameters. All Elasticsearch-related classes are moved to a
dedicated elasticsearch package for better organization.

Key changes:

* Add ElasticsearchVectorStore.builder() with comprehensive options
* Move classes to org.springframework.ai.vectorstore.elasticsearch package
* Deprecate old constructors in favor of builder pattern
* Add support for configurable batching strategies
* Enhance documentation with usage examples and best practices
2024-12-14 16:21:14 -05:00
Soby Chacko
257b963da9 PgVectorStore package rename and builder support
- Move PgVectorStore and related classes to org.springframework.ai.pg.vectorstore package
 - Update builder pattern to use more idiomatic method names (e.g. withSchemaName -> schemaName)
 - Deprecate existing constructors and old Builder class in favor of new static builder() method
 - Update tests to reflect the new builder style usage
 - Update docs
2024-12-14 15:24:14 -05:00
Christian Tzolov
9e18652bb8 docs: Update mcp diagram 2024-12-13 15:12:28 +01:00
Mark Pollack
5b11501cbe Update usage of Document::getContent to getText 2024-12-12 14:43:51 -05:00
Christian Tzolov
dda86808b7 docs: improve mcp docs 2024-12-12 11:24:44 +01:00
Christian Tzolov
7b9da084dd Add a doc page about MCP 2024-12-12 11:12:06 +01:00
Christian Tzolov
a474b1294e docs(bedrock-converse): add list of supported models to converse api docs
The commit adds a note to the bedrock-converse.adoc document that lists the supported models for the Converse API, including:
Amazon Titan, Amazon Nova, AI21 Labs, Anthropic Claude, Cohere Command, Meta Llama, Mistral AI
2024-12-10 11:40:53 +01:00
Christian Tzolov
9a5d61cc05 Bedrock Converse: Add multimodal support for documents, images and videos
- Add BedrockMediaFormat class to handle media format conversions for documents, images and videos
- Enhance Media class with builder pattern and comprehensive format constants
- Refactor BedrockProxyChatModel to support multimodal content handling
- Add integration tests for PDF, image and video processing
- Add unit tests for Media and BedrockMediaFormat classes
- Upgrade AWS SDK version from 2.26.7 to 2.29.29
- Remove redundant aws.sdk.version property in favor of awssdk.version

Documentation updates for Bedrock Converse API

- Added multimodal support documentation (images, video, documents)
- Added deprecation notices for existing Bedrock model implementations
- Updated feature comparison table
- Added warning notes about transitioning to Converse API
2024-12-09 22:54:53 -05:00
Christian Tzolov
c4ca5826f7 feat(ollama): Add streaming support for function calls and improve OllamaApi
- Implement streaming tool call support in OllamaApi and OllamaChatModel
- Add OllamaApiHelper to manage merging of streaming chat response chunks
- Remove @Disabled annotations for streaming function call tests
- Update documentation to reflect new streaming function call capabilities
- Add a new default constructor for ChatResponse
- Update Ollama chat documentation to clarify streaming support requirements
- Deprecated withContent(), withImages(), and withToolCalls() methods
- Replaced with content(), images(), and toolCalls() methods

Add token and duration aggregation for Ollama chat responses

- Modify OllamaChatModel to support accumulating tokens and durations across multiple responses
- Update ChatResponse metadata generation to aggregate usage and duration metrics
- Add tests to verify metadata aggregation behavior

Refactor Ollama duration fields and tests

- Replace Duration fields in OllamaApi.ChatResponse with Long to represent durations in nanoseconds, ensuring precision and compatibility.
- Update methods to convert Long nanoseconds to Duration objects (getTotalDuration, getLoadDuration, getEvalDuration, getPromptEvalDuration).
- Adjust merge logic in OllamaApiHelper to sum Long values for duration fields.
- Modify test cases in OllamaChatModelTests to align with Long duration representation and Duration.ofNanos conversions.
- Add new test class OllamaDurationFieldsTests to validate JSON deserialization and Duration conversion for duration fields.

Resolves #1847
Related to #1800
Resolves #1796
Related to #1307

test: Update OllamaWithOpenAiChatModelIT integration tests

- Remove @Disabled annotation for streamFunctionCallTest
- Add inputType for function callback in stream function call test
2024-12-08 21:28:10 +00:00
wstever
81a63910ac Update openai-embeddings.adoc
update azure openai to openai
2024-12-01 07:27:29 +01:00
Christian Tzolov
6792707d07 docs: update model/concepts diagram 2024-11-30 14:12:24 +01:00
Christian Tzolov
cdffc72c14 feat(openai) - Support for audio output in OpenAI chat model
- Introduced new options for audio output modalities in ChatCompletionRequest
- Added AudioParameters configuration for voice and audio format selection
- Enhanced OpenAiChatModel to handle audio generation and embedding
- Updated AssistantMessage and Media classes to support audio media
- Added integration tests for audio output functionality
- Implemented support for text and audio multi-modal responses
- Updated Spring AI's chat model comparison table to clarify OpenAI's input/output modalities
- Added new configuration properties for audio output:
  * spring.ai.openai.chat.options.output-modalities
  * spring.ai.openai.chat.options.output-audio
- Extended documentation to explain audio output generation with the gpt-4o-audio-preview model
- Updated Spring Boot configuration metadata to support new audio-related properties
- Included auto-configuration integration test for chat model with audio response generation

Resolves #1841
2024-11-28 20:27:02 +00:00
Christian Tzolov
6a195ee9fe refactor(core): extract common function callback builder functionality
Extracts shared function callback builder functionality into DefaultCommonCallbackInvokingSpec
base class, reducing code duplication across builder implementations.
Makes FunctionInvokingSpec and MethodInvokingSpec extend CommonCallbackInvokingSpec for better
code organization. Also fixes function/description builder order in Anthropic tests.

- Introduced a common base class for function callback builders to centralize shared logic
- Standardized the order of method chaining for function and description in multiple AI model test classes
- Refactored test cases across various AI model integrations
- Corrected builder method order from .description().function() to .function().description()
  and .description().method() to .method().description()
- Updated multiple test files to consistently use .function() before .description()
- Updated documentation examples to reflect new builder method order
- Modified DefaultFunctionCallbackResolver to maintain new builder method order
- Updated DefaultChatClient and ChatClient test classes to reflect new builder pattern
- Simplified callback specification by removing parent spec reference
- Removed cascading getter logic for description, schema type, and other properties
- Minor adjustments to function callback builder and invoking specs
2024-11-28 19:28:08 +00:00
Alexandros Pappas
dcc8d5b620 feat: Add Perplexity AI integration and documentation updates
- Introduced `PerplexityWithOpenAiChatModelIT` integration test for Perplexity AI with OpenAI Chat Model.
  - Includes various test cases for role-based prompts, streaming responses, token usage validation, and output converters.
  - Added tests for function calls and metadata validation.
- Updated Antora navigation (`nav.adoc`) to include Perplexity AI documentation link.
- Enhanced chat model comparison documentation to highlight Perplexity AI integration.
- Added a dedicated `perplexity-chat.adoc` page under `spring-ai-docs` to provide detailed documentation for integrating Perplexity AI.
  - Covers API prerequisites, auto-configuration, and runtime options.
  - Explains configuration properties such as `spring.ai.openai.base-url`, `spring.ai.openai.chat.model`, and `spring.ai.openai.chat.options.*`.
  - Provides examples for environment variable setup and runtime overrides.
  - Highlights limitations like lack of multimodal support and explicit function calling.
  - Includes a sample Spring Boot controller demonstrating integration usage.
  - Links to Perplexity documentation for further reference.
2024-11-28 19:11:27 +01:00
diego
0b00e6f446 feat(vector-store) Add MariaDB Vector Store support to Spring AI
- Updated `org.springframework.boot.autoconfigure.AutoConfiguration.imports` to include MariaDB vector store auto-configuration
- Created MariaDB Vector Store autoconfiguration integration tests (`MariaDbStoreAutoConfigurationIT`)
- Added MariaDB store properties configuration and tests (`MariaDbStorePropertiesTests`)
- Introduced new Maven modules:
  - `spring-ai-mariadb-store`: Core MariaDB vector store implementation
  - `spring-ai-starter-mariadb-store`: Spring Boot starter for MariaDB vector store
- Added `MariaDBFilterExpressionConverter` to support JSON-based metadata filtering in MariaDB
- Implemented filter expression conversion for MariaDB vector store queries
- Added README.md with documentation link for MariaDB Vector Store
- Updated project dependencies to include MariaDB JDBC driver and test containers
- Configured integration testing with TestContainers for MariaDB
- Added observability support for MariaDB vector store operations
2024-11-28 17:25:32 +01:00
Thomas Vitale
33f431e4a7 feat(openai) - Support audio input and output modality
- Added support for audio input and output in OpenAI Chat Completion API
- Introduced new audio-related parameters, enums, and record types
- Updated ChatCompletionMessage, ChatCompletionChunk, and related classes
- Added new AudioParameters, AudioOutput, and InputAudio record types
- Implemented method to handle audio media content conversion
- Included new model enum for GPT-4o audio preview
- Extended existing API classes to accommodate audio modalities
- Modified usage tracking and metadata classes to handle audio-specific token details
- Improved ModelOptionsUtils with additional JSON utility methods

Tests:
- Updated test classes to validate audio input and output functionality
- Added integration tests for multimodal audio input with streaming and non-streaming methods
- Created parameterized tests for audio-enabled models
- Enhanced OpenAI API integration tests to cover audio-related scenarios

Docs:
- Updated documentation in spring-ai-docs to explain audio multimodality support

Resolves #1560
2024-11-27 12:46:43 +01:00
Jemin Huh
7b3f424ae1 Fix correct external link formatting for Ollama documentation
Signed-off-by: Jemin Huh <hjm1980@gmail.com>
2024-11-26 12:07:45 +01:00
Christian Tzolov
e543cd082d Update AnthropicChatModel and Spring AI Documentation for Multimodal Support
- Enhance AnthropicChatModel to support PDF and document content types
- Introduce getContentBlockTypeByMedia method for flexible media type handling
- Update ContentBlock handling to dynamically determine content type for media
- Add multimodal PDF support test case for Claude 3.5 Sonnet
- Update documentation to reflect PDF and multimodal capabilities
- Modify comparison chart to show PDF support for Anthropic Claude

Fixese #1819

review
2024-11-25 23:54:57 -05:00
Christian Tzolov
979de19162 docs(vertex-ai-gemini): Add Gemini PDF support docs and add IT
- Add test case for PDF document summarization using Gemini multimodal capabilities
- Update documentation to reflect PDF support in model comparison table
- Add PDF format to multimodal capabilities documentation
2024-11-25 14:09:54 +01:00
Christian Tzolov
87ff101946 docs: move Bedrock Converse to chat folder & add to comparison table
- Move bedrock-converse.adoc from api/ to api/chat/ directory
- Add Bedrock Converse to chat models comparison table
- Fix table entry formatting for OCI GenAI/Cohere width values

The move aligns with the documentation structure where chat-related content
is organized under the api/chat/ directory.
2024-11-25 12:41:17 +01:00
Christian Tzolov
64c4567eb1 docs: reorganize and enhance FunctionCallback documentation
* Remove redundant section headers
* Improve builder pattern documentation with hierarchical structure overview
* Add cross-references between related sections
* Restructure function and method invoking sections for better organization
* Adjust heading levels for better document hierarchy
* Move schema generation and common pitfalls under appropriate sections
2024-11-24 18:10:16 +01:00
Christian Tzolov
b3bb541cc9 docs: improve documentation for function callback and tool context
- Add cross-references to tool context documentation section
- Enhance BiFunction section title and description
- Improve readability and consistency of function callback documentation
2024-11-24 17:26:36 +01:00
Christian Tzolov
eaa61cd231 docs: Imporove Function Calling docs 2024-11-24 16:38:43 +01:00
Christian Tzolov
c1f2ec65d3 doc: Fix the Ollama hugging face support documentation 2024-11-24 15:00:20 +01:00
Virle
357efd0b0b Update function-callback.adoc (#1797)
turn onn => turn on
2024-11-22 11:53:45 +00:00
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
Soby Chacko
1abfd9ab96 Add truncation support for Cohere embeddings
Fixes: #1753

https://github.com/spring-projects/spring-ai/issues/1753

- Add character-based truncation (max 2048 chars) for Cohere embedding requests
- Support both START and END truncation strategies
- Add unit tests verifying truncation behavior for both strategies

Truncation is applied before sending requests to Bedrock API to avoid
ValidationException when text exceeds maximum length. The END strategy
(default) keeps the first 2048 characters while START keeps the last
2048 characters.
2024-11-20 10:06:38 -05:00
Christian Tzolov
379f21235a Update chroma.adoc 2024-11-20 01:13:02 +01: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
heqiang
d2e9e55d25 Fix TokenCountBatchingStrategy example. (#1702) 2024-11-19 13:10:21 -05:00
Christian Tzolov
c529c839ee Update chroma.adoc 2024-11-19 17:16:06 +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
jitokim
d8583271c7 fix callback merging in AzureOpenAiChatModel constructor
and minor fixes

Signed-off-by: jitokim <pigberger70@gmail.com>
2024-11-19 09:12:51 +01: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
Emmanuel Ferdman
f9a9c02e2b Update Message.java reference
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
2024-11-18 11:20:05 +01:00
Ilayaperumal Gopinathan
4e3955eee9 Fix typo 2024-11-18 10:14:20 +00:00
coderamittad
24096b04bf Update getting-started.adoc 2024-11-18 07:49:53 +05:30
Christian Tzolov
bc24b4c45d docs: Clarify function calling concepts and usage patterns
Improves function calling documentation with clearer organization and examples:

- Reorganizes content into server-side and client-side registration sections
- Adds detailed examples for both function-invoking and method-invoking approaches
- Enhances tool context documentation with diagrams and usage examples
- Updates function-calling diagrams to reflect current implementation
2024-11-17 17:23:21 +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
Gareth Evans
ea1871041c docs: document how to programatically configure vertex embeddings to use a service account 2024-11-15 17:49:10 +01:00
Gareth Evans
01fa511339 docs: correct code in vertex chat functions doc 2024-11-15 13:22:23 +00:00
Ilayaperumal Gopinathan
b4e0a4598e Update documentation for Milvus vector store
- Add custom field name properties
2024-11-13 12:04:34 +00:00
Christian Tzolov
5f6b892eda Add function calling support to invoke methods with dynamic arguments and return values
This change enables more flexible integration between Spring AI and LLM function
calling capabilities while maintaining type safety and ease of use.

- Add new MethodFunctionCallback class to support method invocation via reflection
 - Supports both static and non-static method calls
 - Handles multiple parameter types including primitives, objects, collections
 - Supports empty parameters and empty response
 - Auto-generates JSON schema from method parameters
 - Special handling for ToolContext parameters
 - Builder pattern for easy configuration

- Add comprehensive unit tests for MethodFunctionCallback
- Add integration tests for MethodFunctionCallback with both Anthropic and OpenAI clients
- Add jackson-module-jsonSchema dependency
- Modify FunctionCallback to check for empty tool context

Testing coverage includes:
- Static method invocation scenarios
- Non-static method calls with various parameter types
- Void return type methods
- Complex parameter types (enums, records, lists)
- Tool context handling
- Error cases and validation

Add MethodFunctionCallback reference docs
2024-11-10 22:58:40 -05:00
Christian Tzolov
c24ef4e79a docs: enhance Bedrock Converse API documentation
- Add migration note recommending transition from InvokeModel to Converse API
- Update model configuration to remove default model ID
- Add AWS session token configuration for temporary credentials
- Improve documentation links and descriptions
2024-11-10 15:42:03 +01: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
79266be970 GH-1335: Add JSON schema property order support
Fixes: #1335

https://github.com/spring-projects/spring-ai/issues/1335

Add support for maintaining JSON property order in generated schemas using
@JsonPropertyOrder. Users can now control the order of properties in their
JSON schemas by annotating their classes/records with @JsonPropertyOrder.

- Add JacksonOption.RESPECT_JSONPROPERTY_ORDER to BeanOutputConverter
- Add test to verify schema property ordering
- Update documentation with property ordering example
2024-11-08 13:41:48 +00:00