Commit Graph

1572 Commits

Author SHA1 Message Date
Mark Pollack
30a618d63d Module refactorings
* Created spring-ai-commons module that contains the document classes and Media
* Created spring-ai-document-ingestion containing ETL related classes
* Created spring-ai-chat-document-transformer module containing transformers that utilitze the ChatModel

Started to refactor package names for document ETL classes to have 'document' in their package name.
2025-01-08 14:40:04 -05:00
Mark Pollack
fc15c8ded4 refactor: Extract vector store and advisor functionality from spring-ai-core
Major Changes:
- Created new module spring-ai-vector-store from spring-ai-core functionality
- Split advisor functionality into three new modules:
  * advisor-memory: Memory-based chat advisors
  * advisor-rag: Retrieval Augmentation Generation advisors
  * advisor-vector-store: Vector store based advisors
2025-01-06 15:50:43 -05:00
Mark Pollack
bff28299a2 wip 2024-12-18 14:12:37 -05:00
Ilayaperumal Gopinathan
99a44fbab8 Fix builder methods not to use deprecated methods 2024-12-18 12:14:43 +00:00
Ilayaperumal Gopinathan
7eb201ea17 Suppress varargs warnings 2024-12-18 11:14:23 +00:00
Eddú Meléndez
67eee8a43b Enable tests on PRs
It only executes unit tests.

Checkstyle and Spring Java Format are executed.
2024-12-18 11:52:14 +01:00
Thomas Vitale
6ab7e20616 Support Ollama JSON Structured Output
Ollama has recently introduced native support for JSON structured output, as described in https://ollama.com/blog/structured-outputs.
This PR introduces support for it, both for directly passing a JSON schema and when using the Spring AI output conversion APIs.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-12-18 11:43:57 +01:00
Ilayaperumal Gopinathan
be9d6a10fa Fix WeaviateContainerConnectionDetailsFactoryIT
- Use the WeaviateVectorStore.MetadataField types for assertion
2024-12-18 07:39:12 +00:00
Alexandros Pappas
eccf33a6ec Refactor WatsonxAiChatOptions builder methods
- Refactor the builder methods to remove `with` as the prefix.
- Introduce new methods with updated naming conventions.
- Deprecate the existing `with*` methods to maintain backward compatibility.
- Update WatsonxAi documentation
2024-12-17 22:00:36 +00:00
Alexandros Pappas
1d38fd11fd Refactor AnthropicChatOptions builder methods
- Refactor the builder methods to remove `with` as the prefix.
- Introduce new methods with updated naming conventions.
- Deprecate the existing `with*` methods to maintain backward compatibility.
- Update AnthropicChatOptions builder documentation
2024-12-17 21:51:10 +00:00
Alexandros Pappas
de29df7c58 Refactor MistralAiChatOptions builder methods
- Refactor the builder methods to remove `with` as the prefix.
- Introduce new methods with updated naming conventions.
- Deprecate the existing `with*` methods to maintain backward compatibility.
- Update MistralAiChatOptions builder documentation
2024-12-17 21:48:10 +00:00
Soby Chacko
48bcbd1555 Add builder pattern to QdrantVectorStore
Introduces a builder pattern for configuring QdrantVectorStore instances to
provide a more flexible and type-safe way to create and configure vector stores.
This change:

- Makes configuration more intuitive through fluent builder methods
- Improves validation by enforcing required parameters at compile time
- Deprecates old constructors in favor of the builder pattern
- Adds comprehensive builder tests to ensure reliability
- Updates reference documentation with builder usage examples
- Maintains backward compatibility while providing a clear migration path

The builder pattern simplifies QdrantVectorStore configuration by providing
clear method names, proper validation, and better IDE support through method
chaining. This makes the API more user-friendly and helps prevent configuration
errors at compile time rather than runtime.
2024-12-17 16:44:08 -05:00
Alexandros Pappas
19e61bf71a Refactor ChatResponseMetadata Builder methods
- Refactor builder methods in `ChatResponseMetadata` to remove `with` prefixes and introduce new methods with updated naming conventions.
- Deprecate existing `with*` methods while maintaining backward compatibility.
- Ensure dependent files and tests are compatible with the updated `ChatResponseMetadata` class.
2024-12-17 21:28:19 +00:00
Alexandros Pappas
8c51f7a84c Refactor MoonshotChatOptions builder methods
- Refactor the builder methods to remove `with` as the prefix.
- Introduce new methods with updated naming conventions.
- Deprecate the existing `with*` methods to maintain backward compatibility.
- Update the `copy()` method to use the new builder methods.
- Update MoonshotChatOptions builder documentation
2024-12-17 21:10:24 +00:00
Soby Chacko
8edf1bea47 Add builder pattern to MariaDBVectorStore and refactor package name
Introduces a builder pattern for configuring MariaDBVectorStore instances and
improves the overall implementation. This change:

