Spring AI Overview
The Problem Spring AI Solves
Every AI provider has its own SDK, its own request/response format, its own authentication scheme, and its own streaming protocol. Without an abstraction layer you end up tightly coupled to one provider, with vendor-specific code scattered throughout your application.
Spring AI provides a consistent programming model — the same ChatClient, EmbeddingModel, and VectorStore interfaces work regardless of which provider is underneath.
Key Abstractions
| Abstraction | Interface | Purpose |
|---|---|---|
| ChatClient | ChatClient |
Send prompts (user + system messages) and receive text or structured responses. Supports streaming. |
| EmbeddingModel | EmbeddingModel |
Convert text strings into dense float vectors for semantic similarity comparison. |
| VectorStore | VectorStore |
Store documents with their embeddings and search for semantically similar documents given a query. |
| DocumentReader | DocumentReader |
Parse various file formats (PDF, Word, HTML) into Spring AI Document objects. |
| ImageModel | ImageModel |
Generate images from text prompts (e.g., DALL-E, Imagen). |
The "Write Once, Run Anywhere" Promise
Because all providers implement the same interfaces, you can swap Claude for Gemini by changing one Spring bean declaration. Your service code, your tests, your prompt logic — none of it changes.
In Power RAG, SpringAiConfig.java registers one ChatClient bean per provider. The service layer injects whichever bean it needs by @Qualifier. At runtime, the user can even choose a different provider per request — the service resolves the correct client dynamically. See Topic 05 and Topic 06 for the full pattern.
Spring AI BOM Pattern
Spring AI uses a Bill of Materials (BOM) to manage dependency versions. You import the BOM once in <dependencyManagement> and then declare individual starters without specifying versions — the BOM ensures all Spring AI artifacts stay in sync.
Power RAG uses Spring AI 1.1.2, the latest GA release for Spring Boot 3.x. See Topic 03: Project Setup for the full pom.xml configuration.
Provider Starters
Each provider has its own auto-configuration starter. Adding the starter to your pom.xml is all you need to get a working ChatModel bean wired up with your application.yml credentials:
spring-ai-starter-model-anthropic— Claude (Anthropic API)spring-ai-starter-model-google-genai— Gemini (Google AI API)spring-ai-starter-model-ollama— Any model running via Ollama locally