Spring AI
The first milestone release of Spring AI, version 0.8.0. was released on FEBRUARY 23, 2024.
What is Spring AI
Spring AI is an application framework for AI engineering. Its goal is to apply to the AI domain Spring ecosystem design principles such as portability and modular design and promote using POJOs as the building blocks of an application to the AI domain.
Features of Spring AI
Portable API support across AI providers for Chat, text-to-image, and Embedding models. Both synchronous and stream API options are supported. Dropping down to access model-specific features is also supported.

Why Spring AI came into existence?
The Spring AI project was founded based on the realization that creating AI applications was no longer the sole domain of Machine Learning or AI Specialists, who typically use Python. With the meteoric rise in popularity of ChatGPT, which provides a simple Web API to access pre-trained models, creating compelling AI applications has become accessible to software developers across many languages and their ecosystems.
The first release of Spring AI features
In this first release, we provide the foundations for creating AI applications with the following high level features.
- Portable API support across AI providers for Chat, text-to-image, and Embedding models. Both synchronous and stream API options are supported. Dropping down to access model-specific features is also supported. We support AI Models from OpenAI, Microsoft, Amazon, Google, Huggingface, and more.
- The Vector Store API provides portability across different providers, featuring a novel SQL-like metadata filtering API that maintains portability. Support for eight vector databases is available.
- Function calling in AI Models. You can declare java.util.Function implementations to OpenAI models for use in their prompt responses. You can directly provide these functions as objects or refer to their names if registered as a @Bean within the application context. This feature minimizes unnecessary code and enables the AI model to ask for more information to fulfill its response. Additionally, there will soon be support for more AI models.
- Spring Boot Auto Configuration and Starters for AI Models and Vector Stores.
- ETL framework for Data Engineering. This framework provides the basis for loading data into a vector database, helping implement the Retrieval Augmented Generation pattern that enables you to bring your data to the AI model to incorporate into its response.
Prompts
Prompts serve as the foundation for the language-based inputs that guide an AI model to produce specific outputs. For those familiar with ChatGPT, a prompt might seem like merely the text entered into a dialog box that is sent to the API. However, it encompasses much more than that. In many AI Models, the text for the prompt is not just a simple string.
ChatGPT’s API has multiple text inputs within a prompt, with each text input being assigned a role. For example, there is the system role, which tells the model how to behave and sets the context for the interaction. There is also the user role, which is typically the input from the user.
Prompt Templates
Creating effective prompts involves establishing the context of the request and substituting parts of the request with values specific to the user’s input.
This process uses traditional text-based template engines for prompt creation and management. Spring AI employs the OSS library StringTemplate for this purpose.
For instance, consider the simple prompt template:
Tell me a {adjective} joke about {content}.
In Spring AI, prompt templates can be likened to the “‘View'” in Spring MVC architecture. A model object, typically a java.util.Map, is provided to populate placeholders within the template. The “‘rendered'” string becomes the content of the prompt supplied to the AI model.
There is considerable variability in the specific data format of the prompt sent to the model. Initially starting as simple strings, prompts have evolved to include multiple messages, where each string in each message represents a distinct role for the model.
For more info refer the Document
Written By Madhuri Taddi
Website: www.sailssoftware.com