Commit Graph

1946 Commits

Author SHA1 Message Date
Soby Chacko
1a6e79cbb9 Enhance vector stores with consistent APIs and null safety
- Replace Document.getContent() with getText() across all vector store implementations
- Fix incorrect package declarations in package-info.java files
- Make builder constructors private and implement proper builder patterns
- Add @Nullable annotations for better null safety
- Simplify PineconeVectorStore builder API by requiring essential parameters in factory method
- Make static Map fields final
- Clean up code and improve JavaDoc documentation

The changes focus on making the vector store APIs more consistent,
type-safe, and maintainable while following best practices for
builder patterns and null safety.
2024-12-20 12:19:12 -05:00
Soby Chacko
ee8bf37359 Require essential dependencies in vector store builder constructors
This commit refactors the builder pattern implementation across all VectorStore
implementations to make the EmbeddingModel a required constructor parameter
rather than an optional builder method. Key changes include:

- Move embeddingModel from being a builder method to a required constructor parameter
- Make embeddingModel final in AbstractVectorStoreBuilder
- Remove redundant validate() methods since EmbeddingModel validation now happens
  in constructor
- Update all VectorStore builder instantiations to pass EmbeddingModel in builder
  creation
- Add @Nullable annotations to appropriate methods in VectorStore interface

This change improves the API design by:
1. Enforcing that EmbeddingModel is provided at builder creation time
2. Removing the possibility of forgotten EmbeddingModel configuration
3. Simplifying the builder implementation by moving validation to construction
4. Making the dependency on EmbeddingModel more explicit in the API

Breaking Changes:
- VectorStore builders must now be created with an EmbeddingModel parameter
- The embeddingModel() builder method has been removed from all implementations
2024-12-20 12:15:58 -05:00
Christian Tzolov
c5bf644039 fix(mistral) Fix the PaymentStatusFunctionCallingIT configuraiton
Resolves #1853
2024-12-20 15:09:15 +01:00
Thomas Vitale
f2820cd8af Mistral: Support Vision Modality
Introduce multimodality support for Mistral AI, which currently supports text and vision modalities.
Added integration tests and documentation for the new capability.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-12-20 14:41:01 +01:00
Mark Pollack
2e5ee4316f Ignore embedding field for Document deserialization
- VectorStore implementations may still be returning the embedding values and mapping onto
  Document.class with Jackson

This change ignores that field, but vector store implementations should change to not return
the embedding data that is no longer stored in Document
2024-12-19 15:40:09 -05:00
Mark Pollack
f92a3f0fcb Add support for general LLMs in FactCheckingEvaluator
The FactCheckingEvaluator was initially designed for the Bespoke Minicheck
model which doesn't require explicit instructions. This change adds support
for general-purpose LLMs like Claude and GPT-4 that need clear evaluation
instructions in their prompts.

Key changes:
- Introduce separate prompts for Bespoke and general LLMs
- Add factory method for Bespoke Minicheck configuration
- Make evaluation prompt configurable via constructor

This maintains backward compatibility while enabling the evaluator to work
effectively with any LLM implementation.
2024-12-19 15:14:18 -05:00
Dennys Fredericci
95eb9fd6a3 Fix OpenAI image dimension handling
The OpenAiImageOptions class previously had inconsistent behavior when
setting width and height properties. This change ensures that the size
property is only computed when both dimensions are available, preventing
invalid states in the API requests.

Key changes:
- Update setWidth/setHeight to only set size when both are non-null
- Add test cases to verify null size when dimensions are incomplete
- Improve code organization with proper import conventions

This change aligns with OpenAI's API requirements for image generation
where both dimensions must be specified for valid requests.
2024-12-19 15:03:58 -05:00
Ilayaperumal Gopinathan
0d122bb007 Remove embedding from Document
- This PR removes the reference of `embedding` from the `Document` object.
   - The Document is designed to contain the content and its metadata but not the embedding representation of its content. This provides clear separation of concern.
   - Prior to this change, all the vector stores are updated by not depending on the embedding from Document. Instead, use the embedding values returned by the Embedding Models directly: https://github.com/spring-projects/spring-ai/issues/1826

Resolves #1781
2024-12-19 14:38:35 -05:00
Ilayaperumal Gopinathan
bfc0b8285e Fix DefaultFunctionCallingOptionsBuilder inheritance
Removes duplicate state by reusing parent's options field for both function
calling and chat options. This simplifies the inheritance structure and
prevents potential state inconsistencies.

