Commit Graph

312 Commits

Author SHA1 Message Date
Thomas Vitale
4b123a7516 Use Double instead of Float for portable ChatOptions
This change updates the type of portable chat options from Float to
Double. Affected options include:
- frequencyPenalty
- presencePenalty
- temperature
- topP

The motivation for this change is to simplify coding. In Java, Float
values require an "f" suffix (e.g., 0.5f), while Double values don't
need any suffix. This makes Double easier to type and reduces
potential errors from forgetting the "f" suffix.

APIs, tests, and documentation have been updated to reflect this
change.

Fixes gh-712

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-09-16 15:35:51 -04:00
Soby Chacko
15fdd05fac Add batching for more vector stores
Apply batching when adding Documents to the following vector stores:

- Chroma
- ElasticSearch
- Neo4j
- Qdrant
- Redis
- Typesense
- Weaviate

This improves efficiency by processing multiple Documents at once instead of individually, reducing the overhead for each operation.

Related to #1261
2024-09-09 15:28:22 -04:00
Soby Chacko
087de16cfc Add batching strategy for embedding documents in PgVectorStore
- Precompute all embeddings using a BatchingStrategy before inserting into the vector store

This optimization improves efficiency when adding multiple documents

Related to #1261
2024-09-04 17:23:39 -04:00
Craig Walls
3cab5bd009 Autowire WebClient.Builder into OllamaApi 2024-09-04 14:11:21 -04:00
Mark Pollack
e1884d1d92 Next development version 2024-08-23 18:47:37 -04:00
Mark Pollack
43ad2bdb97 Release version 1.0.0-M2 2024-08-23 18:46:58 -04:00
GR
0927bd197d Fix MiniMax model function call implementation
Implement function call capability for MiniMax model and add unit tests based on new tool classes.
Address most scenarios, but note limitations in complex English contexts
with multiple function calls. Weather query example: may stop
prematurely when querying multiple locations due to single-location
parameter limit. This behavior stems from model performance constraints.

Streaming function calling is not passing tests, will be address seperately.

Resolves #1077

Implement function call capability for the Moonshot model. Include unit
tests to verify the new functionality. This feature addresses the
requirements outlined in issue #1058.
fix: MiniMax function call

review
2024-08-23 12:03:33 -04:00
GR
611c9493e3 Add function call support for Moonshot model
Implement function call capability for the Moonshot model. Include unit
tests to verify the new functionality.

Resolves #1058
2024-08-23 11:43:07 -04:00
GR
935e1a38ed Add ZhiPu model support for AbstractToolCallSupport
Implement ZhiPu function call to work with AbstractToolCallSupport
framework. Add unit tests for function call functionality.

Resolves #1078.
2024-08-23 11:12:21 -04:00
Christian Tzolov
99a4fec214 Remove the reactive advisor observability support
-  Add Anthropic WebClient.Builder autoconfiguration to activate the OOTB WebClient obsercabilty support.
2024-08-23 09:57:49 -04:00
Mohammed, Ahmed yousri salama (Canada)
189468127c Implement OpenAI Moderation model
This commit introduces the OpenAiModerationModel and related classes:

- Add OpenAiModerationModel for content moderation
- Create OpenAiModerationOptions for configuration
- Implement OpenAiModerationProperties for Spring Boot setup
- Add integration tests in OpenAiModerationModelIT
- Add documentation

Co-authored-by: hemeda3 <hemeda3@users.noreply.github.com>
2024-08-22 17:39:16 -04:00
Soby Chacko
d752b3d8d7 Gemfire vector store cleanup
- Based on the pattern established in other vector store support implementations,
  added a builder class as an inner class of the GemfireVectorStoreConfig class which
  is also moved as an inner class to GemfireVectorStore.

Based on the original PR: https://github.com/spring-projects/spring-ai/pull/1168
2024-08-22 11:34:54 -04:00
Thomas Vitale
036093a42b Enhance vector store observability support
* Consolidate usage of “db.collection.name” attribute to track table name, collection name, index name, document name, or whatever concept a vector database uses to store data. Removed “db.index” that was use sometimes instead of “db.collection.name”. This usage is in line with the OpenTelemetry Semantic Conventions.
* Configure query response content to be included as a “span event” instead of a “span attribute” if the backend system supports that, similar to how we do for the model observations.
* Structure vector store observation attributes in dedicated enums, including one for the Spring AI Kinds to avoid hard-coding the same value in a lot of places. This follows the OpenTelemetry Semantic Conventions as much as possible. Also, adopt Spring usual non-null-by-default strategy as much as possible.
* Align vector store conventions to the chat model ones, and follow alphabetical order for values. This is particularly useful for the convention classes, for which the Micrometer performance of exporting telemetry data improves when key values are added already sorted to the context.
* Fix flaky test in Mistral AI.
* Improve Qdrant integration tests.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-22 09:38:59 +02:00
Soby Chacko
f0771f0770 Fixing MongoDB vector store support test failures
Remove the requirement of MongoDB vector store auto-configuration only after `MongoDataAutoConfiguration`.
This enables the `MongoDBAtlasVectorStoreAutoConfiguration` to properly provide custom Mongo conversions.

