Commit Graph

1453 Commits

Author SHA1 Message Date
Christian Tzolov
7ed73e8478 Improve resource management in TransformersEmbeddingModel
- Prevent potential resource leaks
 - Wrap OnnxTensor creation in try-with-resources block
 - Explicitly close inputIds, attentionMask, and tokenTypeIds tensors
 - Close OrtSession.SessionOptions() in afterPropertiesSet
 - Add javadoc

Resolves #1427
2024-10-08 12:30:46 +02:00
Mark Pollack
d96d0b53f6 Add docs for FactCheckingEvaluator 2024-10-08 12:21:52 +02:00
Christian Tzolov
10193431f6 Observability instrumentation for VertexAI Text Embedding 2024-10-08 11:20:08 +02:00
努力的小雨
82a69dc3a3 Update milvus.adoc
error description
2024-10-08 10:56:59 +02:00
John Blum
3738c38b66 Cleanup grammar in documentation
* Fixes grammar in (Ollama) Function Calling.
* Fixes grammar in ETL Pipeline.
* Fixes grammar in Vector Databases.

Closes #1494
2024-10-08 10:56:29 +02:00
Christian Tzolov
d71ca0e68e Add observability support to TransformersEmbeddingModel
- Integrate ObservationRegistry and EmbeddingModelObservationConvention
 - Update TransformersEmbeddingModel to use observations
 - Add TransformersEmbeddingModelObservationTests
 - Update TransformersEmbeddingModelAutoConfiguration for observation support
 - Add ONNX to AiProvider enum
