MCPcopy Index your code
hub / github.com/spring-projects/spring-ai

github.com/spring-projects/spring-ai @v2.0.0-M8 sqlite

repository ↗ · DeepWiki ↗ · release v2.0.0-M8 ↗
22,345 symbols 149,462 edges 2,168 files 4,161 documented · 19% 2 cross-repo links
README

Spring AI build status build status Maven Central

Spring Boot Version Compatibility

Spring AI 2.x.x (main branch) - Spring Boot 4.x

Spring AI 1.1.x (1.1.x branch) - Spring Boot 3.5.x

The Spring AI project provides a Spring-friendly API and abstractions for developing AI applications.

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

spring-ai-integration-diagram-3

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

The project draws inspiration from notable Python projects, such as LangChain and LlamaIndex, but Spring AI is not a direct port of those projects. The project was founded with the belief that the next wave of Generative AI applications will not be only for Python developers but will be ubiquitous across many programming languages.

You can check out the blog post Why Spring AI for additional motivations.

This is a high level feature overview. You can find more details in the Reference Documentation

Getting Started

Please refer to the Getting Started Guide for instruction on adding your dependencies.

Project Resources

  • Documentation
  • Issues

  • Awesome Spring AI - A curated list of awesome resources, tools, tutorials, and projects for building generative AI applications using Spring AI

  • Spring AI Examples contains example projects that explain specific features in more detail.
  • Spring AI Community - A community-driven organization for building Spring-based integrations with AI models, agents, vector databases, and more.

Breaking changes

  • Refer to the upgrade notes to see how to upgrade to 1.0.0.M1 or higher.

Cloning the repo

