liveBook · Manning

What you will learn in Spring AI in Action

by Craig Walls
Foreword by Rod Johnson

Chapter by chapter

Chapter 1: Getting started with Spring AI

The introduction explains what generative AI offers users and developers, and why Spring AI makes it accessible in Java applications.

1.1 Hello, Spring AI! · 1.1.1 Initializing the project · 1.1.2 Submitting prompts · 1.1.3 Writing a test · 1.1.4 Trying it out · 1.2 Choosing a model · 1.2.1 Configuring OpenAI models · 1.2.2 Serving models locally with Ollama · 1.3 Previewing Spring AI’s capabilities · 1.4 Summary

What you learn in chapter 1 →

Chapter 2: Evaluating generated responses

This introduction explains why ordinary assertions and mocked responses cannot fully test generative AI behavior, then introduces Spring AI evaluators as a way to judge generated answers.

2.1 Ensuring relevant answers · 2.2 Testing for factual accuracy · 2.3 Applying self-evaluation at runtime · 2.4 Summary

What you learn in chapter 2 →

Chapter 3: Submitting prompts for generation

The chapter introduction explains why more advanced Spring AI applications may need richer prompt and response handling than simple strings.

3.1 Working with prompt templates · 3.1.1 Defining a prompt template · 3.1.2 Importing the template as a resource · 3.2 Stuffing the prompt with context · 3.3 Assigning prompt roles · 3.4 Influencing response generation · 3.4.1 Specifying chat options · 3.4.2 Formatting response output · 3.4.3 Streaming the response · 3.5 Working with response metadata · 3.6 Summary

What you learn in chapter 3 →

Chapter 4: Talking with your documents

The introduction explains why giving an LLM relevant document content when a question is asked can improve answers beyond what its training alone supports.

4.1 Understanding RAG · 4.2 Setting up a vector store · 4.3 Loading documents · 4.3.1 Initializing the loader project · 4.3.2 Defining the loader pipeline · 4.3.3 Creating the pipeline components · 4.3.4 Running the pipeline · 4.4 Implementing RAG · 4.4.1 Searching for similar documents · 4.4.2 Updating the service · 4.5 Implementing RAG with an advisor · 4.6 Applying modular RAG · 4.6.1 Rewriting the user’s query · 4.6.2 Translating user queries · 4.6.3 Expanding user queries · 4.7 Summary

What you learn in chapter 4 →

Chapter 5: Enabling conversational memory

This introduction explains why an LLM’s lack of memory makes follow-up conversation difficult.

5.1 Making memories in AI · 5.2 Adding conversational memory · 5.2.1 Enabling an in-memory chat advisor · 5.2.2 Inspecting the prompt for chat memory · 5.2.3 Configuring chat memory size · 5.3 Specifying the conversation ID · 5.4 Enabling persistent chat memory · 5.4.1 Persisting chat memory to a database · 5.4.2 Storing chat memory in a vector store · 5.5 Summary

What you learn in chapter 5 →

Chapter 6: Activating tool-driven generation

The introduction explains why an LLM may need tools to obtain real-time information that training and RAG cannot supply.

6.1 Getting started with AI tools · 6.1.1 Developing a tools-enabled application · 6.1.2 Digging deeper · 6.2 Implementing tools · 6.2.1 Writing the tool’s foundations · 6.2.2 Defining the tool · 6.2.3 Putting the tool to work · 6.3 Enables functions as tools · 6.4 Summary

What you learn in chapter 6 →

Chapter 7: Applying Model Context Protocol

Introduces MCP as a way to package related tools for sharing across AI applications, in contrast to coding tools into one Spring AI application.

7.1 Introducing Model Context Protocol · 7.2 Working with MCP Clients · 7.3 Creating your own MCP Server · 7.3.1 Building the server · 7.3.2 Setting up the database · 7.3.3 Creating the MCP Server tools · 7.3.4 Inspecting the MCP Server · 7.3.5 Using the server in a client application · 7.4 Working with the HTTP+SSE transport · 7.4.1 Configuring an HTTP+SSE in the MCP Server · 7.4.2 Inspecting the MCP Server · 7.4.3 Configuring the client to use an HTTP+SSE server · 7.5 Exposing prompts and resources · 7.5.1 Declaring prompt and resource-exposing beans · 7.5.2 Applying annotation-driven prompts and resources · 7.6 Summary

What you learn in chapter 7 →

Chapter 8: Generating with voice and pictures

The introduction explains why moving beyond text-only interaction would make Board Game Buddy more natural for people to use.

8.1 Working with voice · 8.1.1 Transcribing speech · 8.1.2 Generating speech from text · 8.1.3 Applying audio input and output directly · 8.2 Asking questions about images · 8.3 Generating images · 8.3.1 Specifying image options · 8.4 Summary

What you learn in chapter 8 →

Chapter 9: Observing AI operations

The introduction explains why observing application metrics and tracing data helps reveal the health and behavior of a Spring AI application.

9.1 Enabling Actuator metrics · 9.1.1 Inspecting vector store operations · 9.1.2 Examining AI model interaction · 9.1.3 Counting token usage · 9.1.4 Observing ChatClient operations · 9.2 Viewing metrics in Prometheus · 9.3 Creating AI dashboards · 9.4 Tracing AI operations · 9.5 Summary

What you learn in chapter 9 →

Chapter 10: Safeguarding generative AI

The introduction explains why generative AI applications must protect access to documents and tools and guard against prompts that elicit sensitive responses.

10.1 Controlling document access with RAG · 10.1.1 Designating premium content · 10.1.2 Adding security to Board Game Buddy · 10.1.3 Filtering for premium content · 10.1.4 Applying per-user conversational memory · 10.1.5 Trying it out · 10.2 Securing tools · 10.3 Safeguarding against adversarial prompting · 10.3.1 Preventing prompts with sensitive terms · 10.3.2 Preventing prompt leaks · 10.4 Moderating user input · 10.5 Summary

What you learn in chapter 10 →

Chapter 11: Applying generative AI patterns

This introduction explains that Spring AI’s ChatClient can do more than answer questions, with the task shaped largely by the prompt.

11.1 Summarizing content · 11.2 Translating messages · 11.2.1 Building a simple translator · 11.2.2 Translating game rule answers · 11.3 Analyzing sentiment · 11.4 Summary

What you learn in chapter 11 →

Chapter 12: Employing agents

Introduces generative AI agents as goal-oriented actors while noting that their precise definition is debated.

12.1 Understanding agents · 12.2 Implementing agentic workflows and patterns · 12.2.1 Chaining prompts · 12.2.2 Routing tasks · 12.2.3 Applying parallelization · 12.3 Creating self-planning agentic solutions · 12.3.1 Initializing an Embabel project · 12.3.2 Defining the agent class · 12.3.3 Defining an action to get game rules · 12.3.4 Defining an action to get the rules filename · 12.3.5 Defining an action to get the game title · 12.3.6 Running the agent via Embabel’s shell · 12.3.7 Accessing the agent via MCP · 12.4 Summary

What you learn in chapter 12 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.