2024-10-08 10:48:48 +02:00
GR
7bd8a17d33 Add observability to zhipu chat model 2024-10-08 10:38:18 +02:00
GR
6203325f30 Add observability to qianfan chat model 2024-10-08 10:33:58 +02:00
GR
1606383704 Add observability to moonshot chat model 2024-10-08 00:40:27 +02:00
GR
ee7d2b2556 Add observability to minimax chat model
- add observability to minimax embedding model
- fix chat web search result error
- fix minimax auto configuration
2024-10-08 00:24:22 +02:00
Soby Chacko
bac002bf83 Observation for Vertex gemini chat model streaming operation
- Adding observability for Vertex Gemini chat model streaming call
- Updating auto-configuration for gemini chat model with the observability components
- Integration test for streaming observability
2024-10-08 00:14:47 +02:00
Mark Pollack
06392f90cb Update azure embedding test not to set dimensions 2024-10-08 00:10:46 +02:00
Christian Tzolov
6f39704d46 Extend observation support to Azure OpenAI models (#1491)
- Implement observation instrumentation for AzureOpenAiEmbeddingModel
 - Create AzureOpenAiEmbeddingModelObservationIT for integration testing
 - Update AzureOpenAiAutoConfiguration to support observation
 - Introduce ObservationRegistry and observation conventions
2024-10-07 17:43:13 -04:00
Soby Chacko
0763d78fef Add observability for the regular imperative call in VertexAi Gemini chat model
- Integrate ObservationRegistry for instrumentation in VertexAiGeminiChatModel's non-streaming call
- Add ChatModelObservationContext and related classes for observation
- Refactor createGeminiRequest method to support runtime options for imperative calls
- Implement observation for non-streaming chat operations in VertexAiChatModelObservationIT
- Add VertexAiGeminiConstants class for provider name

This commit enhances the VertexAiGeminiChatModel with observability features
for the non-streaming, imperative call() method. It allows for better
monitoring and instrumentation of synchronous chat operations. The changes
include refactoring to improve runtime option handling for these calls and
adds integration tests for the new observability features.
2024-10-07 23:25:40 +02:00
Christian Tzolov
9678ea53e8 Fix NPE in a test fixture 2024-10-07 20:48:10 +02:00
Mark Pollack
4b95dfc2ef Refine prompt for strict comma-separated list output
Improve clarity of instructions for model responses. The changes:

- Specify no leading or trailing text in the output
- Reword for more direct and unambiguous instructions

Fixes #718
2024-10-07 18:58:32 +02:00
Mark Pollack
64b147e699 Restructure OpenAI and AzureOpenAI ChatClientITs
- Use List<ChatResponse> to better examine the full response
2024-10-07 17:29:11 +02:00
Mark Pollack
22a61548ac Fix Keyword extractor test as chatgpt's response changed 2024-10-07 16:25:19 +02:00
Christian Tzolov
38082de0f8 Refactor FunctionCallback API to use ToolContext instead of Map<String, Object>
- Replaced `Map<String, Object>` with `ToolContext` in the `FunctionCallback`, `AbstractFunctionCallback`, and related classes.
 - Updated all BiFunction definitions to use `ToolContext` as the second parameter,
   enhancing the clarity and structure of the tool context management.
 - Modified `FunctionCallbackWrapper` and `FunctionCallbackContext` to adapt to the new `ToolContext` parameter.
 - Adjusted the handling of tool context in the documentation and test classes.
 - Updated relevant test cases to reflect the API changes and modified the function handling logic to ensure consistency.
2024-10-07 16:15:55 +02:00
Mark Pollack
662afdf46e Update asciidoc table in Azure OpenAI properties documentation
- Add description for spring.ai.azure.openai.custom-headers property

Fixes #1434.
2024-10-07 14:32:37 +02:00
Eddú Meléndez
a987e0305a Add new FactCheckingEvaluator for grounded factuality checking
- Introduce FactCheckingEvaluator class for LLM response validation
- Implement evaluation logic using ChatClient for fact-checking
- Add comprehensive JavaDoc explaining the evaluator's purpose and usage
- Reference Bespoke-Minicheck model for efficient implementation options
- Include links to Ollama blog post and MiniCheck research paper
- Distinguish from 'closed book' scenario testing in documentation

This new evaluator enables detection and reduction of hallucinations
in LLM outputs by checking claims against provided context. It provides
a foundation for implementing advanced fact-checking methodologies in
Spring AI applications.

See https://ollama.com/blog/reduce-hallucinations-with-bespoke-minicheck
2024-10-07 14:07:12 +02:00
Bruno Oliveira
78073c64ea Update bedrock-cohere-embedding.adoc to fix an incorrect description 2024-10-07 11:52:36 +02:00
Christian Tzolov
4e7e4cf2b5 Add tool context support to ChatClient and related classes
- Introduce toolContext to ChatClient, DefaultChatClient, and AdvisedRequest
 - Add methods to set and manage toolContext via the FunctionCallingOptions
 - Update tests to include toolContext in relevant scenarios
 - Implement toolContext handling in function calling options
2024-10-07 11:50:41 +02:00
Mudabir Hussain
2090826656 Fix NullPointerException with Ollama + tool calls
Fixed #1459
2024-10-07 11:48:40 +02:00
Thomas Vitale
6e62ff7d83 Add Cloud Bindings for Mistral AI
* Introduce Cloud Bindings support to configure the Mistral AI integration
* Update the Cloud Bindings documentation accordingly
2024-10-07 10:04:51 +02:00
ktm
2babb2a878 Add JSON Pointer support to JsonReader
This enhancement allows users to specify a JSON Pointer to extract
specific parts of a JSON document when reading. Key changes include:

- New get(String pointer) method in JsonReader class
- Updated JsonReaderTests with pointer-based extraction tests
- Added documentation for JSON Pointer usage in etl-pipeline.adoc

This feature enables more flexible parsing of complex JSON structures,
allowing users to easily target nested data for extraction.
2024-10-06 23:10:24 +02:00
John Blum
89487e3565 Optimze imports in ImageResponseMetadata.
* Make the Long created field final.
* Delegate the default constructor to ImageResponseMetadata(:Long) passing System.currentTimeMillis().
2024-10-06 22:52:57 +02:00
John Blum
aa4502896d Correct grammar in the Image Model API doc
Closes #1454
2024-10-06 22:50:58 +02:00
Fu Cheng
ae743f98a5 Enhance ChromaVectorStore initialization and add test for disabled schema
- Improve ChromaVectorStore to throw exception on missing collection with disabled schema
 - Add test case to verify exception is thrown when collection doesn't exist and schema init is false
 - Correctly set Chroma collection id when initializeSchema set to false

 Co-authored-by: Christian Tzolov <ctzolov@vmware.com>
2024-10-06 22:46:22 +02:00
dafriz
b1377d194d Make ElasticsearchVectorStoreAutoConfig class public
This change allows the ElasticsearchVectorStoreAutoConfiguration
class to be excluded, enabling custom configurations. It brings
consistency with other vector store auto-configuration classes.
2024-10-06 22:44:26 +02:00
Hyune-c
e12372171b Fix anthropicApi visibility in AnthropicChatModel 2024-10-06 22:41:23 +02:00
inpink
5431bdd956 Include index name in OpenSearch similarity search
- Resolved issue where index name was not being sent during
  similaritySearch
- Updated similaritySearch method to include index in the SearchRequest
- Implemented test to verify documents can be added and retrieved from
  two different indices using separate OpenSearchVectorStore instances
- Ensured similarity search results are correctly returned for the
  respective indices

Fixes #885
2024-10-06 22:39:14 +02:00
Christian Tzolov
8bea302b11 Add missing observation and merics names to the docs 2024-10-06 22:01:50 +02:00
Thomas Vitale
60e36c3b55 Update Observability documentation
* Update attributes
* Add more information on optional attributes and risks
* Include documentation for events.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-06 19:19:58 +02:00
Thomas Vitale
012f07c97b Optimize Testcontainers config for VectorStores
* Unify image definition for vector stores in vector-store modules

* Unify image definition for vector stores in spring-ai-testcontainers module

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-06 19:18:05 +02:00
Christian Tzolov
eb2deba9cb Clarify how advisors are ordered in the reference doc 2024-10-06 16:40:54 +02:00
Thomas Vitale
1ee90944de Improve chat client and advisor observations
* Make ChatClient and Advisor observation logic null-safe
* Simplify naming for Advisor observations
* Include high-cardinality attributes only if a value is present
* Fix condition to include system test to chat client observations
* Add Advisor order information to context
* Streamline usage of enums and utils to reduce hard-coded/duplications
* Fix pending Chroma integration test

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-06 16:38:18 +02:00
Soby Chacko
8ea56329ac Adding observability for AzureOpenAiChatModel streaming 2024-10-06 15:37:15 +02:00
Thomas Vitale
21504a6296 Keep model metric attributes fixed for Prometheus
Unlike other metrics implementations supported by Micrometer, when using the Prometheus integration, all metric attributes are supposed to have a value, or else the related metrics are dropped.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-06 15:36:49 +02:00
Thomas Vitale
50e11e3f46 Improve optional values handling in vector store observations
Vector store observations support several key-value pairs, coming from the Spring AI abstractions. Currently, whenever a value is not available (either because not configured by the user or not supported by the vector store provider), span/metrics attributes are generated anyway with value none.

That causes several issues, including an unneeded increase in time series, challenges in alerting/monitoring (especially for integer/double attributes that suddenly are populated with a string), and non-compliance with the OpenTelemetry Semantic Conventions (according to which, attributes should be excluded altogether if there's no value).

This pull request changes the conventions for vector store observations to exclude the generation of span/metrics attributes for optional values which don't have any value.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-06 15:36:18 +02:00
Thomas Vitale
3b1c68ac10 Improve optional values handling in chat model observations
Chat model observations support several key-value pairs, coming from the Spring AI abstractions.
Currently, whenever a value is not available (either because not configured by the user or not supported by the model provider), a span/metrics is generated anyway with value none.
That causes several issues, including an unneeded increase in time series, challenges in alerting/monitoring (especially for integer/double attributes that suddenly are populated with a string), and incompliance with the OpenTelemetry Semantic Conventions (according to which, attributes should be excluded altogether if there's no value).
This pull request changes the conventions for chat model observation to exclude the generation of span/metrics attributes for optional values which don't have any value.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-05 23:55:16 +02:00
Thomas Vitale
dc0476478c Fix chat model autoconfig when no Micrometer Tracing in context
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-05 23:30:39 +02:00
Christian Tzolov
c59411c124 Rename Chat Client observation metrics
Change the name from  spring.ai.chat.client.operation to  spring.ai.chat.client
2024-10-05 23:19:48 +02:00
Jang990
bf172e931d Remove duplicate Elasticsearch initialize-schema property
This commit removes the duplicate entry of
'spring.ai.vectorstore.elasticsearch.initialize-schema' property from
the Elasticsearch Vector Store documentation.
2024-10-04 16:55:14 -04:00
Christian Tzolov
9c10a08bef Add tool context support to chat options and enhance function calling
This commit adds support for tool context in various chat options classes across
  different AI model implementations and enhances function calling capabilities.

  The tool context allows passing additional contextual information to function callbacks.

 - Add toolContext field to chat options classes
 - Update builder classes to support setting toolContext
 - Enhance FunctionCallback interface to support context-aware function calls
 - Update AbstractFunctionCallback to implement BiFunction instead of Function
 - Modify FunctionCallbackWrapper to support both Function and BiFunction and
   to use the new SchemaType location
 - Add support for BiFunction in TypeResolverHelper
 - Update ChatClient interface and DefaultChatClient implementation to support
   new function calling methods with Function, BiFunction and FunctionCallback arguments
 - Refactor AbstractToolCallSupport to pass tool context to function execution
 - Update all affected <Model>ChatOptions with tool context support
 - Simplify OpenAiChatClientMultipleFunctionCallsIT test
 - Add tests for function calling with tool context
 - Add new test cases for function callbacks with context in various integration tests
 - Modify existing tests to incorporate new context-aware function calling capabilities
 - Add docs in in openai function calling

 Resolves #864, #1303, #991
2024-10-04 16:47:42 -04:00
Soby Chacko
b68112d4cb Add Micrometer observability for Azure OpenAI chat
Implement observability for imperative calls in AzureOpenAiChatModel:

* Integrate ObservationRegistry to track metrics and events
* Create observation context and define conventions for consistency
* Add integration test to verify chat model observations
* Update AiProvider enum with new AZURE_OPENAI entry
2024-10-04 16:09:18 -04:00
Christian Tzolov
45c6622736 Fix support for FunctionCallingOptions across AI models
Add support for PortableFunctionCallingOptions across AI models

- Modify FunctionCallingOptions interface to extend ChatOptions for better integration
- Refactor option handling in chat models to accommodate both ChatOptions and FunctionCallingOptions
- Implement handling of FunctionCallingOptions in Anthropic, Azure OpenAI,
  MistralAI, Ollama, OpenAI, VertexAI Gemini, and other models
- Update existing function calling tests to use new FunctionCallingOptions.

Resolves #624
2024-10-04 15:50:59 -04:00
Christian Tzolov
89cfa9911d Simplify advisor observation naming
- Simplify advisor naming in DefaultAdvisorObservationConvention
 - Update corresponding test cases
2024-10-04 19:52:33 +02:00
Christian Tzolov
d6dc2b26bf Add conditinal support for logging errors in observation Span
- Useful for not Web apps.
 - Introduce ErrorLoggingObservationHandler for tracing errors across various AI contexts
 - Add error logging configuration option to ChatObservationProperties
 - Include ErrorLoggingObservationHandler bean in ChatObservationAutoConfiguration
 - Update docs

Resolves #1440
2024-10-04 11:08:26 -04:00
Fu Cheng
05292ac730 Fix NPE in TextReader source metadata
This commit addresses the NPE issue in TextReader's source metadata
handling. It introduces a new method getResourceIdentifier() to
robustly extract identifiers from various Resource types.
The fix ensures that:

1. Filename is used if available
2. Falls back to URI, then URL if filename is not present
3. Uses resource description as a last resort

Additionally, the commit includes updated tests to verify the behavior
with different Resource types, particularly ByteArrayResource

This change prevents NPEs when dealing with Resources that lack
certain properties, improving the overall reliability of TextReader.

Fixes https://github.com/spring-projects/spring-ai/issues/1386
2024-10-03 17:11:05 -04:00