- Remove functionCallingOptions field from DefaultFunctionCallingOptionsBuilder
- Set parent class options with FunctionCallingOptions in child constructor
- Add protected constructor in DefaultChatOptionsBuilder for inheritance
- Initialize options through constructors instead of direct assignment
2024-12-19 13:57:52 -05:00
Mark Pollack
a4acd8e4fa Add builder pattern to PineconeVectorStore and refactor package name 2024-12-19 13:50:21 -05:00
Mark Pollack
d6d246096b reformatting 2024-12-19 13:44:38 -05:00
Soby Chacko
351dfc2f85 Pinecone vector store builder refactoring 2024-12-19 13:44:38 -05:00
Soby Chacko
d4a6e1e619 CosmosDB vector store builder refactoring 2024-12-19 13:40:18 -05:00
Soby Chacko
138e11a3e5 Add builder pattern to AzureVectorStore and refactor package name 2024-12-19 13:38:22 -05:00
Soby Chacko
8c28c6dc88 Gemfire vector store builder refactoring 2024-12-19 13:22:54 -05:00
Soby Chacko
71584e5238 Add builder pattern to HanaCloudVectorStore and refactor package name 2024-12-19 13:21:29 -05:00
Soby Chacko
7a7a914dc0 Add builder pattern to CoherenceVectorStore and refactor package name 2024-12-19 13:17:59 -05:00
Soby Chacko
08bf66cbd5 Oracle vector store builder refactoring 2024-12-19 13:12:37 -05:00
Mark Pollack
7e2cefc3aa Share options instance between DefaultFunctionCallingOptionsBuilder and parent class 2024-12-19 11:23:01 -05:00
Ilayaperumal Gopinathan
adefca13f8 Fix EmbeddingOptions
- Remove the explicit EMPTY check when merging the default embedding options
 - Use the builder to build the default embedding options
2024-12-19 10:28:58 -05:00
Ilayaperumal Gopinathan
69cd3173f7 Fix mariadb similarity search
- The similarity search doesn't need the embedding to be returned/stored back to Document
2024-12-19 10:24:51 -05:00
Mark Pollack
5caf1084a7 Add tests for DefaultFunctionCallingOptions 2024-12-19 10:17:20 -05:00
Ilayaperumal Gopinathan
1c72f14a69 Refactor ModerationResult builder methods
- Deprecate the existing builder methods to remove the prefix `with`
 - Update references
2024-12-19 09:13:39 -05:00
Ilayaperumal Gopinathan
5f300c237e Fix javadoc error/warnings 2024-12-19 07:55:44 +00:00
Ilayaperumal Gopinathan
7e4a187f0d Refactor Ollama builder API
The Ollama options builder API has been refactored to follow standard Java
builder pattern conventions. This change deprecates all builder methods
prefixed with 'with' in favor of more concise method names, improving API
consistency and usability.

The deprecated methods are marked for removal in version 1.0.0-M5, giving
users time to migrate to the new builder pattern. This change aligns with
our goal of providing a more intuitive and maintainable API surface.

Breaking Changes:

* builder() method now returns Builder instead of OllamaOptions
* Clients using the old fluent API will need to migrate to the new builder pattern
Refactor Ollama options builder methods
2024-12-18 22:39:42 -05:00
Ilayaperumal Gopinathan
26fab03c2c Refactor VectorStoreObservationContext builder methods
This commit deprecates builder methods with the "with" prefix in the VectorStoreObservationContext class
and introduces new methods without the prefix for a cleaner API. For example:

withCollectionName() → collectionName()
withDimensions() → dimensions()
withNamespace() → namespace()

The old methods are marked as deprecated for maintaining backward compatibility.

All vector store implementations have been updated to use the new method names.
2024-12-18 18:15:09 -05:00
Ilayaperumal Gopinathan
8ce8374825 Add builder pattern to SimpleVectorStore
- Create SimpleVectorStoreBuilder which can be used to create the SimpleVectorStore instance
 - Remove the field embeddingModel from SimpleVectorStore as it can be retrieved from AbstractObservationVectorStore
 - Deprecate the existing SimpleVectorStore constructors and use the builder to instantiate it
 - Fix the tests
2024-12-18 18:01:41 -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