AI for Java Developers
Building Intelligent Applications with Spring AI
Dan Vega - Spring Developer Advocate @Broadcom
https: [Link]/blog/
/
/
Introduction
About Me
Learn more at [Link]
🧑🧑🧒🧒 Husband & Father
🏠 Cleveland
☕ Java Champion
🧑💻 Software Development 23 Years
🍃 Spring Developer Advocate
📖 Author (Soon to be)
https: [Link]
/
/
[Link]
Agenda
What we will cover in this course
Agenda
What we will NOT cover in this course
How to get the most out of this course
• Use timestamps - Jump to speci c topics as • Keep a learning journal - Note ideas for your own
needed projects as you watch
• Access all resources - Links, documentation, • Watch in segments - One section per day for better
and code samples provided retention
• Learn → Build → Share - Apply each concept • Prepare your environment rst - Have API keys
immediately in your own project and tools ready before starting
• Code along actively - Don't just watch, open • Build a portfolio project - Create one substantial
your IDE and follow along AI-powered app by course end
• Pause and experiment - Try variations of the • Cross-reference documentation - Keep Spring AI
examples shown docs open while watching
• Join the Spring AI community - Ask questions • Share your progress - Tweet/post about what
and share your implementations you're building for accountability
• Start with simple use cases - Build a basic • Focus on your domain - Think how each feature
chatbot before complex features applies to your speci c industry/work
fi
fi
fi
Prerequisites and resources
Prerequisites
• Familiar with the Java programming Language
• Familiar with Spring (but not Spring AI)
• IDE (IntelliJ)
Resources
• [Link]
• [Link]
• [Link]
What is artificial intelligence (AI)
MACHINE LEARNING
Machine Learning
Unlike traditional programming, where explicit instructions are provided for
every scenario, ML systems learn patterns from data, allowing them to make
predictions or decisions without being explicitly programmed for each possibility.
Machine Learning
Machine Learning encompasses various techniques and types of tasks, including:
Machine Learning
Use Cases
• Facial Recognition
• Recognize Tumors on x-ray scans
• Abnormality on ultrasounds
• Self-drive mode
• Fraud Detection
• Credit Score / Loan Approval
• Product Recommendations (YouTube)
• Spam Filtering
• Search Ranking
Supervised Learning
Labeling the training data
DEEP LEARNING
Deep learning and neural networks
NEURAL NETWORKS
What makes deep learning powerful?
• The rst layer mi ht detect ed es
• The next layer mi ht reco nize
shapes
• Deeper layers could identify more
complex features like eyes or wheels
• The nal layer puts it all to ether to
classify the entire ima e
fi
fi
g
g
g
g
g
g
Artificial neural network
• Scienti c Advances - Deep
Learnin
• Availability of Bi Data (You
need data to con ure these
neural networks)
• Lots of compute power
fi
g
fi
g
g
Large language models (llm)
Attention is all you need
The Foundation: Attention Mechanisms
• Introduced in 2017 with the transformer, a
breakthrou h in AI that chan ed how
machines process lan ua e
• The key innovation: Attention
Mechanisms allow models to understand
context by focusin on the relevant parts
of text, similar to how humans read
• This laid the roundwork for more
powerful lan ua e models
g
g
g
g
g
g
g
g
How Transformers work
Transformer Architecture
• A specialized neural network desi ned for
understandin lan ua e
• Uses attention mechanism to wei h the
importance of words in context
• Can process entire sentences at once,
understandin relationships between
words
g
g
g
g
g
g
How do LLMs actually work?
[976, 9059, 10139, 402, 290]
How LLMs Learn
The Training Process
Generative AI
Generative Pre-trained Transformer (GPT)
• Now that we understand:
• Transformers provide the architecture (how they process lan ua e)
• Pre-trainin on vast amounts of data teaches lan ua e understandin
• Generative capability allows them to create new content
• Key Capabilities:
• Text eneration (writin , translation, summarization)
• Code eneration and analysis
• Complex reasonin and problem-solvin
g
g
g
g
g
g
g
g
g
g
g
Prompt engineering
Prompt engineering
Learn how to effectively communicate with AI
• Clear communication is key - just like with
humans
• Structure determines success - ivin
context, examples and speci c instructions
• Think of it as teachin , not commandin
• Bad Prompt: “Write a blo post about AI”
• Good Prompt: “Write a technical blo post
explainin neural networks to junior
developers, focusin on practical examples.
g
g
g
g
fi
g
g
g
g
Clear communication is key
Bad Prompt:
•Write some Java code for sorting
Good Prompt:
Write a Java method that sorts an ArrayList of Employee
objects by their salary in descending order. Include error
handling for null inputs.
The 2nd prompt gives AI everything it needs
Structure determines success
Bad Prompt:
•Explain database indexing
Good Prompt:
As an experienced Java developer, explain database indexing in 3 parts:
1. What indexes are and why they matter for performance
2. When to use clustered vs non-clustered indexes
3. One practical example of creating an index in PostgreSQL
Keep each section to 2-3 sentences and include one code example.
Advanced techniques
• Zero-shot Promptin : Will not contain
examples or demonstrations
• One-shot promptin : Providin a sin le
example
• Few-shot promptin : Providin Examples
• Chain-of-Thou ht: Think step by step
• XML Ta s: help structure complex requests by
clearly separatin different types of
information
• Task Decomposition: Breakin complex
problems into steps
g
g
g
g
g
g
g
g
g
g
Zero-shot prompting
is asking the AI to perform a task without providing any examples. There is
nothing wrong with this approach and there are times when this will give
you exactly what you are looking for.
Create a Java class that implements the Observer pattern
for a stock price monitoring system.
one-shot prompting
provides a single example to establish a pattern you would like the AI to follow:
Here's an example of the coding style I prefer:
public Optional<User> findUserByEmail(String email) {
if (email null [Link]().isEmpty()) {
return [Link]();
return [Link]([Link]());
}
/
/
=
=
|
|
Few-shot prompting
provides multiple examples to guide the AI’s response.
Classify the sentiment of these customer reviews:
Example 1: "The software is intuitive and saves me hours of work" → Positive
Example 2: "Great documentation and excellent support team" → Positive
Example 3: "Buggy interface and crashes frequently" → Negative
Now classify: "The new features are helpful but the UI is confusing"
Chain-of-thought prompting
Bad Prompt:
•Optimize this code. [paste your code here]
Good Prompt:
I need to optimize this Java method that searches through a large dataset.
First, help me identify the current time complexity. Then suggest specific
improvements. Finally, show me the refactored code with comments explaining
the performance gains.
[paste your code here]
XmL tags
help structure complex requests by clearly separating different types of
information.
Task decomposition
breaks down complex problems into manageable pieces.
I'm building a file processing system in Java. Help me break this down:
Phase 1: Design the file reading strategy (stream vs batch)
Phase 2: Create the data validation logic
Phase 3: Implement error handling and logging
Phase 4: Add unit tests
Start with Phase 1 - analyze the pros and cons of each approach for processing 1GB+
files.
Practical tips for immediate improvement
• Be Speci c About Context: Always provide relevant background information. If you're working on a Spring Boot application,
mention it. If you're dealing with legacy code, say so.
• Use Examples: Show the AI what good output looks like. If you want code formatted a certain way, provide an example.
• Give Context About Your Environment: Mention your Java version, frameworks you're using, or constraints you're working
within.
• Specify a Role When Applicable: Give the AI a speci c persona or expertise to embody. For example, "Act as a senior Java
architect reviewing this code" or "As a performance optimization expert, analyze this query." This helps frame the response
with the appropriate level of detail and perspective.
• Iterate and Re ne: Don't expect perfection on the rst try. Use the AI's response to re ne your prompt and get closer to your
desired output.
• Use AI to Improve Your Prompts: When you're not getting the results you want, ask the AI to help you craft a better prompt. Try
something like: "I'm trying to get you to help me debug this performance issue, but your response wasn't quite what I needed.
Can you suggest how I should rephrase my request to get more speci c debugging steps?"
• Save Good Prompts: When you craft a prompt that works well, save it. You'll likely need similar requests in the future.
fi
fi
fi
fi
fi
fi
https: [Link]/
http: [Link]/3ZVD7T5
https: [Link]/examples/gpt4-1_prompting_guide
/
/
/
/
/
/
Prompting with your voice
macOS Dictation
Settings > Keyboard > Dictation
Java & AI
Java & AI
Leveraging Arti cial Intelligence in Java Applications
• Why AI + Java?
• The world of software is experiencin widespread adoption of Arti cial
Intelli ence
• Java is the lan ua e of enterprises, creatin Java + AI apps is a new requirement
• Sprin AI
• Provides the necessary API access and components for developer AI applications
• Abstraction similar to Sprin Data
• Use Cases
• Q&A Over docs
• Documentation Summarization
• Text, Code, Ima e, Audio and Video Generation
g
g
g
g
g
g
fi
g
g
fi
/bin/bash
echo "Calling Open AI "
MY_OPENAI_KEY=“YOUR_API_KEY_HERE”
PROMPT=“Tell me an interesting fact about Java"
curl https: [Link]/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MY_OPENAI_KEY" \
-d '{"model": "gpt-4o", "messages": [{"role":"user", "content": "'"${PROMPT}"'"}] }'
#
!
/
/
.
.
.
{
"id": "chatcmpl-ABNbjZ5oRbo72OevnCX2arPufJCYK",
"object": "[Link]",
"created": 1727275719,
"model": "gpt-4o-2024-05-13",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Sure! Did you know that Java was initially designed with interactive television in mind? James Gosling
and his team at Sun Microsystems started the project in 1991 under the name \"Oak.\" The name was later changed to
\"Java\" after discovering there was already a programming language called Oak. Java's versatility has made it one of the
most popular programming languages for a wide range of applications, far beyond its initial intended use for TV set-top
boxes!",
"refusal": null
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 14,
"completion_tokens": 90,
"total_tokens": 104,
"completion_tokens_details": {
"reasoning_tokens": 0
}
},
"system_fingerprint": "fp_e375328146"
}
public static void main(String[] args) throws IOException, InterruptedException {
var apiKey = "YOUR_API_KEY_HERE";
var body = """
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Tell me an interesting fact about Java"
}
]
}""";
HttpRequest request = [Link]()
.uri([Link]("https: [Link]/v1/chat/completions"))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + apiKey)
.POST([Link](body))
.build();
var client = [Link]();
var response = [Link](request, [Link]());
[Link]([Link]());
}
/
/
Spring AI provides us so much
More than a facility for
Making rest api calls
Spring ai
Spring ai
AI for Spring Developers
• [Link] .io/projects/sprin -ai
• Dr. Mark Pollack
• Current Version 1.0.0
• Portable API support across AI providers
for Chat, Ima e & Audio
• Synchronous & Streamin API options
• Inspired by Python Projects
• Lan Chain
• LllamaIndex
g
g
g
g
g
Getting started
Getting started
• Signing up for an API Key - OpenAI
• Signing up for multiple keys if you want to run multiple modals
• Setting an environment variable
• [Link]
• Chat Client & Chat Model
• Blocking vs Non Blocking (Streaming Responses)
• Response Types
• Using Multiple Modals in the same application
Llm pricing
Model Context window Pricing
GPT-4.1 (OpenAI) 1 M tokens $2.00 / $8.00
GPT-4.1 Mini (OpenAI) 1 M tokens $0.40 / $1.60
GPT-4.1 Nano (OpenAI) 1 M tokens $0.10 / $0.40
o4-mini (OpenAI) 128 k tokens $0.60 / $2.40
Gemini 2.5 Pro (Google) 1 M tokens (2 M rolling out) $1.25 / $10.00 (≤ 200 k prompt)
Gemini 2.5 Flash (Google) 1 M tokens $0.15 / $0.60 (non-thinking)
Gemini 1.5 Pro (Google) 2 M tokens $1.25 / $5.00 (< 128 k prompt)
GPT-4.5 Preview (OpenAI) 128 k tokens $75 / $150
Claude 3.7 Sonnet (Anthropic) 200 k tokens $3.00 / $15.00
GPT-4o (OpenAI) 128 k tokens $5.00 / $20.00
o3-mini (OpenAI) 200 k tokens $1.10 / $4.40
o3-mini-high (OpenAI) 200 k tokens $1.10 / $4.40
Gemini 2.0 Flash (Google) 1 M tokens $0.10 / $0.40
Gemini 2.0 Flash-Lite (Google) 1 M tokens $0.075 / $0.30
Grok 3 (xAI) 1 M tokens $3.00 / $15.00
Latest Models:
• GPT-4.1 - The agship multimodal model with major improvements in coding and instruction following, supporting up to 1 million tokens of context
• GPT-4.1 mini - Fast, affordable version performing almost as well as GPT-4.1 at 1/5th the price
• GPT-4.1 nano - The fastest and cheapest model for low-latency tasks
• GPT-4.5 - Research preview of their strongest GPT model (being deprecated in July 2025)
Reasoning Models:
• o3 - Most powerful reasoning model for logical, technical, and scienti c tasks
• o4-mini - Most powerful small reasoning model, almost as powerful as o3 at 1/10th the price
• o3-mini (2025-01-31) - Latest reasoning model with enhanced reasoning abilities
Specialized Models:
• GPT-image-1 (2025-04-15) - Latest image generation model with major improvements over DALL-E
• gpt-4o-audio-preview - Model for audio generation and voice-based interactions
• Sora - Video generation model for creating videos from text prompts
Latest Models:
• Gemini 2.5 Pro - Most intelligent AI model with "thinking" capabilities and enhanced reasoning
• Gemini 2.5 Flash - Ef cient workhorse model designed for speed and low cost, improved across reasoning, multimodality, and code
• Gemini 2.5 Pro Deep Think - Experimental enhanced reasoning mode for highly complex math and coding
Current Generation:
• Gemini 2.0 Flash - Multimodal model with native image generation and text-to-speech capabilities
• Gemini 2.0 Pro - Released February 5, 2025
• Gemini 2.0 Flash Thinking Experimental - Shows the model's thinking process when responding
Legacy Models:
• Gemini 1.5 Pro and Gemini 1.5 Flash (note: starting April 29, 2025, these are not available in new projects)
Latest Models (Claude 4 Family):
• Claude Opus 4 - Most powerful model, described as "the best coding model in the world" capable of working autonomously for up to 7 hours
• Claude Sonnet 4 - Smart, ef cient model for everyday use, designed as a drop-in replacement for Sonnet 3.7 with improved coding and instruction following
Previous Generation:
• Claude Sonnet 3.7 - Previous agship model
• Claude Haiku 3 - Fastest, most compact model
fl
fi
fi
fl
fi
# Criterion Questions to Ask Typical Signals / How to Test
- Quick manual prompts - does it “sound” right?-
• Does the model already solve your task (chat, code-gen, doc QA, …)?
1 Task Fit Search papers/blogs for domain evals.- Try small-
• Is there evidence on similar domains?
scale eval harness with 10–20 gold answers.
Check open leaderboards (Hugging Face, LM); run
• Are there recent third-party numbers on tasks that resemble yours?
2 Quality & Benchmarks LM-Eval-Harness / OpenAI Evals yourself.
• Has the vendor cherry-picked?
Benchmarks age fast, so prefer ones < 3 mo old.
• Minimum tokens your prompt + docs require? Hard cut-off → disqualify below the needed
3 Context Window
• Do you anticipate growth (RAG, code)? window.
4 Latency & Throughput • User-facing? batch background? real-time streaming? Measure end-to-end. Compare latency & tokens/sec.
• Budget per request / month?
API $/1K tokens vs. GPU TCO (open-source on-prem).
5 Cost & Licensing • Can you cache or ne-tune cheaper model?
Total Cost of Ownership often outweighs raw $/token.
• OSS licensce compatible with your product?
• Can data leave VPC? If “no cloud” → shortlist local OSS (e.g., Llama 3) or
6 Privacy / Data Residency
• PII, trade secrets? vendor’s private endpoints.
7 Integration & Tooling • Supports function/tool calling, JSON mode? Verify in docs / quick code snippet.
• SLAs? rate-limit ceiling? Vendor contracts, community activity, GitHub issues
8 Governance & Support
• Security posture & audits? velocity.
fi
Check out my demo
Spring AI features
Spring AI Features
• Spring AI Reference Documentation
• Prompts & Prompt Templates
• Structured Output
• Multimodal (Text, Images & Audio)
• Chat Memory
Check out my demo
Llm limitations
Why do we care?
🛠
Limitation Quick Note — “what this looks like”
🧠✨ Hallucinate Invents facts or API names with total confidence
🕒 Stale Data Knowledge cutoff means “today’s stock price?” → ¯\_(ツ)_/¯
⚖ Bias & Safety Outputs stereotypes, toxic language, or policy violations
🏗 Domain Gaps Uses generic wording where niche jargon is required
📏 Context Window Long threads get truncated; model “forgets” earlier details
🎲 Non-Determinism Same prompt, different answer → flaky tests, review churn
🔒 Privacy Leak Proprietary/PII text could leave your trusted boundary
💰⏱ Cost & Latency High-token chains drain budget and slow UX
🧩 Weak Reasoning Multi-step calculations or logical deductions fail
🔍 Low Explainability Hard to audit: “Why did you choose that answer?”
LLm Limitations
Here’s our Swiss-army lineup for taming any limitation
# Lever Purpose
Encode rules that constrain the model’s behavior (tone, honesty,
1 🛡 Prompt Guarding
refusal policy).
Inject fresh, task-speci c context so the model quotes facts instead
2 📄 Prompt Stuf ng / RAG
of guessing.
Let the model invoke code or APIs for real-time data, calculations,
3 🔧 Tools / Function Calling
or business logic.
Package those tools as reusable, versioned endpoints every client
4 🌐 MCP (Resources + Tools)
can share.
fi
fi
Prompt guarding
Prompt stuffing
Retrieval augmented generation (RAG)
Tools / function calling
Tool calling / function calling
Tool calling / function calling
public class DatTimeTools {
@Tool(description = "Get the current date and time in the user's timezone")
String getCurrentDateTime() {
return [Link]().atZone([Link]().toZoneId()).toString();
}
}
@RestController
public class DatTimeChatController {
private final ChatClient chatClient;
public DatTimeChatController([Link] builder) {
[Link] = builder
.build();
}
@GetMapping("/tools")
public String tools() {
return [Link]("What day is tomorrow?")
.tools(new DatTimeTools())
.call()
.content();
}
}
Model context protocol (MCP)
Why MCP?
MCP helps you build agents and complex work ows on top of LLMs. LLMs
frequently need to integrate with data and tools, and MCP provides:
• A growing list of pre-built integrations that your LLM can directly plug into
• The exibility to switch between LLM providers and vendors
• Best practices for securing your data within your infrastructure
fl
fl
Transports
Standard Input/Output (stdio) Server-Sent Events (SSE)
• Use stdio when: • Use SSE when:
• Building command-line tools • Only server-to-client streaming
is needed
• Implementing local integrations
• Working with restricted
• Needing simple process networks
communication
• Implementing simple updates
• Working with shell scripts
Securing MCP Servers
• Security Challenge: While local MCP servers (STDIO transport) may not need
authentication, enterprise HTTP deployments require robust security and permission
management
• OAuth2 Integration: New MCP spec (2025-03-26) leverages OAuth2 framework - MCP server
acts as both Resource Server (validates tokens) and Authorization Server (issues tokens)
• Implementation Requirements:
• Add Spring Security & Spring Authorization Server Dependencies
• Con gure OAuth2 client credentials in [Link]
• Create SecurityFilterChain to handle authentication and token validation
fi
Securing MCP Servers
https: [Link]/blog/2025/04/02/mcp-server-oauth2 [Link]
/
/
Testing your mcp servers
• Create an executable JAR
• Test using an MCP Client
• Spring MCP Client
• Claude Desktop
• Cursor / Windsurf / Junie
• Any MCP Client of your choice
Open source vs proprietary
models
Open source models - key challenges
•Performance Gap vs Frontier Models
•Up-Front Hardware & Ops Overhead
•No Vendor-Grade Support or SLA
•Safety & Quality Risks (Hallucinations/Bias)
•Security & Supply-Chain Exposure
•License & IP Ambiguity
•Benchmark / Eval Burden Rests on You
•Rapid-Fire Releases - Maintenance Churn
Why open source models
•Transparency & Auditability
•Self-Hosting for Data Privacy & Compliance
•Lower Total Cost (No API metering)
•Low-Latency Local Development
•Full Customization & Fine-Tuning Rights
•Community-Driven Innovation & Fast Patch Cycles
•Deployment Flexibility (cloud, on-prem, edge)
•No Vendor Lock-In
How to evaluate open source models
• Licence & “Openness” – OSI-approved? any commercial-use limits?
• Capability Benchmarks – MMLU, HellaSwag, GSM-8K scores; check the Open LLM Leaderboard
• Tool / Function-Calling Support – built-in schemas for agents & Spring AI’s callable() interface
• Size vs Hardware Budget – parameter count, VRAM need, quantised variants
• Context Window – 8 K, 128 K… even 1 M tokens for long-doc RAG
• Latency & Throughput – tokens/sec locally vs on-prem GPU or HF Endpoint
• Community & Release Cadence – active issues, model-card updates, patch frequency
• Security & Supply Chain – reproducible weights, SBOM, no suspicious commits
https: [Link]
/
/
Open WebUI
https: [Link]
/
/
Check out my demo
Observability
<dependency>
<groupId>[Link] groupId>
<artifactId>spring-boot-starter-actuator artifactId>
dependency>
<
/
<
/
<
/
Why observability
• Cost can spike ⟶ need token & $ metrics
• • LLMs are nondeterministic ⟶ traces & logs for debug
• • Safety / legal ⟶ need evidence when things go wrong
The 3+1 Pillars of observability
• Metrics – latency, token counts, cost
• Logs – structured prompt / response (PII-redacted)
• Traces – end-to-end view of RAG pipeline
• Evaluations – automated quality checks (FactCheckingEvaluator)
What spring gives you for free
• Micrometer metric names (gen_ai.usage.*, gen_ai.[Link])
([Link])
• • Observation events → Micrometer Tracing / OpenTelemetry
• • Pluggable log masking (PII lter)
• • GenerationListener hook for custom metrics
fi
Check out my demo
Evaluations
Deterministic Non-deterministic
Why Evaluate AI Responses
The Challenge
• AI Models can generate plausible but incorrect responses (hallucinations)
• Traditional Unit tests don’t work for AI-generated content
• Need systematic ways to validate AI output quality
The Solution
• Use AI to evaluate AI responses
• Structured evaluation frameworks
• Automated quality checks in your pipeline
Spring AI Evaluation Framework
Core Interface
@FunctionalInterface
public interface Evaluator {
EvaluationResponse evaluate(EvaluationRequest evaluationRequest);
Evaluation Request Components
• userText - Original user input
• dataList - Context data (e.g., from RAG)
• responseContent - AI model’s response
Two Key evaluators
Relevancy Evaluator Fact Checking Evaluator
• Purpose: Is there AI response • Purpose: Is the AI response factually
relevant to the user’s question? accurate?
• Best for: • Best for:
• RAG (Retrieval Augmented • Detecting hallucinations
Generation)
• Verifying claims against source
• Ensuring responses stay on topic material
• Quality Control for chatbots • Content validation
Relevancy Evaluator deep dive
What it does:
• Compares AI response against retrieved context
• Asks: “Does this response answer the users’s question?”
• Returns YES/NO evaluation
Default Prompt Template
Your task is to evaluate if the response for the query is in line with
the context information provide
Answer YES if relevant, otherwise NO.
Fact checking Evaluator deep dive
What it does:
• Veri es claims against provided documents
• Detects factual inaccuracies and hallucinations
• Can use specialized models like Bespoke-Minicheck
• Accurate, Small, Fast & Cost-effective
Evaluation Format:
Document: {context}
Claim: {ai_response}
fi
Testing deterministic ai tasks
Classi cation Tasks
More predictable outcomes = Traditional testing approaches
Examples:
• Sentiment analysis (positive/negative/neutral)
• Content Moderation (safe/unsafe)
• Intent detection (question/request/complaint)
fi
Testing deterministic ai tasks
@Test
void testSentimentClassification() {
String positiveText = "I love this product!";
String result = classifySentiment(positiveText);
assertThat(result).isEqualTo("POSITIVE");
}
Key Difference: Expected outcomes are known and consistent
Check out my demo
Best practices for AI evaluation
When to use each evaluator
Conclusion
What did we learn?
• Fundamentals of AI: We explored the key concepts of Arti cial Intelligence, including Machine Learning, Deep
Learning, and the transformer architecture that powers Large Language Models (LLMs).
• Prompt Engineering is Key: We learned that the quality of our input (prompts) directly impacts the quality of
the AI's output. We covered several techniques, from basic-to-advanced, for crafting effective prompts,
including zero-shot, one-shot, and few-shot prompting, as well as providing clear context and structure.
• Spring AI for Java Developers: We saw how Spring AI simpli es integrating arti cial intelligence capabilities
into Java applications. It provides abstractions for interacting with various AI models for chat, image, audio,
and more.
• Overcoming LLM Limitations: We addressed the inherent limitations of LLMs, such as hallucinations and stale
data, and discussed strategies like Retrieval Augmented Generation (RAG) and tool calling to make them more
reliable and capable.
• Evaluating AI Responses: We learned that traditional testing methods are insuf cient for non-deterministic AI
outputs and explored how to use evaluator tools within Spring AI to check for relevance and factual accuracy.
fi
fi
fi
fi
Key takeaways
• AI is a Tool to be Mastered: Large Language Models are powerful but not magical. They are pattern-matching machines
that predict the next word. Your success in using them depends on your ability to communicate effectively through
well-crafted prompts.
• Prompt Engineering is a Developer Skill: Don't just command the AI; teach it what you want. Providing context,
examples, and a clear structure to your prompts will dramatically improve the quality of the response. Start saving your
effective prompts as you create them.
• Spring AI is Your Gateway: Spring AI simpli es the process of integrating AI into your Java applications by providing a
portable API that can work across different AI providers. This means you can build with AI without being locked into a
single vendor.
• Don't Trust, Verify: LLMs can "hallucinate" and provide incorrect information with con dence. You must build
guardrails. Use techniques like Retrieval Augmented Generation (RAG) to ground the model with your speci c data , and
implement evaluation checks to validate the accuracy and relevance of AI responses.
• Start Building Now: The best way to learn is by doing. Begin with a simple use case, get your API keys, and start
experimenting. Use the provided resources like the Spring AI workshop code and documentation to actively code along
and build a project of your own.
fi
fi
fi
Resources
• [Link]
• Spring AI Reference Documentation
• Spring AI Source Code
• Spring AI Examples Repo
• Spring AI Community
• Spring Of ce Hours
• Dan Vega
• [Link]
• [Link]
fi
https: [Link]/books/spring-ai-in-action
/
/