Commit Graph

1532 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
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
Mark Pollack
1cac9bfc90 Temporarily disable MariaDBStoreIT 2024-12-05 16:34:03 -05:00
Soby Chacko
d16665dad9 Add VectorStore builder hierarchy
This refactoring introduces a consistent builder pattern across vector store
implementations to standardize configuration and initialization, while also
moving ChromaVectorStore to a dedicated chroma package.

Key changes:
- Add VectorStore.Builder interface and AbstractVectorStoreBuilder to establish
  a common builder hierarchy
- Move ChromaVectorStore and related classes from vectorstore to
  org.springframework.ai.chroma.vectorstore package
- Migrate ChromaVectorStore to builder pattern as the first implementation
- Add null-safety annotations and parameter validation
- Deprecate direct constructors in favor of builder API
- Update all tests and documentation to reflect new structure

The builder pattern provides several benefits:
- Consistent configuration across all vector store implementations
- Better validation of required parameters
- More flexible initialization order
- Clearer separation of concerns between configuration and usage
- Improved discoverability of options through method chaining
2024-12-05 16:28:49 -05:00
Ilayaperumal Gopinathan
ebd29e0959 GH-1826 Fix EmbeddingModel's usage on Document#embedding
- Since the Document object's reference to the `embedding` is deprecated and will be removed, the VectorStore implementations require a way to store the embedding of the corresponding Document objects

     - One way to fix this is, to have the EmbeddingModel#embed to return the embeddings in the same order as that of the Documents passed to it.

       - Since both the Document and embedding collections use the List object, their iteration operation will make sure to keep them in line with the same order.

       - A fix is required to preserve the order when batching strategy is applied.
	  - Updated the Javadoc for BatchingStrategy
          - Fixed the Document List order in TokenCountBatchingStrategy

    - Refactored the vector store implementations to update this change

Resolves #GH-1826
2024-12-05 21:37:27 +01:00
Christian Tzolov
6cfe5e79e8 add chatclient IT for openai multimodal Audio resposne 2024-12-05 06:50:28 +01:00
Mark Pollack
f922195d36 fix document builder tests 2024-12-03 09:37:28 -05:00
Mark Pollack
b405536bba Fix failing OpenSearch IT and disable Mistral function calling IT
- PaymentStatusFunctionCallingIT in org.springframework.ai.mistralai.api.tool
  is failing.  Needs investigation.
  See https://github.com/spring-projects/spring-ai/issues/1853
- OpenSearchVectorStoreWithOllamaIT updated to pull model if not available.
2024-12-02 16:45:02 -05:00
Mark Pollack
771c4a3182 fix typo in ci exclusion list 2024-12-02 15:06:55 -05:00
Thomas Vitale
fe58fd30eb Support similarity scores in Document API
Document
* Introduced “score” attribute in Document API. It stores the similarity score.
* Consolidate “distance” metadata for Documents. It stores the distance measurement.
* Adopted prefix-less naming convention in Document.Builder and deprecated old methods.
* Deprecated the many overloaded Document constructors in favour of Document.Builder.

Vector Stores
* Every vector store implementation now configures a “score” attribute with the similarity score of the Document embedding. It also includes the “distance” metadata with the distance measurement.
* Fixed error in Elasticsearch where distance and similarity were mixed up.
* Added missing integration tests for SimpleVectorStore.
* The Azure Vector Store and HanaDB Vector Store do not include those measurements because the product documentation do not include information about how the similarity score is returned, and without access to the cloud products I could not verify that via debugging.
* Improved tests to actually assert the result of the similarity search based on the returned score.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-12-02 14:54:28 -05:00
Ilayaperumal Gopinathan
50223d20e3 Add IT test for OpenAI stream function call usage verification 2024-12-02 11:05:16 +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