- Makes configuration more flexible and type-safe through builder methods
- Deprecates old constructors and builder in favor of the new builder pattern
- Adds comprehensive validation of configuration options
- Improves documentation with clear examples and better structure
- Updates all test classes to use the new builder pattern
- Adds comprehensive builder tests
- Updated reference documentation

The builder pattern provides a more maintainable and user-friendly way to
configure vector stores while ensuring configuration validity at compile time.
This aligns with the project's move towards using builder patterns across all
vector store implementations.
2024-12-17 15:56:45 -05:00
Soby Chacko
8877672846 Add builder pattern to TypesenseVectorStore and refactor package name
Introduces a builder pattern for configuring TypesenseVectorStore instances and
moves the implementation to the org.springframework.ai.vectorstore.typesense
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
- Enhances documentation with clear usage examples
- Adds dedicated builder test class for better test coverage
- Add builder tests
- update reference docs

The builder pattern simplifies TypesenseVectorStore configuration while ensuring
proper validation of all settings. The package move aligns with Spring AI's
architectural patterns and improves maintainability by grouping related classes
together.

review
2024-12-17 15:09:16 -05:00
Ilayaperumal Gopinathan
b25d6e8d2d Refactor FunctionCallingOptions Builder
- Deprecate existing FunctionCallingOptionsBuilder
  - Create FunctionCallingOptions.Builder which extends ChatOptions.Builder
  - Create DefaultFunctionCallingOptions which extends DefaultChatOptions and implements FunctionCallingOptions to serve the default FunctionCalling options
  - Create DefaultFunctionCallingOptionsBuilder to build the default functioncalling options
  - Update the usage of functioncalling options builder to use the newly added builder including the tests

Improve extensibility of DefaultChatOptionsBuilder

 - Enable DefaultChatOptionsBuilder to accommodate any other sub types
   - Introduce generics to support sub types that extend DefaultChatOptionsBuilder
   - Update builder methods to return the sub type

 - Make FunctionCallingOptions' builder()'s return type to accommodate sub types which can extend FunctionCallingOptions.Builder
2024-12-17 11:58:50 -05:00
Ilayaperumal Gopinathan
627fb79e5e Refactor ImageOptions builder method
- Deprecate the builder method with the prefix 'with' and add new methods
2024-12-17 11:55:38 -05:00
Ilayaperumal Gopinathan
18bc0cff25 Refactor QianFan model option builder methods
- Deprecate the builder methods with the prefix `with` and add the new methods
 - Update docs and references
2024-12-17 11:51:59 -05:00
Ilayaperumal Gopinathan
071b897951 Refactor Zhipu AI options builder methods
- Deprecate builder methods with the prefix `with`
 - Update docs and references
2024-12-17 11:46:27 -05:00
Ilayaperumal Gopinathan
3e82e3117f Refactor Vertex AI embedding/Gemini options builder methods
- Deprecate the builder methods with the prefix `with`
 - Update references and docs
2024-12-17 11:41:36 -05:00
Ilayaperumal Gopinathan
9748820727 Refactor Stability AI Image options builder methods
- Deprecate builder methods with the prefix `with`
 - Update docs and references
2024-12-17 11:25:01 -05:00
Ilayaperumal Gopinathan
18eb4c3c61 Refactor PostgresML embedding options builder
- Deprecate the builder methods with the prefix `with`
 - Update the docs and references
2024-12-17 11:20:47 -05:00
Ilayaperumal Gopinathan
95c32f05a3 Refactor OCI Gen AI builder methods
- Deprecate the builder methods with the prefix `with`
   - Fix OCI cohere chat model options and OCI Embedding model options
 - Update references and docs
2024-12-17 11:17:24 -05:00
Ilayaperumal Gopinathan
429bd2af35 Refactor Advisor builder methods
- Deprecate the builder methods with the prefix `with`
 - Update references and docs
2024-12-17 11:13:24 -05:00
Ilayaperumal Gopinathan
da45244d99 Refactor Azure model options builder methods
- Deprecate builder methods with the prefix `with` and add them without the prefix
 - Update references and docs
2024-12-17 09:26:24 -05:00
Ilayaperumal Gopinathan
93a7ba4c84 Refactor Minimax model builder methods
- Refactor minimax chat and embedded options builder methods to remove the prefix `with`
 - Update references and docs
2024-12-17 09:18:18 -05:00
Ilayaperumal Gopinathan
174a258276 Refactor builder methods of Moderation package
- Update Moderation, Generation, Categories, CategoryScores' builder method
   - deprecate the existing builder methods with the prefix `with` and replace them without the prefix
2024-12-17 09:15:48 -05:00
Ilayaperumal Gopinathan
65e7a1ddd9 Refactor Spring AI Bedrock options
- Refactor the options builder methods to remove `with` as the suffix
   - Update all the models under spring-ai-bedrock

 - Deprecate the existing methods
 - Update references and docs
2024-12-17 09:11:16 -05:00
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