Commit Graph

1543 Commits

Author SHA1 Message Date
Ilayaperumal Gopinathan
58efee6d90 Refactor OpenAI chat options
- Deprecate existing OpenAI chat options
 - Add the options' methods by removing the prefix "with"
   - Update the following options
    - OpenAI chat options
    - OpenAI image options
    - OpenAI moderation options
    - OpenAI embedding options
    - OpenAI audiospeech options
    - OpenAI audio transcription options
 - Update referecens and docs
 - Deprecate 'with' methods in builders
2024-12-17 09:06:06 -05:00
Tyler Russell
c14618fe9a feat(gemini) Support Safety Settings for VertexAiGeminiChatModel
feat(gemini) not null checks on safetySettings

feat(gemini) check safety settings not empty instead of not null

feat(gemini) Add VertexAiGeminiSafetySetting wrapper class

feat(gemini) Update documentation with new property

feat(gemini) Update equals, hashCode, and toString
2024-12-17 13:05:32 +01:00
Ilayaperumal Gopinathan
7bbd3ef593 Fix Azure OpenAI chat model function calling token usage
- Fix Azure OpenAI chat model's functioncalling to report accumulated token usage
   - Fix both call() and stream() operations
     - For streaming operation, use buffering to store the usage from the last response when stream option include usage is enabled
   - Add tests
2024-12-17 13:00:11 +01:00
Ilayaperumal Gopinathan
cadea8b730 Fix Anthropic chat model functioncalling token usage
- Accumulate the token usage when functioncalling is used
   - Fix both call() as well as stream() operations

 - Add/update tests
2024-12-17 12:56:53 +01:00
Ilayaperumal Gopinathan
81dfd3b6b5 Fix Mistral AI Chat model function call usage calculation
- Fix the chat model's call() to calculate the cumulative usage
   - Use an explicit internalCall to pass the previous chat response so that accumulation can be done

 - Fix the chat model's stream() to calculate the cumulative usage
   - Fix MistralAi API to include usgae in ChatCompletionChunk
   - Use internalStream() to accumulate the usage

Add/update tests
2024-12-17 12:27:51 +01:00
chenwei
187360d132 Fix OpenAI API Tool Choice type
Resolves: https://github.com/spring-projects/spring-ai/issues/1899
2024-12-17 12:11:51 +01:00
Soby Chacko
d77c950ea6 Add builder pattern to WeaviateVectorStore and refactor package name
Introduces a builder pattern for configuring WeaviateVectorStore instances and
moves the implementation to the org.springframework.ai.vectorstore.weaviate
package. This change:

- Makes configuration more flexible and type-safe through builder methods
- Improves code organization by moving to a dedicated vector store package
- Deprecates old constructors in favor of the builder pattern
- Adds builder tests
- Enables better IDE support through method chaining
2024-12-16 16:26:59 -05:00
Soby Chacko
25123a5364 Add builder pattern to CassandraVectorStore and refactor package name
Introduces a builder pattern for configuring CassandraVectorStore instances and
moves the implementation to the org.springframework.ai.vectorstore.cassandra
package. This change:

- Makes configuration more flexible and type-safe through builder methods
- Improves code organization by moving to a dedicated vector store package
- Deprecates old constructors in favor of the builder pattern
- Adds comprehensive validation of configuration options
- Enables better IDE support through method chaining
- The builder pattern provides a more maintainable and user-friendly way to
  configure vector stores while ensuring configuration validity at compile time.
2024-12-16 15:38:20 -05:00
Soby Chacko
d3d34c9215 Add builder pattern to OpenSearchVectorStore and refactor package name
Add builder pattern to OpenSearchVectorStore

Introduces a builder pattern for OpenSearchVectorStore configuration and
refactors the package structure to org.springframework.ai.vectorstore.opensearch
for better organization and consistency with other vector stores.

The builder pattern improves usability by:

* Providing a fluent API for configuring store instances
* Making configuration options more discoverable through method names
* Enabling better validation of configuration parameters
* Supporting optional parameters with sensible defaults
* The package refactoring aligns with the project's standard package naming
conventions and improves code organization. All constructors are deprecated
in favor of the new builder pattern to guide users toward the preferred
configuration approach.
2024-12-15 13:09:15 -05:00
Soby Chacko
f69d879ec9 Add builder pattern to RedisVectorStore and refactor package name
Refactors RedisVectorStore to use the builder pattern for improved
configuration and usability. The changes include:

