Get ahead
VMware offers training and certification to turbo-charge your progress.
Learn moreWe are happy to announce the 1.0.0 Milestone 4 release of Spring AI.
This release has squashed most of the reported bugs and brings significant enhancements across various areas.
Spring AI now supports the Amazon Bedrock Converse API, which provides a unified interface for the AI chat models that Amazon offers. Unlike the older Bedrock Invoke API, Converse introduces exciting new features such as Tool Calling and Multimodality/Visual capabilities (for models that support these features). This makes it a more powerful and versatile option for working with Amazon’s chat models.
In many ways, the Converse API serves a role similar to Spring AI itself, offering portability across model APIs but limited to Amazon's chat models. We recommend transitioning to the Converse module for chat models. Note that embedding models remain unaffected.
For details on this new capability, refer to the Spring AI Bedrock Converse documentation. You can also follow upcoming improvements for future enhancements. Many thanks to Max Jiang for starting this large undertaking.
Recent improvements expand support for various Function types and methods through the FunctionCallback
Builder class. This allows invocation of java.util.Function
, Supplier
, and Consumer
interfaces.
FunctionCallback callback = FunctionCallback.builder()
.description("Process a new order")
.function("processOrder", (Order order) -> processOrderLogic(order))
.inputType(Order.class)
.build();
Access additional state or context using ToolContext
with BiFunction<I, ToolContext, O>
@Bean
@Description("Get the weather in location")
public BiFunction<WeatherService.Request, ToolContext, WeatherService.Response> weatherFunctionWithContext() {
return (request, context) -> new MockWeatherService().apply(request);
}
Method invocation support provides the foundation for the upcoming @ToolMapping
annotation in M5:
public static class LightControl {
private static final Logger logger = LoggerFactory.getLogger(LightControl.class);
private final Map<String, Object> arguments = new HashMap<>();
public void controlLight(String roomName, boolean on) {
arguments.put("roomName", roomName);
arguments.put("on", on);
logger.info("Setting light in room '{}' to: {}", roomName, on ? "ON" : "OFF");
}
}
Usage:
LightControl lightControl = new LightControl();
String response = ChatClient.create(this.chatModel)
.prompt("Turn light on in the living room.")
.functions(
FunctionCallback.builder()
.description("Controls lights by room name, allowing them to be turned on or off.")
.method("controlLight", String.class, boolean.class)
.targetObject(lightControl)
.build()
)
.call()
.content();
For additional features, consult the FunctionCallback documentation which covers:
ParameterizedTypeReference
Spring AI introduces support for Kotlin, making it even easier for Kotlin developers to integrate AI capabilities into their applications. This release introduces idiomatic Kotlin extensions and type-safe APIs. Many thanks to Sebastien Deleuze for taking on this work.
The new Kotlin extensions enable more concise and type-safe ways to handle AI responses. Instead of using Java-style type declarations, you can now use Kotlin's reified generics:
import org.springframework.ai.chat.client.entity
data class Joke(val setup: String, val punchline: String)
@SpringBootApplication
class KotlinHelloWorldApplication {
@Bean
fun jokeRunner(chatModel: ChatModel) = CommandLineRunner {
val response = ChatClient.create(chatModel).prompt().user("Tell me a joke").call().entity<Joke>()
println("\nJoke:")
println("Setup: ${response.setup}")
println("Punchline: ${response.punchline}")
}
}
fun main(args: Array<String>) {
runApplication<KotlinHelloWorldApplication>(*args)
}
Kotlin functions can now be directly registered as AI tools. The syntax is straightforward:
@Configuration
class Config {
@Bean
fun weatherFunctionInfo(currentWeather: (WeatherRequest) -> WeatherResponse): FunctionCallback {
return FunctionCallback.builder()
.description(
"Find the weather conditions, forecasts, and temperatures for a location, like a city or state."
)
.function("WeatherInfo", currentWeather)
.inputType(WeatherRequest::class.java)
.build()
}
@Bean
@Description("Get current weather")
fun currentWeather(): (WeatherRequest) -> WeatherResponse = { request ->
MockKotlinWeatherService().invoke(request)
}
}
Then, it can be used as below.
@Bean
open fun init(chatModel: ChatModel) = CommandLineRunner {
try {
val userMessage = UserMessage(
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations."
)
val response = chatModel.call(
Prompt(
listOf(userMessage),
OpenAiChatOptions.builder().withFunction("WeatherInfo").build()
)
)
println("Response: $response")
}
catch (e: Exception) {
println("Error during weather check: ${e.message}")
}
}
The reference documentation has been updated to include Kotlin examples, and you can find other examples in the spring-ai-examples repository.
The repository awesome-spring-ai keeps the theme of other “awseome” repositories and collects community related resources for Spring AI such as book, presentation, example code and so on. Please make PRs to the repository for any useful material you a have found.
The repository spring-ai-integration-tests is now available and is making progress to run all the integration tests for the entire project twice daily.
The repository spring-ai-examples is now available for hosting “official” examples. Check out the reflection agent example!
Also, as an introduction to the project, check out the blog post Why Spring AI
Spring AI introduces experimental support for advanced Retrieval Augmented Generation (RAG) based on recent research in modular RAG system design, in particular the papers Modular RAG: Transforming RAG Systems into LEGO-like Reconfigurable Frameworks and Retrieval-Augmented Generation for Large Language Models: A Survey. A big thanks to Thomas Vittale for leading this effort.
Here are the key building blocks:
Pre-retrieval Components
QueryTransformer
: Transforms queries to improve retrieval effectiveness (e.g., translation, rewrites)QueryExpander
: Expands single queries into multiple variations for broader context captureOrchestration Components
QueryRouter
: Routes queries to appropriate retrievers based on metadata or semantic analysisRetrieval Components
DocumentRetriever
: Core interface for retrieving relevant documentsDocumentJoiner
: Combines results from multiple retrievers/queriesPost-retrieval Components
DocumentCompressor
: Reduces document content while preserving key informationDocumentRanker
: Reorders documents by relevanceDocumentSelector
: Filters retrieved documents based on criteriaAugmentation Components
QueryAugmenter
: Enhances queries with retrieved contextContextualQueryAugmenter
: Default implementation focused on document context integrationBuilding on our modular RAG components, the RetrievalAugmentationAdvisor
provides an implementation to get you started and provides a linear RAG flow:
You stitch together these collaborating building block components in a bean definition such as
@Bean
public RetrievalAugmentationAdvisor customRagAdvisor(VectorStore vectorStore) {
return RetrievalAugmentationAdvisor.builder()
.queryTransformers(List.of(new TranslationQueryTransformer(...)))
.queryExpander(new MultiQueryExpander(...))
.queryRouter(
AllRetrieversQueryRouter.builder()
.documentRetrievers(new VectorStoreDocumentRetriever(...))
.build()
)
.documentJoiner(new ConcatenationDocumentJoiner())
.queryAugmenter(new ContextualQueryAugmenter(...))
.build();
}
While RetrievalAugmentationAdvisor implements a linear flow, users can implement custom Advisor
s for advanced patterns like conditional, branching, recursive, and adaptive flows. More documentation is to come and we encourage you to send feedback on our github issue tracker.
There were a few locations where Spring Boot being used in the model modules. This is no longer the case. The only dependencies on Spring Boot are not isolated to the autoconfigure module.
Azure OpenAI SDK upgraded to version 12 beta.
Expanded configuration and setup documentation, focusing on:
There were other refactoring, bug fixing, documentation enhancements across the board by a wide range of contributors. If we haven’t gotten to your PR yet, we will, please be patient. Thanks to
We are planning to have one more milestone release, 1.0.0 M5 targeted for late December that focuses on design issues, for example returning more information in the ChatResponse, overhaul the VectorStore API to add/delete and support different query types, unify the API styles of various builders, and more. Then in January we will make a 1.0.0 RC1 release followed quickly by a 1.0.0 GA release.