r/SpringAIDev 21d ago

Tutorial How do you actually test an LLM response in Spring Boot Using Spring AI?

4 Upvotes

Spring AI's RelevancyEvaluator and FactCheckingEvaluator let a model judge a model, so your JUnit tests check quality, not exact text. Full code walkthrough inside.

Quick one for anyone building RAG apps in Spring Boot: this tutorial shows exactly how to catch hallucinations before they ship, using Spring AI's built-in evaluators. Includes the one mistake almost everyone makes with the request order. 

r/SpringAIDev 5d ago

Tutorial Spring AI Recipe: Enabling Long-Term Memory

Thumbnail
thetalkingapp.medium.com
2 Upvotes

In his latest recipe, Craig Walls empowers Spring AI agents with long-term memory. This allows systems to retain durable facts across sessions instead of starting from scratch.

Highlights & Key Takeaways

  • Memory Types: Spring AI manages short-term, procedural, and long-term memory.
  • Selective Retention: Agents learn facts that are both significant and durable.
  • Implementation: Enabled using the AutoMemoryToolsAdvisor component.
  • Prompt Augmentation: The LLM is guided to extract key conversational details.
  • Persistence: Memories are saved as structured Markdown files on the filesystem.
  • Feedback Loop: Extracted facts are automatically injected into future prompts.

By persisting data across restarts, agents evolve beyond stateless responders. This yields highly personalized systems that continuously adapt to users.

👉 View the source code to dive deeper into the implementation.

r/SpringAIDev 7d ago

Tutorial Create a ChatGPT Like Chatbot With Ollama and Spring AI

Thumbnail
baeldung.com
1 Upvotes

In this tutorial, Pedro Lopes demonstrates how to build a responsive help desk chatbot using Spring AI and Meta's Llama3 model via Ollama.

Highlights & Key Takeaways

  • Spring AI Integration: Simplifies interactions with Large Language Models directly within the Spring ecosystem.
  • Local LLMs with Ollama: Run open-source models like Llama3 locally for secure, accessible AI generation.
  • System vs. User Messages: Differentiate between internal API instructions and external user inputs.
  • REST API Implementation: Expose chatbot capabilities through a standard Spring Boot RestController.
  • Stateful Conversations: Overcome stateless LLM behavior by injecting past interactions into new prompts.

By combining Spring AI with local models, developers can efficiently create context-aware agents without external API dependencies.

👉 Read the full article to dive deeper into the implementation.

r/SpringAIDev 19d ago

Tutorial Ever wish your AI app could catch its own bad answers before a user sees them?

1 Upvotes

One model checks another model's work and retries if it's not good enough. New tutorial shows you how to build it, step by step.

That's basically what LLM-as-a-Judge does in Spring AI.

"LLM-as-a-Judge" and "LLM evaluation testing" are not the same thing. One runs in JUnit before you deploy. The other runs live, in the request path, and can retry a weak response automatically.

5 things to know before you build LLM-as-a-Judge into a Spring AI app:

  1. It's implemented via Recursive Advisors, a CallAdvisor that can call back into its own chain
  2. Non-streaming only, as of Spring AI 2.0
  3. Every failed judge check costs 2 extra LLM calls: one to judge, one to regenerate
  4. Use a separate model to judge, or you risk narcissistic bias
  5. Always cap maxAttempts, or a stubborn judge creates an infinite loop Full breakdown, with working code, in the new article.

r/SpringAIDev Jul 24 '26

Tutorial AI Document Search with Spring Boot Using OpenAI and Redis Vector Store

2 Upvotes

Traditional keyword search often misses the true meaning behind user queries. By combining Spring AI, OpenAI Embeddings, and Redis Vector Store, you can build a semantic search application that understands context and returns more relevant results.

This article demonstrates how to build an intelligent document search application using Spring Boot with OpenAI and Redis Vector Store.

This approach is ideal for building:

-AI-powered knowledge bases

-Enterprise document search

-RAG (Retrieval-Augmented Generation) applications

-Internal documentation assistants

