: A specific demonstration of Retrieval-Augmented Generation (RAG) using Spring AI with PDF documents as data sources. Key Resources & Blog Posts Reference Documentation : Currently, there is no official PDF download

To help tailor this guide further, let me know if you are interested in a (like Ollama or Azure), want to see a full PDF ingestion RAG pipeline , or need help troubleshooting a specific configuration error . Share public link

Codebases demonstrating the use of PdfReader alongside automated vector indexing tools.

habuma/spring-ai-in-action-examples : Contains the code exactly as it appears in the book (Spring AI 1.0.x).

The ChatModel interface is the programmatic heart of Spring AI. It handles the request-response lifecycle with generative text models. The newer, fluent ChatClient API provides a builder-style pattern to construct prompts, manage system instructions, and handle contextual memory efficiently. Prompts and Output Parsers

Prompts are the inputs passed to the AI model. Spring AI provides a structured Prompt class that encapsulates a collection of Message objects (System, User, Assistant). PromptTemplate allows for dynamic string manipulation using placeholders, ensuring clean separation between prompt logic and application data. 3. Structured Outputs

: Reviewers on Amazon and LinkedIn highlight Craig Walls' "relentless emphasis on getting stuff done," noting the book's clear-cut explanations and wonderful demos.

package com.example.ai.service; import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.document.Document; import org.springframework.ai.reader.tika.TikaDocumentReader; import org.springframework.ai.transformer.splitter.TokenTextSplitter; import org.springframework.ai.vectorstore.VectorStore; import org.springframework.ai.vectorstore.SearchRequest; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; import java.util.List; import java.util.stream.Collectors; @Service public class KnowledgeBaseService private final VectorStore vectorStore; private final ChatClient chatClient; public KnowledgeBaseService(VectorStore vectorStore, ChatClient.Builder chatClientBuilder) this.vectorStore = vectorStore; this.chatClient = chatClientBuilder.build(); // Ingest a PDF file into the vector database public void ingestPdf(Resource pdfResource) TikaDocumentReader reader = new TikaDocumentReader(pdfResource); List rawDocuments = reader.get(); TokenTextSplitter splitter = new TokenTextSplitter(); List splitDocuments = splitter.apply(rawDocuments); this.vectorStore.accept(splitDocuments); // Query the system using RAG public String answerQuery(String userQuery) // Retrieve relevant context pieces from the database List similarDocuments = this.vectorStore.similaritySearch( SearchRequest.query(userQuery).withTopK(4) ); String context = similarDocuments.stream() .map(Document::getContent) .collect(Collectors.joining("\n")); // Ask the LLM to generate an answer based purely on the context return this.chatClient.prompt() .system(sp -> sp.text(""" You are an expert enterprise assistant. Answer the user question based only on the provided context. If you do not know the answer from the context, say 'I cannot find that in the documents.' Context: context """).param("context", context)) .user(userQuery) .call() .content(); Use code with caution. 5. Structuring a Production GitHub Repository

The landscape of enterprise Java development is shifting. For years, Spring Framework has been the undisputed king of dependency injection, web MVC, and data access. But 2023 and 2024 brought a tidal wave of Generative AI—Large Language Models (LLMs) like GPT-4, Gemini, and Llama. The question on every Spring developer’s lips became: How do I integrate AI into my existing Spring Boot applications without rewriting everything from scratch?

: The official code repository for the book. It includes branches for different versions, such as Spring AI 1.1.0 and the main branch aligned with Spring AI 1.0 Spring AI in Action Samples : A placeholder repository managed by the author, Craig Walls (habuma)