Tech Stack · Java
Spring AI
Spring's portable API for chat models, embeddings, vector stores, and tools in Java.
What it is
Spring AI brings Spring Boot conventions (auto-configuration, starters, properties) to AI. You code against one API (ChatClient, EmbeddingModel, VectorStore) and switch providers such as OpenAI, Anthropic, or Ollama by changing a dependency and a few properties.
Get started
Add the Spring AI BOM and a model starter. With Gradle:
dependencies {
implementation platform("org.springframework.ai:spring-ai-bom:${springAiVersion}")
implementation "org.springframework.ai:spring-ai-starter-model-ollama"
}
# application.yml
spring:
ai:
ollama:
base-url: http://localhost:11434
chat:
options:
model: llama3.2
Check the reference docs for the current version and starter names.
Your first endpoint
@RestController
class AskController {
private final ChatClient chatClient;
AskController(ChatClient.Builder builder) {
this.chatClient = builder.build();
}
@GetMapping("/ask")
String ask(@RequestParam String q) {
return chatClient.prompt().user(q).call().content();
}
}
Building blocks
| Piece | Use it for |
|---|---|
ChatClient |
Fluent prompts, system messages, streaming, structured output (.entity(MyRecord.class)) |
EmbeddingModel |
Turning text into vectors |
VectorStore |
Storing and searching embeddings (pgvector, Chroma, Qdrant, Redis, …) |
| Advisors | Cross-cutting behaviour such as RAG retrieval and chat memory |
| Tool calling and MCP | Letting the model call your Java methods or MCP servers |