Spring AI — AI Engineering for Java/Spring
Spring AI provides Spring-friendly APIs for AI apps. 8.4K+ stars. Chat, embeddings, RAG, vector DBs, function calling. Major providers. Apache 2.0.
Installation agent prête
Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.
npx -y tokrepo@latest install 98ae1961-8a0b-456f-9ff2-10852b832001 --target codexÀ exécuter après confirmation du plan en dry-run.
What it is
Spring AI is a framework that brings AI engineering capabilities to Java and Spring Boot applications. It provides Spring-friendly APIs for chat completions, embeddings, retrieval-augmented generation (RAG), vector database integration, function calling, and structured output parsing. It supports major AI providers including OpenAI, Anthropic Claude, Google Gemini, Mistral, Ollama, and Azure OpenAI.
Spring AI is for Java developers and enterprise teams who want to add AI capabilities to existing Spring Boot applications. If your backend is Java and you need to integrate LLMs, build RAG pipelines, or add AI-powered features, Spring AI provides familiar Spring patterns (auto-configuration, dependency injection, properties) for AI integration.
How it saves time or tokens
Spring AI abstracts provider-specific APIs behind a common interface. Switch from OpenAI to Anthropic by changing a configuration property, not your code. The auto-configuration handles client setup, retry logic, and rate limiting. RAG support with built-in vector store integrations (PGVector, Chroma, Pinecone, Milvus) means you wire up retrieval without writing embedding pipeline code from scratch. Spring Boot starters reduce AI integration to adding a dependency and setting an API key.
How to use
- Add the Spring AI starter to your pom.xml or build.gradle.
- Configure your AI provider API key in application.properties.
- Inject the ChatClient or EmbeddingClient beans and use them in your services.
Example
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;
@RestController
public class AiController {
private final ChatClient chatClient;
public AiController(ChatClient.Builder builder) {
this.chatClient = builder.build();
}
@GetMapping("/ask")
public String ask(@RequestParam String question) {
return chatClient.prompt()
.user(question)
.call()
.content();
}
@GetMapping("/structured")
public Movie recommend(@RequestParam String genre) {
return chatClient.prompt()
.user("Recommend a " + genre + " movie")
.call()
.entity(Movie.class);
}
}
record Movie(String title, int year, String director) {}
Related on TokRepo
- AI tools for coding -- developer tools for AI integration
- AI tools for API -- API integration frameworks
Common pitfalls
- Hardcoding the AI provider instead of using the abstraction layer. Spring AI's value is provider portability. Program against the ChatClient interface so you can switch providers by changing configuration.
- Not configuring retry and rate limiting. AI provider APIs have rate limits. Use Spring AI's built-in retry configuration to handle transient failures gracefully.
- Ignoring structured output parsing. Instead of parsing LLM responses manually, use
.entity(MyClass.class)to get typed Java objects. This reduces parsing bugs and makes AI responses type-safe.
Questions fréquentes
Spring AI supports OpenAI, Anthropic Claude, Google Gemini, Mistral, Amazon Bedrock, Azure OpenAI, Ollama (local models), and more. Each provider has a dedicated Spring Boot starter for auto-configuration.
Yes. Spring AI provides a complete RAG pipeline with document readers, text splitters, embedding clients, and vector store integrations. Supported vector stores include PGVector, Chroma, Pinecone, Milvus, Qdrant, and Weaviate.
Yes. Spring AI is designed as an add-on to existing Spring Boot applications. Add the starter dependency, configure the API key, and inject AI clients into your existing services using standard Spring dependency injection.
Function calling lets the AI model invoke Java methods based on the conversation. You register Java functions that the model can call to get real-time data, perform calculations, or interact with your systems. Spring AI handles the serialization and invocation.
Spring AI reached 1.0 GA status and is used in production by organizations running Spring Boot. It follows Spring's stability and backward compatibility standards. The Apache 2.0 license allows unrestricted commercial use.
Sources citées (3)
- Spring AI GitHub— Spring AI provides Spring-friendly APIs for AI applications
- Spring AI Documentation— Supports OpenAI, Anthropic, Google, Mistral, and more
- Spring AI Vector Store Docs— Vector store integrations for RAG pipelines
En lien sur TokRepo
Source et remerciements
spring-projects/spring-ai — 8,400+ GitHub stars
Fil de discussion
Actifs similaires
LangChain4j — LLM Integration for Java
LangChain4j integrates 20+ LLM providers and 30+ vector stores into Java apps. 11.4K+ stars. Unified API, RAG, MCP, Spring Boot. Apache 2.0.
Spring Boot — Production-Grade Java Apps with Minimum Fuss
Spring Boot makes it easy to create stand-alone, production-grade Spring-based applications. Auto-configuration, embedded servers, actuator endpoints, and a massive starter ecosystem. The dominant framework for enterprise Java backends.
Spring Framework — The Enterprise Java Application Framework
Spring Framework provides comprehensive infrastructure for building Java applications with dependency injection, AOP, transaction management, and a modular architecture used in millions of production systems.
ROS 2 Engineering Skills — Production-Grade Patterns
Load a deep ROS 2 engineering SKILL.md with progressive references (QoS, lifecycle, RT, Nav2, MoveIt); verified 67★ with marketplace install and CI claims.