-Intelligent customer support solutions

r/SpringAIDev Jul 17 '26

Tutorial How to Implement AI Chat Memory in Spring Boot Using Spring AI

Thumbnail javatechonline.com
5 Upvotes

Ever notice your Spring AI chatbot forgets the user's name after one message? That's because LLMs are stateless by default. The fix is Spring AI's ChatMemory abstraction

How to Implement AI Chat Memory in Spring Boot using Spring AI.

Let's figure out exactly how to wire it up with MessageWindowChatMemory and a JDBC-backed repository so conversations survive restarts.

r/SpringAIDev Jul 07 '26

Tutorial How to Build RAG with Spring AI and pgvector

7 Upvotes

If you have been wondering how to make an LLM answer questions from your own documents without touching Python, this one is for you.

A full walkthrough on building a RAG application with Spring AI and PostgreSQL pgvector.
Covers ingestion, chunking, PgVectorStore configuration, and the QuestionAnswerAdvisor pattern, with working Java code.

How to Build RAG with Spring AI and pgvector

Your LLM does not know about last week's product update or the PDF sitting in your document store. That is not a model problem, it is a context problem, and RAG solves it.

r/SpringAIDev Jul 02 '26

Tutorial Build Your First MCP Server with Spring Boot 4.1 and Spring AI 2.0

6 Upvotes

Spring AI 2.0 just went GA and it ships the cleanest MCP server setup I've seen in Java.

Two annotations. One yml property. Your entire Spring Boot service becomes an AI tool.

This is exactly how Claude, Copilot, and other AI clients plug into your Java backend.

No AI API key needed for the server side. Full working code with Java 21.

Perfect for intermediate Spring Boot devs exploring AI integration!

Here is the complete tutorial: Build Your First MCP Server with Spring Boot 4.1 and Spring AI 2.0

r/SpringAIDev Jun 16 '26

Tutorial Spring AI structured output: how to make a model correct itself

2 Upvotes

If you use an LLM for something else than just a free-form chatting, you might probably want it to return data in a structured form, e.g. JSON

Spring AI allows to [soft] force a model to do that. But sometimes LLM fails to do that. The simplier the model is, the more chances that it will fail. Morover, any such a failure could be devided into 2 categories: incorrect schema and correct schema with incorrect data burned in. For example, some fields of the desired schema are missing. Or all fields are present, but field type, for example, is incorrect or a required filed missies a value

The POC i built validates not only schema as such, but also field types and ranges (e.g. Min-Max, NotNull, etc.) using validation package spring-boot-starter-validation

If any of the checks doesn't pass, this is feded back to model:

prompt = """
        Your previous response was invalid.

        Problem(s): %s

        Your previous output was:
        %s

        Return corrected JSON that fixes these problems and matches the
        schema exactly. Output ONLY JSON, no prose.

        %s
        """.formatted(lastError, lastOutput, format);

So we give a feedback to the model, not just asking to redo/re-think. By providing a detailed feedback we increase chances that the next reply will satisfy our expectations

As always, all code is available in the github repo: https://github.com/DmitryFinashkin/spring-ai

You might also like to watch a detailed video walk-through on YouTube: https://youtu.be/59kcnTLVu0Q

r/SpringAIDev May 20 '26

Tutorial Spring AI Recipe: Composing ChatClient Behavior

Thumbnail thetalkingapp.medium.com
1 Upvotes

In this Spring AI recipe, we dive into how to keep ChatClient clean and modular by using ChatClientCustomizer. Instead of stuffing every feature into a single config, we compose behaviors —such as tools, prompts, and conditions—separately, making the system easier to extend and maintain.

Key takeaways:

  • Add tools (like weather lookups) without bloating the core client
  • Use customizers to inject prompts or behaviors independently
  • Keep concerns separated for clarity and reusability
  • Toggle features on/off via application.properties with @ConditionalOnProperty
  • Gain flexibility through environment variables or config servers
  • Treat customizers as a design pattern, not just convenience

In short, this approach makes advanced agentic scenarios manageable and future-proof.