In `MongoDBAtlasVectorStoreIT` and `MongoDbVectorStoreObservationIT` tests, properly provision the `MongoTemplate`
with custom conversions as these tests are not relying on auto-configuration.
2024-08-21 07:10:54 +02:00
Soby Chacko
949f1ed4e8 Add Batching strategy for embedding documents
- When embedding documents, allow batching the documents using some criteria.
 - `BatchingStrategy` interface with a `TokenCountBatchingStrategy` implementation that uses
   the openai max input token size of 8191 as the default.
 - Add a default method in EmbeddingModel to embed document using this new batching strategy.
 - Change `MilvusVectorStore` to make use of this new batching API.
 - Adding unit tests for `TokenCountBatchingStrategy`.
 - Adding openai integration test to call the embed API that uses batching.

Resolves https://github.com/spring-projects/spring-ai/issues/1214

Other vector stores will be updated seperately
2024-08-20 14:08:06 -04:00
Christian Tzolov
7afc2b56a1 Disable MonogDB ITs due to #698 2024-08-20 16:19:25 +02:00
Christian Tzolov
4cc9a9ce4a Harden the WeaviateContainer initialization to prevent IT instability 2024-08-20 10:54:43 +02:00
Christian Tzolov
93fa2bf45a Add observability support to existing vector stores
Add observability support to:
 - Cassandra
 - Chroma
 - Elasticsearch
 - Milvus
 - Neo4j
 - OpenSearch
 - Qdrant
 - Redis
 - Typesense
 - Weaviate
 - Pinecone
 - Oracle
 - Gemifire
 - MongoDB
 - HanaDB

 Add autoconfiguration obsrvability for the above vector stores.
 Add integration tests for all vector stores.
2024-08-20 01:37:45 -04:00
Thomas Vitale
3b7522b6c0 Model observability for Anthropic
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-20 01:13:43 -04:00
Thomas Vitale
3fa102e78f Prompt content and completion as span events
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-20 00:59:43 -04:00
Thomas Vitale
80fe5e4897 Model observability for Mistral
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-20 00:36:31 -04:00
Thomas Vitale
10e1e13fa2 Add observability support for Ollama
- Improve ITs to reuse a single container across tests
2024-08-16 14:29:23 -04:00
Christian Tzolov
bc3f9acb86 Add observability support to VectorStore
Implementation:
- Introduce AbstractObservationVectorStore with instrumentation for add, delete, and similaritySearch methods
- Create VectorStoreObservationContext to capture operation details
- Implement DefaultVectorStoreObservationConvention for naming and tagging
- Add VectorStoreObservationDocumentation for defining observation keys
- Create VectorStoreObservationAutoConfiguration for auto-configuring observations
- Add VectorStoreObservationProperties to control optional observation content filters
- Update VectorStore interface with getName() method
- Modify PgVectorStore and SimpleVectorStore to extend AbstractObservationVectorStore
- Add vector_store Spring AI kind

Filters:
- Implement VectorStoreQueryResponseObservationFilter
- Add VectorStoreDeleteRequestContentObservationFilter and VectorStoreAddRequestContentObservationFilter

Enhancements:
- Update PgVectorStoreAutoConfiguration to support observations
- Add observation support to PgVectorStore's Builder
- Add VectorStoreObservationContext.Operation enum with ADD, DELETE, and QUERY options

Tests:
- Add tests for VectorStore context, convention, and filters
- Add VectorStoreObservationAutoConfiguration tests
- Add PgVectorObservationIT

Resolves #1205
2024-08-16 10:33:50 -04:00
Christian Tzolov
d538e00643 Replace the Embedding format from List<Double> to float[]
- Adjust all affected classes including the Document.
 - Update docs.