* Move classes to org.springframework.ai.vectorstore.redis package
* Add RedisBuilder with comprehensive configuration options
* Deprecate RedisVectorStoreConfig in favor of builder pattern
* Enhance documentation with detailed usage examples
* Improve error handling and parameter validation

This change makes RedisVectorStore configuration more intuitive and
consistent with other vector stores in the project.
2024-12-14 18:40:41 -05:00
Soby Chacko
cde8f7446c Add builder pattern and refactor Neo4jVectorStore
The Neo4j vector store implementation has been enhanced with a builder
pattern to be more intuitive than using ctors and follows spring ai builder
conventions.  Current constructors have been deprecated to maintain
backward compatibility for one releaes cycle.

The change includes:

* Move classes to dedicated neo4j package for better organization
* Add comprehensive builder pattern implementation with validation
* Improve documentation with detailed usage examples
* Deprecate but maintain old configuration approach for compatibility
* Update integration tests to demonstrate new builder pattern
* Enhance code readability and maintainability
2024-12-14 17:53:15 -05:00
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
Mark Pollack
03a9379bb7 Refactor PgVector to package org.springframework.ai.vectorstore.pgvector 2024-12-14 16:45:06 -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
Mark Pollack
677a18e3d4 Update PgVector javadoc 2024-12-14 15:33:45 -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
Soby Chacko
218c9677f4 Add builder pattern for MilvusVectorStore
Introduces a fluent builder API to improve configuration readability and
type safety when creating MilvusVectorStore instances. This replaces the
existing configuration object approach which was less intuitive and harder
to maintain.

The builder pattern provides better encapsulation of configuration logic
and validation, while maintaining backward compatibility through a
deprecated config class. This change makes the codebase more maintainable
and the API more discoverable for users.

Key changes:
- Replace configuration object with fluent builder pattern
- Move Milvus-related classes to dedicated milvus package
- Deprecate MilvusVectorStoreConfig in favor of builder
- Update constructor to use builder internally
- Maintain backward compatibility with deprecated config
- Add comprehensive builder methods with validation
2024-12-12 15:19:13 -05:00
Mark Pollack
5b11501cbe Update usage of Document::getContent to getText 2024-12-12 14:43:51 -05:00
Ilayaperumal Gopinathan
f252b2417a Refactor ChatOptions Builder
- Deprecate existing ChatOptionsBuilder and its inner class DefaultChatOptions
- Create a new builder interface ChatOptions.Builder for building the Chat options
- Create an explicit DefaultChatOptions
- Create DefaultChatOptionBuilder which can create DefaultChatOptions
- Add javadoc for the deprecated Builder

Resolves #1875
2024-12-12 10:06:16 -05:00
Mark Pollack
85580f81fa Fix RAG tests after Document refactoring 2024-12-12 09:22:27 -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
Gareth Evans
e7bd8d5da1 feat: allow stream usage to be set for azure openai requests 2024-12-11 21:32:45 +00:00
Ilayaperumal Gopinathan
863cf38efd Add null check and javadoc to UsageUtils
- Add null check to UsageUtils#getCumulativeUsage() arguments
  - Add javadoc the methods
2024-12-11 20:29:59 +00:00
Ilayaperumal Gopinathan
f7e8e7f388 Use RequiresAwsCredentials in AWS credentials based tests
- Update Spring AI Bedrock tests to use the @RequiresAwsCredentials to check the AWS keys
2024-12-11 18:21:14 +00:00
Soby Chacko
e2825c9877 Refactor ChromaVectorStore builder API
The commit restructures the ChromaVectorStore builder pattern to use a no-args constructor
with fluent API for setting the ChromaApi.

This change:

 - Makes builder creation consistent with other vector stores
 - Moves ChromaApi validation to the doValidate method
 - Improves builder API ergonomics

The change requires updating all builder usages to use the new .chromaApi() method instead
of passing it in the constructor.
2024-12-10 18:20:23 -05:00
Christian Tzolov
ad87c122d9 Fix duplicaiton 2024-12-10 15:39:59 +01:00
Ilayaperumal Gopinathan
37cf20dfe4 Fix OpenAI ChatResponse usage calculation when toolcalling is used
- Fix OpenAI ChatModel's call() operation

   - When toolcalling is used, calculate cumulative usage from the preceding ChatResponses

 - Fix OpenAI ChatModel's stream() operation

   - Make sure that cumulative usage is calculated from the ChatResponse which has a valid usage
     - Use overlapping buffer to check and store the usage from the response that holds the usage.

 - Add tests for both call() and stream()
