Spring AISpring AI2.1.0

Spring AI is an application framework for AI engineering. Its goal is to apply Spring ecosystem design principles, such as portability and modular design, to the AI domain, and to promote using POJOs as the building blocks of an application.

The building blocks of Spring AI: the ChatClient with advisors, tool calling, memory and the agent harness, the model APIs and providers, vector stores and RAG, MCP, observability, the Session API, and the Spring AI community projects

At its core, Spring AI addresses the fundamental challenge of AI integration: Connecting your enterprise Data and APIs with the AI Models.

Features

Spring AI provides the following features:

ChatClient

  • ChatClient API - Fluent API for communicating with AI Chat Models, with synchronous and streaming calls, idiomatically similar to the WebClient and RestClient APIs.
  • Advisors API - Encapsulates recurring Generative AI patterns, transforms data sent to and from Language Models (LLMs), and provides portability across various models and use cases.
  • Structured Outputs - Mapping of AI Model output to POJOs.
  • Multimodality - Images, audio and other media next to text in a message.
  • Tool Calling - Permits the model to request the execution of client-side tools and functions, thereby accessing necessary real-time information as required. Tool Search handles large tool sets, and Tool Call Confirmation lets a person approve a call.
  • Session API - Keeps a conversation as an append-only log of events, with turn-aware compaction, recall and a JDBC repository. It replaces the deprecated Chat Memory.
  • Agent workflow patterns - Worked examples of the common agentic patterns, built with the ChatClient and its tools.

Models

Data and Retrieval

  • Support for all major Vector Database providers such as Amazon Bedrock Knowledge Base, Amazon S3, Apache Cassandra, Azure Vector Search, Chroma, Couchbase, Elasticsearch, GemFire, MariaDB, Milvus, MongoDB Atlas, Neo4j, OpenSearch, Oracle, Oracle Coherence, PostgreSQL/PGVector, Pinecone, Qdrant, Redis, Typesense, and Weaviate.
  • Portable API across Vector Store providers, including a novel SQL-like metadata filter API.
  • Document ingestion ETL framework for Data Engineering.
  • Retrieval Augmented Generation (RAG) - Out-of-the-box RAG flows as advisors, and a modular architecture to build your own.

Model Context Protocol

  • MCP (Model Context Protocol) - Boot Starters and MCP Java Annotations for building AI applications that consume MCP servers or expose Spring-based services to the AI ecosystem, for both the modern and the legacy generation of the protocol.

Across the Application

  • Observability - Provides insights into AI-related operations.
  • AI Model Evaluation - Utilities to help evaluate generated content and protect against hallucinated responses.
  • Spring Boot Auto Configuration and Starters for all AI Models and Vector Stores - use start.spring.io to select the Model or Vector Store of choice.

This feature set lets you implement common use cases such as "Q&A over your documentation" or "Chat with your documentation."

Documentation

Extensive reference documentation, sample applications, and workshop/course material.

Getting Started

You can get started in a few simple steps:

  1. Create a Spring Boot Web application with a Spring AI OpenAI boot starter dependency. This Spring Initializr link can help you bootstrap the application. (With start.spring.io you can select any AI Models or Vector Stores that you want to use in your new applications).

  2. Add your OpenAI key to the application.properties:

    spring.ai.openai.api-key=<YOUR OPENAI KEY>
    
  3. Add the following snippet to your SpringAiDemoApplication class:

    @Bean
    public CommandLineRunner runner(ChatClient.Builder builder) {
        return args -> {
            ChatClient chatClient = builder.build();
            String response = chatClient.prompt("Tell me a joke").call().content();
            System.out.println(response);
        };
    }
    
  4. Run the application:

    ./mvnw spring-boot:run
    

Want to get started in another way? View the Getting Started section in the reference documentation.

Spring Initializr

Quickstart Your Project

Get ahead

VMware offers training and certification to turbo-charge your progress.

Learn more

Get support

TrueSource Spring Enterprise offers support and binaries for OpenJDK™, Spring, and Apache Tomcat® in one simple subscription.

Learn more

Upcoming events

Check out all the upcoming events in the Spring community.

View all