Related to #405
2024-08-13 11:53:08 -04:00
Christian Tzolov
66e4b8868f Add ObservationRegistry support to ChatClient
- Implement observable chat responses in DefaultChatClient
 - Add ChatClientObservationContext and related classes for metrics
 - Update ChatClient and builder methods to support ObservationRegistry
 - Enhance RequestResponseAdvisor with getName() method
 - Add ChatClient streaming observability support
 - Introduce ChatClientObservationDocumentation for metric key names
 - Create DefaultChatClientObservationConvention for implementing conventions
 - Add ChatClientInputContentObservationFilter for optional input content logging
 - Update ChatClientAutoConfiguration to include new observation components
 - Extend ChatClientBuilderProperties with observation configuration options
 - Add unit tests for new observation classes and configurations
 - Update AiOperationType and AiProvider enums with new values
 - Implement safeguards and warnings for sensitive data in observations

 Resolves #1206
2024-08-11 18:26:53 +02:00
Thomas Vitale
bf84d5945e Streamline ChatOptions
* Surface more configuration APIs to ChatOptions
* Use abstraction in Observations directly instead of dedicated implementation
* Simplify metadata config in observations for defined models
* Improve merging of runtime and default options in OpenAI
* Fix missing option in Mistral AI

Relates to gh-1148

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-10 14:48:05 +02:00
Christian Tzolov
91afed5ae5 OpenAi: Add support for structured outputs and JSON schema
- Added support for OpenAI's structured outputs feature, which allows specifying a JSON schema for the model to match
- Introduced new record to configure the desired response format
- Added support for configuring the response format via application properties or the chat options builder
- Extend teh BeanOutputConverter to help generate JSON schema from a target domain object and convert the response.
- Added comprehensive tests to cover the new response format functionality

Resolves #1196
2024-08-08 17:00:18 -04:00
Eddú Meléndez
80007d4d6c Update testcontainers version to 1.20.1
Weaviate module contains the wait strategy.
2024-08-07 09:25:58 +02:00
Christian Tzolov
3978e8ecc2 Enhance OpenAI Authentication and Configuration
- Add org-id and project-id properties with unified merging logic
- Update autoconfig and docs for all OpenAI models
- Introduce OpenAiChatOptions#httpHeaders option
- Add integration test for httpHeaders and update docs

Resolves #1141
2024-08-03 22:30:37 +02:00
Thomas Vitale
4c1347db17 Fix autoconfig dependency when metrics enabled
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-02 22:25:56 +02:00
Thomas Vitale
12cf38a669 Make MeterObservationHandler conditional on MeterRegistry bean
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-02 22:11:47 +02:00
Thomas Vitale
6bdb395686 Initial observability for Spring AI
* Observation APIs for chat, embedding and image models
* Conventions based on OpenTelemetry Semantic Conventions for GenAI
* Instrumentation for OpenAI chat, embedding, and image models
* Autoconfiguration for observability for OpenAI

Fixes gh-953

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-01 22:25:43 +02:00
kamosama
7c800f35b8 Fix a FunctionCallback inside a container that pollutes the global model's ChatOptions
The autoconfiguration adds the FunctionCallbacks directly to the model's ChatOptions,
 which results in the FunctionCallback being included in the request each time it is called.

 The modification registers the container's FunctionCallback directly to the model's functionCallbackRegister
 using the parent AbstractToolCallSupport constsructor.

 Replace the handleFunctionCallbackConfigurations by simplified runtimeFunctionCallbackConfigurations.

Co-authored-by Christian Tzolov <ctzolov@vmware.com>
2024-07-30 20:11:14 +02:00
Soby Chacko
ce5961348b GH-868: Fix inconsistency in autoconfigured beans
* Fixing auto configured beans where they are missing `@ConditionalOnMissingBean`
* Add `matchIfMissing` on `@ConditionalOnProperty` where it is missing with value `true`

