Spring AI Tutorial: Spring Boot, Ollama, RAG and Agents

Spring AI tutorial: a learning path of articles in reading order, from the first ChatClient call to RAG, tools, agents, testing and other model providers.

Spring AI

Spring AI provides Java APIs for connecting Spring Boot applications to language models and related services. This tutorial series follows a practical path from a local chat endpoint to retrieval, tools, agents, testing, and provider integrations.

Start with the first stage if you are new to Spring AI. If you already have an application, use the stage descriptions to find the feature you need and check that article’s prerequisites.

Most examples extend OrderDesk, a demo store’s support assistant using Spring Boot 4.1, Spring AI 2.0.1, and Java 21. The Embabel example uses a separate project and Java version. Local chat and embedding examples run in Ollama without a hosted key; media and hosted-provider articles state where valid provider access is required and which results were recorded locally.

The minimal endpoint below adds a question to a ChatClient request and returns the completed response. Configure the model and client as shown in Getting Started before using it:

@RestController
class ChatController {

    private final ChatClient chatClient;

    ChatController(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    @GetMapping("/ask")
    String ask(@RequestParam String question) {
        return chatClient.prompt()
            .user(question)
            .call()
            .content();
    }
}
Eight numbered boxes joined by arrows in reading order: 1 Start Here, 2 Core Chat, 3 Beyond Text, 4 RAG, 5 Tools and Agents, 6 Production, 7 Model Providers, 8 Reference. Each box names the main topics of its stage
The eight stages of the Spring AI learning path, from getting started to the reference articles

1. Start Here

After this stage, you have a Spring Boot app that sends a question to a local model and returns the answer.

2. Core Chat

After this stage, you can control what the model is told, get Java objects back instead of text, stream long answers, and keep a conversation going.

3. Beyond Text

This stage covers image input, image generation, speech generation, and transcription. The local vision example uses Ollama. The hosted media examples show setup and captured requests, and identify their account-access and model-lifecycle limits.

4. RAG: Answer from Your Own Documents

RAG retrieves relevant document sections and includes them with the question. This gives the model evidence about the store’s policies, but retrieval can miss a section and the model can still apply the wrong rule. These articles cover both the pipeline and those failure modes.

5. Tools and Agents

This stage connects model requests to Java operations and multi-step application flows. The application remains responsible for executing tools, authorizing access, and enforcing limits.

6. Production

These articles cover deterministic tests, real-model evaluation, metrics, traces, and moderation. They explain what each check measures and where model-based decisions still need validation.

7. Other Model Providers

Each integration article configures a second backend alongside Ollama. Hosted access requires provider credentials or an appropriate cloud identity; recorded answers use Ollama where account keys were unavailable. Docker Model Runner uses a local endpoint, with the example identifying its Ollama-backed recorded run.

8. Reference

Drop me your questions related to Spring AI in the comments.

Happy Learning !!

Source Code on Github

Leave a Comment

Comments are closed.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.