2024-12-10 15:38:18 +01:00
Christian Tzolov
ebc91680f8 Improve OllamaWithOpenAiChatModelIT stability 2024-12-10 15:14:35 +01:00
Christian Tzolov
16a9d891aa tests Improve stability for PerplexityWithOpenAiChatModelIT 2024-12-10 14:29:50 +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
Mark Pollack
dfbc394f83 Make Document support single text or media content
The Document class previously allowed multiple media entries while also having a
text field, leading to ambiguity in content handling. This change enforces a
clear separation between text and media documents to prevent content type
confusion and simplify document processing.

A Document now must contain either text content or a single media entry, but
never both. This aligns with the class's primary use in ETL pipelines where
clear content type boundaries are essential for proper embedding generation and
vector database storage.

Additional architectural changes:
- Document now implements a cleaner API by removing deprecated methods
- Removed MediaContent interface implementation from Document class
- Document.getMedia() now returns a single Media object instead of Collection
- Removed EMPTY_TEXT constant in favor of proper null handling
- Constructor signatures simplified and streamlined
- Builder pattern improved to enforce single content type constraint

The breaking changes include:
- Media is now a single entry instead of a collection
- Content field renamed to text for clarity
- Removed support for mixed content types
- Simplified builder API to prevent ambiguous construction

Prefer using text-related methods over deprecated content methods to
better reflect the actual content type being handled and improve API clarity.
2024-12-09 23:25:38 -05: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
Mark Pollack
dba3eee7a7 Remove running Ollama in CI tests 2024-12-09 10:41:56 -05:00
Mark Pollack
778752a14d Disable brittle IT that pulls models from hugging face for Ollama 2024-12-09 10:09:30 -05:00
Mark Pollack
87d5112fe0 Disable brittle IT that pulls models from hugging face for Ollama 2024-12-09 09:37:43 -05:00
Mark Pollack
aae4d24f09 Use ci-fast-integration-tests for CI build 2024-12-09 09:12:16 -05:00
Eddú Meléndez
070ba3f787 Polish postgresml autoconfiguration IT 2024-12-09 09:25:19 +00:00
Eddú Meléndez
d084916ac3 Polish PostgresMlEmbeddingModelIT 2024-12-09 09:25:19 +00:00
Christian Tzolov
9f775ab2c2 feat(ollama): upgrade to 0.5.1 and improve code quality
- Upgrade Ollama version used for IT from 0.3.14 to 0.5.1
- Fix string comparison pattern in OllamaModelManager
- Re-enable stream function calling test
- Improve multimodal test assertions
2024-12-09 10:08:07 +01:00
Ilayaperumal Gopinathan
a2d9ddd27a Disable docker-compose and testcontainers tests for the CI/CD build
- These modules run their tests at the https://github.com/spring-projects/spring-ai-integration-tests
2024-12-09 07:56:28 +00:00
Mark Pollack
51261e46f8 Add Ollama service to CI job 2024-12-08 23:17:46 -05:00
Mark Pollack
b9e4123b5d Temporarily disable Ollama streaming function calling tests 2024-12-08 22:15:49 -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
Soby Chacko
6307377ef5 Fix null issues with custom observation convention
- Relax null constraints for custom observation convention in AbstractVectorStoreBuilder
2024-12-06 18:13:58 -05:00
Ilayaperumal Gopinathan
a8dda0a8f1 fix: Chroma VectorStore auto configuration
- Add null check for the Chroma vector store ObservationConvention
   - Since the builder enforces non null check, the ChromaVectorStore builder in its autoconfiguration will only set the ObservationConvention if it is not null.
2024-12-06 18:49:01 +00:00
Ilayaperumal Gopinathan
2ef4559827 Fix OpenSearch vector store's doAdd(List<Document> documents)
- Since Document's reference to its embedding is deprecated, store the embedding into OpenSearch vector store by creating an explicit OpenSearch Document type which has embedding associated with it
2024-12-06 18:08:50 +00:00
Ilayaperumal Gopinathan
3e9256fc00 Fix MariaDBVectorStore Document embedding
- Create an explicit MariaDBDocument to store the embeddings of its content
    - This is because the Spring AI Document no longer holds reference to its embeddings
 - Address the test case which checks just the MariaDB documents storing without their embeddings
 - Re-enable the MariDB ITs
2024-12-06 07:43:48 +00:00
Mark Pollack
957a2ea5ee Temporarily disable MariaDBStoreObservationIT 2024-12-05 23:23:45 -05:00