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

Key concepts

Posts using Spring AI

Java • 9 min read Reader level: Intermediate

What you'll learn

  • How a RAG system that chats with local documents is designed
  • How data ingestion and retrieval work with Spring AI
  • How to set up, build, and run the project
  • How to ingest documents, ask questions, and test the results
RAG-Nomic LLM using Java and Spring AI

A Retrieval-Augmented Generation (RAG) system built with Spring AI, designed to chat with local documents.

#project#java#spring-ai#rag