Resolves https://github.com/spring-projects/spring-ai/issues/868
2024-07-30 14:15:50 +02:00
Christian Tzolov
d875d48bd3 Streamline Azure OpenAI Function Calling 2024-07-30 11:52:44 +02:00
Mark Pollack
b64f6f1f75 Revert change to RedisVectorStoreAutoConfiguration 2024-07-24 23:20:16 -04:00
xiaoxin
02bd11f05a Use RedisProperties to pass in host and port for RedisVectorStore creation
Fixes #1094
2024-07-24 16:57:57 -04:00
Christian Tzolov
d53876a624 Add Ollama Function Call support
- extend the OllamaApi with Tool, ToolCalls and Function and add Tool Role.
- make OllamaChatModel extend the AbstractToolCallSupport.
- extend the OllamaChatModel to convert the Spring AI messages to OllamaApi messages, including Tools.
- OllamaOptions implements FunctionCallingOptions.
- add OllamaApiToolFunctionCallIT for testing function calling.
- patch the AbstractToolCallSupport#isToolCall to take set of stop resons.
- add FunctionCallbackInPromptIT and FunctionCallbackWrapperIT function calling auto-configuration tests.
- extend OllamAutoConfiguration to support function calling registration.
- add function call tests to OllamChatAutoConfigurationIT.
- add OllamaWithOpenAiChatModelIT to OpenAi that uses the OpenAI API to call Ollama.
- move buildToolCallConversation and handleToolCalls to parent AbstractToolCallSupport.
- update Docs. add Ollama function call docs.
- update Ollama diagrams.

Resolves #720
2024-07-24 16:28:06 -04:00
Mark Pollack
ee696f33dd Make chat and embedding paths configurable
* Updated docs
* Minor code cleanup
2024-07-24 15:19:01 -04:00
Thomas Vitale
6c88654404 Consolidate retry config for OpenAI
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-07-23 18:22:39 +02:00
Christian Tzolov
03d1d50130 Update the Azure OpenAI Chat Model to defult to the gpt-4o 2024-07-22 14:51:11 +02:00
Piotr Olaszewski
0e97f9c579 Introduce AzureOpenAI transcription support
- Breaking changes: Classes from the org.springframework.ai.openai.metadata.audio.transcription package have been moved to the org.springframework.ai.audio.transcription package.
 - The AzureOpenAiAudioTranscriptionModel has been added to the auto-configuration.
 - The spring.ai.azure.openai.audio.transcription prefix was introduced for properties.
 - Introduces options properties which cover all of them (see: AzureOpenAiAudioTranscriptionOptions).
 - fix missing MutableResponseMetadata
 - add docs
 - adjust code to updated ResponseMetadata design
 - add test to AzureOpenAiAutoConfiguration
 - add missing AzureOpenAiAudioTranscriptionModel tests
2024-07-22 14:08:11 +02:00
Christian Tzolov
5dc9480eea Anthropic: make the beta features header value configurable
- add new spring.ai.anthropic.beta-version property.
  - add ITs.

  Resolves #1068
2024-07-18 20:54:28 +02:00
Soby Chacko
50d34b8a48 BREAKING CHANGE - Change vector store initialize-schema to false
* Change default schema initialization of vector stores from `true` to `false.`
  Users need to explicitly opt-in for schema initialization by setting the
  `initialize-schema` property on the corresponding vector store.
* Update integration tests
* Update docs

Fixes #907
2024-07-18 14:28:00 -04:00
Youngrae Cho
75db25b13d Fix RetryTemplate retry condition
Resolves #846
2024-07-18 15:33:16 +02:00
Eddú Meléndez
0a07f65d6a Use RedisAutoConfiguration in RedisVectorStoreAutoConfiguration
Currently, `RedisVectorStoreAutoConfiguration` creates its own
configuration to connect with Redis. This commit reuse
`RedisAutoConfiguration` from spring boot project. It's limited
to Jedis.
2024-07-18 14:24:10 +02:00
Mark Pollack
97f443d615 Update to ResponseMetadata design
* Remove inheritance from HashMap
* No more subclasses per model provider
* Builder class for ChatResponse
* Fix the AbstractResponseMetadata#AI_METADATA_STRING parameter order
* ChatResponseMetadata ignore Null values.
2024-07-18 12:48:28 +02:00
Mark Pollack
17c44237a5 Fix cassandra chat memory entry in autoconfig .imports file 2024-07-17 10:04:56 -04:00
mck
4aacab020b Implement CassandraChatMemory
- provides a flexible schema, can be combined with a vector store, and supports time-to-live rows.
 - fix initialize-schema docs and so that it actually works.
 - move CommonVectorStoreProperties to .vectorstore. package
 - add CassandraAutoConfiguration to the AutoConfiguration.imports
2024-07-17 11:42:09 +02:00
Chris Turchin
f07e3911dc Fix system messages handling issue
- re-assign the model on withSystemInstruction return.
 - deprecate the gemini-pro-vision model and replace the default model to gemin-pro-1.5
 - update docs.
 - improve system message handling implementation.

 Resolves #1030

Co-authored-by: Christian Tzolov <ctzolov@vmware.com>
2024-07-15 19:26:12 +02:00