Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
# Build AI Applications with Spring AI — Reading Guide
## 【One-Line Pitch】
A practical, code-first guide for Java developers who want to build AI-powered applications using Spring AI 1.1.0, covering everything from chat completions and streaming to RAG pipelines and vector stores. If you're a Spring Boot developer looking to integrate LLMs into your existing stack, this book is your hands-on roadmap.
## 【Book Arc】
- **Opening (~0%–10%)**: Sets up the development environment — Java 17+ (recommended Java 21/25 for virtual threads), Spring AI 1.1.0 with Maven and the spring-ai-bom, and local LLM setup using Docker with models like Qwen3-0.6B. Establishes the core abstractions: ModelRequest, ModelResponse, and the generic model API.
- **Early (~10%–23%)**: Dives into chat completion fundamentals — ChatOptions (temperature, topP, maxTokens, stop sequences), Generation and ChatResponseMetadata (rate limits, finish reasons), and the fluent ChatClient API for building prompts. Introduces PromptTemplate with TemplateRenderer for dynamic prompt rendering and the Advisor chain for intercepting requests/responses.
- **Early (~23%–32%)**: Explores advanced chat patterns — advisor ordering with Spring's Ordered interface, recursive advisors (new in 1.1) for agent loops like evaluator-optimizer, and streaming chat with Server-Sent Events (SSE) including event types like MessageStreamingStartEvent and TokenUsageEvent.
- **Early (~32%–39%)**: Covers structured output conversion — ListOutputConverter, MapOutputConverter, and BeanOutputConverter for turning LLM text responses into typed Java objects using Spring's ConversionService.
- **Middle (~39%–48%)**: Shifts to RAG fundamentals — embedding models (EmbeddingModel, EmbeddingOptions, BatchingStrategy), document handling (TextReader, JsonReader, Document Transformer/Writer), and vector stores as the semantic backbone for similarity search.
- **Middle (~48%–end)**: Completes the RAG picture — vector store operations (add, delete, similarity search), filter expressions (Filter.Expression with AND/OR composition), SimpleVectorStore and Pgvector implementations, cloud vector store options, and the full RAG pipeline from simple to modular architectures (query, pre-retrieval, retrieval, post-retrieval, generation).
## 【Key Takeaways】
- **Java 17+ with virtual threads is the baseline** (Opening): Spring AI 1.1.0 requires Java 17 minimum, but Java 21/25 unlocks virtual threads for better concurrency. Use the spring-ai-bom for dependency management to avoid version conflicts.
- **ChatClient is the primary entry point** (Early): The fluent API lets you build prompts with user/system messages, set options, and call or stream responses. You can pass an existing Prompt object or build one inline with methods like `user()`, `system()`, and `options()`.
- **Advisors enable cross-cutting concerns** (Early): The Advisor chain runs before and after model calls, perfect for logging, caching, or modifying requests. Order matters — use values greater than 0 to avoid conflicts with built-in advisors. Spring AI 1.1's recursive advisors enable repeated execution for agent patterns.
- **Streaming requires SSE and event handling** (Early): Use Flux<ServerSentEvent> for real-time chat responses. The event stream includes start/complete markers and token usage events, letting you build responsive UIs with JavaScript's EventSource.
- **Structured output converters tame LLM responses** (Early): ListOutputConverter, MapOutputConverter, and BeanOutputConverter transform free-text LLM output into typed Java objects, making AI responses safe to use in business logic.
- **RAG reduces hallucinations by grounding responses** (Middle): Convert documents to embeddings, store them in a vector store, retrieve similar content at query time, and combine with a prompt template that instructs the model to answer from provided context only.
- **Vector stores are the backbone of RAG** (Middle): Documents are stored as vectors, not raw text. Filter expressions (e.g., source=db AND lastUpdatedAt>yesterday) let you narrow searches. SimpleVectorStore works for testing; Pgvector and cloud services scale to production.
- **Document readers handle multiple formats** (Middle): TextReader and JsonReader parse resources into Document objects, with JsonMetadataGenerator for enriching metadata. This is the ingestion layer that feeds your vector store.
## 【Reading Tips】
- **Skim the environment setup (Opening)**: If you already have Java and Docker, jump straight to the chat completion chapters. The Docker Compose for local LLM serving is useful but not the core value.
- **Deep-read the ChatClient and Advisor chapters (Early)**: These are the most reusable patterns. The logging advisor example is worth copying verbatim — it's a debugging lifesaver for seeing exactly what goes to and from the model.
- **Pay attention to the streaming event model (Early)**: The four-event sequence (start, deltas, token usage, complete) is a clean pattern you'll want to replicate. Don't skip the HTML/JavaScript example — it shows the full client-server loop.
- **Focus on the RAG pipeline chapters (Middle)**: The progression from naive to modular RAG is the book's payoff. Understand the pre-retrieval (query rewriting), retrieval (vector search), and post-retrieval (reranking) stages before implementing.
- **Use the code samples as templates**: The REST controllers for vector stores and streaming are production-ready patterns. Adapt them rather than writing from scratch.
## 【Coverage Limits】
This guide covers the book's core content on chat completion, streaming, structured output, and RAG with vector stores. Excerpts do not cover image understanding, advanced agent patterns, or cloud deployment specifics in detail — those sections are listed in the table of contents but not sampled here.
##
advisors Set Advisors options Set ChatOptions in the prompt toolNames Set names of registered tools tools Add a tool Methods in the above table may have serv...
This vector is the semantic representation of the content. When querying similar documents for the given query, the query is also converted into a vector usi...
ines all modular RAG components mentioned before, including RAG Examples 120 Database Metadata JDBC provides an API to get metadata from a database. We can u...
is a Map, and the values in the map are the sub-properties. The implementation of the tool is shown below. In the description of the tool, the json schema of...
fer additional information. Annotations has two attributes. • The audience of type List<Role> represents the target roles of the annotation. It can contain m...
model should stop generating further tokens in the output. • metadata of type Map<String, Object> represents additionalmetadata. CreateMessageRequest provide...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
Build AI Applications with Spring AI (Fu Cheng)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share to WeChat Moments
Build AI Applications with Spring AI (Fu Cheng)(Z-Library)
Scan the QR code with WeChat to open this book
Tap the ··· menu in the top-right corner
Choose Share to Moments
You are already in WeChat. Tap ··· in the top-right corner and choose Share to Moments.
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
Build AI Applications with Spring AI (Fu Cheng)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
这本书围绕如何使用 Spring AI 构建 AI 应用展开,内容从基础接口讲到完整的功能模块,适合想了解 Spring AI 整体开发路径的读者。全书的主线是:先建立对核心抽象的认识,再逐步进入具体能力的实现。开篇部分给出了全书目录的轮廓,可以看到图像理解、检索增强生成等主题都在讨论范围之内,说明本书并不局限于单一功能,而是覆盖了多种 AI 应用场景。
沿着这条主线,读者可以抓住几条关键线索。第一条是模板渲染机制。书中介绍了 TemplateRenderer 接口,它继承自 BiFunction,接收字符串和 Map 参数并返回渲染后的模板内容,这构成了提示词组织的基础设施。第二条是向量与检索。摘录提到嵌入向量会被存入向量数据库,提示词的内容同样通过相同的嵌入模型转换为向量,再与参考文档的向量做相似度比较,这正是检索增强生成的核心思路。书中还提到模块化的 RAG 组件,以及利用 JDBC 提供的 API 从数据库提取元数据,说明检索增强并不只是向量比对,还涉及数据源的组织。第三条是模型交互的细节。摘录中出现频率惩罚参数、停止生成 token 的条件,以及带有附加元数据的 CreateMessageRequest 及其构建...
Digital LibraryAI Assistant
Hi — I can help you pick a book. Tell me a topic, language, or level, e.g. “a light English read”. If that's too broad, I'll ask one follow-up.
Loading comments...
Reply to Comment
Edit Comment