This repository contains large model files. To clone it you have to either:

  • Ignore the large files (won't affect the spring-ai behaviour) : GIT_LFS_SKIP_SMUDGE=1 git clone git@github.com:spring-projects/spring-ai.git.
  • Or install the Git Large File Storage before cloning the repo.

Building

The project targets and builds artifacts compatible with Java 17+, and requires a JDK with support for the -XDaddTypeAnnotationsToSymbol javac argument, like Liberica 17.0.19+, for nullability checks.

The recommended JDK is specified in the .sdkmanrc file, which can be installed and configured with the SDKMAN! tool: - sdk env install to install the related JDK locally - sdk env to use the related JDK

NOTE: Building Spring AI requires components that depend on your specific CPU architecture (PyTorch for example). MacOS can seamlessly run x86 Java applications on ARM processors using Rosetta, but this will fail when building this project because it tries to download architecture-specific native dependencies. (Note: this is only an issue for building the project, not for consuming the libraries). If you are unsure if you have the correct JDK distribution for your CPU, run the command java -XshowSettings:properties -version 2>&1 | grep os.arch from a fresh terminal to validate that it matches your machine.

To build with running unit tests

./mvnw clean package

To build including integration tests.

./mvnw clean verify -Pintegration-tests

Note that you should set API key environment variables for OpenAI or other model providers before running. If the API key isn't set for a specific model provider, the integration test is skipped.

To run a specific integration test allowing for up to two attempts to succeed. This is useful when a hosted service is not reliable or times out.

./mvnw -pl vector-stores/spring-ai-pgvector-store -am -Pintegration-tests -Dfailsafe.failIfNoSpecifiedTests=false -Dfailsafe.rerunFailingTestsCount=2 -Dit.test=PgVectorStoreIT verify

Integration Tests

There are many integration tests, so it often isn't realistic to run them all at once.

A quick pass through the most important pathways that runs integration tests for

  • OpenAI models
  • OpenAI autoconfiguration
  • PGVector
  • Chroma

can be done with the profile -Pci-fast-integration-tests and is used in the main CI build of this project.

A full integration test is done twice a day in the Spring AI Integration Test Repository

One way to run integration tests on part of the code is to first do a quick compile and install of the project

./mvnw clean install -DskipTests -Dmaven.javadoc.skip=true

Then run the integration test for a specific module using the -pl option

./mvnw verify -Pintegration-tests -pl spring-ai-spring-boot-testcontainers

Documentation

To build the docs

./mvnw -pl spring-ai-docs antora

The docs are then in the directory spring-ai-docs/target/antora/site/index.html

Formatting the Source Code

The code is formatted using the java-format plugin as part of the build. Correct formatting is enforced by CI.

Updating License Headers

To update the year on license headers using the license-maven-plugin

./mvnw license:update-file-header -Plicense

Javadocs

To check javadocs using the javadoc:javadoc

./mvnw javadoc:javadoc

Source Code Style

Spring AI source code checkstyle tries to follow the checkstyle guidelines used by the core Spring Framework project with some exceptions. The wiki pages Code Style and IntelliJ IDEA Editor Settings define the source file coding standards we use along with some IDEA editor settings we customize.

Run checkstyle manually:

./mvnw process-sources -P checkstyle-check

Contributing

Your contributions are always welcome! Please read the contribution guidelines first.

Extension points exported contracts — how you extend this code

VectorStoreRetriever (Interface)
A functional interface that provides read-only access to vector store retrieval operations. This interface extracts only [6 …
spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/VectorStoreRetriever.java
JdbcChatMemoryRepositoryDialect (Interface)
Abstraction for database-specific SQL for chat memory repository. [7 implementers]
memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/main/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryDialect.java
ImageOptions (Interface)
ImageOptions represent the common options, portable across different image generation models. [8 implementers]
spring-ai-model/src/main/java/org/springframework/ai/image/ImageOptions.java
McpSseClientConnectionDetails (Interface)
Connection details for an MCP client. @author Eddú Meléndez [9 implementers]
auto-configurations/mcp/spring-ai-autoconfigure-mcp-client-common/src/main/java/org/springframework/ai/mcp/client/common/autoconfigure/McpSseClientConnectionDetails.java
ChromaConnectionDetails (Interface)
Connection details for a Chroma service. @author Eddú Meléndez [7 implementers]
auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-chroma/src/main/java/org/springframework/ai/vectorstore/chroma/autoconfigure/ChromaConnectionDetails.java
OllamaConnectionDetails (Interface)
Connection details for an Ollama service. @author Eddú Meléndez [21 implementers]
auto-configurations/models/spring-ai-autoconfigure-model-ollama/src/main/java/org/springframework/ai/model/ollama/autoconfigure/OllamaConnectionDetails.java
ChatClientObservationConvention (Interface)
Interface for an ObservationConvention for chat client workflows. @author Christian Tzolov @since 1.0.0 [12 implementers]
spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationConvention.java
MetaProvider (Interface)
Common interface for classes that provide metadata for the "_meta" field. This metadata is used in tool, prompt, and res [9 …
mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/context/MetaProvider.java

Core symbols most depended-on inside this repo

build
called by 6757
spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/ChatClient.java
of
called by 5549
spring-ai-model/src/main/java/org/springframework/ai/chat/metadata/PromptMetadata.java
get
called by 4055
spring-ai-model/src/main/java/org/springframework/ai/chat/memory/ChatMemory.java
isNotNull
called by 1912
spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/filter/FilterExpressionBuilder.java
name
called by 1291
spring-ai-model/src/main/java/org/springframework/ai/tool/definition/ToolDefinition.java
content
called by 1224
spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/ChatClient.java
prompt
called by 1103
spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/ChatClient.java
builder
called by 1061
spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/ChatOptions.java

Shape

Method 18,525
Class 3,489
Enum 171
Interface 159
Function 1

Languages

Java100%
Python1%

Modules by API surface

spring-ai-client-chat/src/test/java/org/springframework/ai/chat/client/DefaultChatClientTests.java221 symbols
spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/filter/antlr4/FiltersParser.java190 symbols
auto-configurations/models/spring-ai-autoconfigure-model-ollama/src/main/java/org/springframework/ai/model/ollama/autoconfigure/OllamaChatProperties.java149 symbols
auto-configurations/models/spring-ai-autoconfigure-model-openai/src/main/java/org/springframework/ai/model/openai/autoconfigure/OpenAiChatProperties.java139 symbols
models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java131 symbols
models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatOptions.java120 symbols
mcp/mcp-annotations/src/test/java/org/springframework/ai/mcp/annotation/provider/tool/AsyncStatelessMcpToolProviderTests.java109 symbols
mcp/mcp-annotations/src/test/java/org/springframework/ai/mcp/annotation/provider/tool/AsyncMcpToolProviderTests.java107 symbols
auto-configurations/models/spring-ai-autoconfigure-model-google-genai/src/main/java/org/springframework/ai/model/google/genai/autoconfigure/chat/GoogleGenAiChatProperties.java105 symbols
mcp/mcp-annotations/src/test/java/org/springframework/ai/mcp/annotation/provider/tool/SyncMcpToolProviderTests.java100 symbols
mcp/mcp-annotations/src/test/java/org/springframework/ai/mcp/annotation/provider/tool/SyncStatelessMcpToolProviderTests.java98 symbols
mcp/mcp-annotations/src/test/java/org/springframework/ai/mcp/annotation/method/resource/SyncMcpResourceMethodCallbackTests.java95 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

${coherence.groupId}:coherence
${coherence.groupId}:coherence-bedrock-testing-support
${coherence.groupId}:coherence-hnsw
ai.djl.huggingface:tokenizers
ai.djl.pytorch:pytorch-engine
ai.djl:api
ai.djl:bom
ai.djl:model-zoo
ch.qos.logback:logback-classic
co.elastic.clients:elasticsearch-java
com.alibaba.fastjson2:fastjson2
com.anthropic:anthropic-java

Datastores touched

(mysql)Database · 1 repos
testdbDatabase · 1 repos
testdbDatabase · 1 repos

For agents

$ claude mcp add spring-ai \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact