Skip to content

S3 Vector Store implementation #4031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2023-2025 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>spring-ai-autoconfigure-vector-store-s3</artifactId>
<packaging>jar</packaging>
<name>Spring AI Auto Configuration for S3 vector store</name>
<description>Spring AI Auto Configuration for S3 vector store</description>
<url>https://github.com/spring-projects/spring-ai</url>

<scm>
<url>https://github.com/spring-projects/spring-ai</url>
<connection>git://github.com/spring-projects/spring-ai.git</connection>
<developerConnection>[email protected]:spring-projects/spring-ai.git</developerConnection>
</scm>

<dependencies>
<!-- production dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-s3-vector-store</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-test</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-transformers</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ai.vectorstore.s3.autoconfigure;


import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SpringAIVectorStoreTypes;
import org.springframework.ai.vectorstore.s3.S3VectorStore;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.util.Assert;
import software.amazon.awssdk.services.s3vectors.S3VectorsClient;

/**
* {@link AutoConfiguration Auto-configuration} for S3 Vector Store.
*
* @author Matej Nedic
*/
@AutoConfiguration
@ConditionalOnClass({S3VectorsClient.class, EmbeddingModel.class})
@EnableConfigurationProperties(S3VectorStoreProperties.class)
@ConditionalOnProperty(name = SpringAIVectorStoreTypes.TYPE, havingValue = SpringAIVectorStoreTypes.S3,
matchIfMissing = true)
public class S3VectorStoreAutoConfiguration {

private final S3VectorStoreProperties properties;

S3VectorStoreAutoConfiguration(S3VectorStoreProperties p) {
Assert.notNull(p.getIndexName(), "Index name cannot be null!");
Assert.notNull(p.getVectorBucketName(), "Bucket name cannot be null");
this.properties = p;
}
@Bean
@ConditionalOnMissingBean
S3VectorStore s3VectorStore(S3VectorsClient s3VectorsClient, EmbeddingModel embeddingModel) {
S3VectorStore.Builder builder = new S3VectorStore.Builder(s3VectorsClient, embeddingModel);
builder.indexName(properties.getIndexName()).vectorBucketName(properties.getVectorBucketName());
return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ai.vectorstore.s3.autoconfigure;


import org.springframework.boot.context.properties.ConfigurationProperties;


/**
* @author Matej Nedic
*/
@ConfigurationProperties(prefix = S3VectorStoreProperties.CONFIG_PREFIX)
public class S3VectorStoreProperties {

public static final String CONFIG_PREFIX = "spring.ai.vectorstore.s3";

private String indexName;

private String vectorBucketName;

public String getIndexName() {
return indexName;
}

public void setIndexName(String indexName) {
this.indexName = indexName;
}

public String getVectorBucketName() {
return vectorBucketName;
}

public void setVectorBucketName(String vectorBucketName) {
this.vectorBucketName = vectorBucketName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright 2025-2025 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
org.springframework.ai.vectorstore.s3.autoconfigure.S3VectorStoreAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ai.vectorstore.azure.autoconfigure;


import io.micrometer.observation.tck.TestObservationRegistry;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.transformers.TransformersEmbeddingModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.s3.S3VectorStore;
import org.springframework.ai.vectorstore.s3.autoconfigure.S3VectorStoreAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3vectors.S3VectorsClient;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Matej Nedic
*/
@ExtendWith(OutputCaptureExtension.class)
public class S3VectorStoreAutoConfigurationTest {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of( S3VectorStoreAutoConfiguration.class))
.withUserConfiguration(Config.class)
.withPropertyValues("spring.ai.vectorstore.s3.vectorBucketName=testBucket")
.withPropertyValues("spring.ai.vectorstore.s3.indexName=testIndex");

@Test
public void autoConfigurationDisabledWhenTypeIsNone() {
this.contextRunner.withPropertyValues("spring.ai.vectorstore.type=none").run(context -> {
assertThat(context.getBeansOfType(S3VectorStore.class)).isEmpty();
assertThat(context.getBeansOfType(VectorStore.class)).isEmpty();
});
}

@Test
public void autoConfigurationEnabledByDefault() {
this.contextRunner.run(context -> {
assertThat(context.getBeansOfType(S3VectorStore.class)).isNotEmpty();
assertThat(context.getBeansOfType(VectorStore.class)).isNotEmpty();
assertThat(context.getBean(VectorStore.class)).isInstanceOf(S3VectorStore.class);
});
}

@Test
public void autoConfigurationEnabledWhenTypeIsS3() {
this.contextRunner.withPropertyValues("spring.ai.vectorstore.type=S3").run(context -> {
assertThat(context.getBeansOfType(S3VectorStore.class)).isNotEmpty();
assertThat(context.getBeansOfType(VectorStore.class)).isNotEmpty();
assertThat(context.getBean(VectorStore.class)).isInstanceOf(S3VectorStore.class);
});
}

@Configuration(proxyBeanMethods = false)
static class Config {

@Bean
public S3VectorsClient s3VectorsClient() {
return S3VectorsClient.builder().region(Region.US_EAST_1).credentialsProvider(DefaultCredentialsProvider.builder().build()).build();
}

@Bean
public EmbeddingModel embeddingModel() {
return new TransformersEmbeddingModel();
}

}


}
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<module>vector-stores/spring-ai-redis-store</module>
<module>vector-stores/spring-ai-typesense-store</module>
<module>vector-stores/spring-ai-weaviate-store</module>

<module>vector-stores/spring-ai-s3-vector-store</module>

<module>auto-configurations/common/spring-ai-autoconfigure-retry</module>

Expand Down Expand Up @@ -140,6 +140,7 @@
<module>auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-typesense</module>
<module>auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-weaviate</module>
<module>auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-pgvector</module>
<module>auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-s3</module>

<module>spring-ai-spring-boot-starters/spring-ai-starter-vector-store-aws-opensearch</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-vector-store-azure</module>
Expand All @@ -161,6 +162,7 @@
<module>spring-ai-spring-boot-starters/spring-ai-starter-vector-store-redis</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-vector-store-typesense</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-vector-store-weaviate</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-vector-store-s3</module>

<module>models/spring-ai-anthropic</module>
<module>models/spring-ai-azure-openai</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public enum VectorStoreProvider {
*/
REDIS("redis"),

/**
* Vector store provided by simple.
*/
S3_VECTOR("s3_vector"),

/**
* Vector store provided by simple.
*/
Expand Down
1 change: 1 addition & 0 deletions spring-ai-docs/src/main/antora/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
*** xref:api/vectordbs/hana.adoc[SAP Hana]
*** xref:api/vectordbs/typesense.adoc[]
*** xref:api/vectordbs/weaviate.adoc[]
*** xref:api/vectordbs/s3-vector-store.adoc[]

** xref:observability/index.adoc[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ These are the available implementations of the `VectorStore` interface:
* xref:api/vectordbs/hana.adoc[SAP Hana Vector Store] - The https://news.sap.com/2024/04/sap-hana-cloud-vector-engine-ai-with-business-context/[SAP HANA] vector store.
* xref:api/vectordbs/typesense.adoc[Typesense Vector Store] - The https://typesense.org/docs/0.24.0/api/vector-search.html[Typesense] vector store.
* xref:api/vectordbs/weaviate.adoc[Weaviate Vector Store] - The https://weaviate.io/[Weaviate] vector store.
* xref:api/vectordbs/s3-vector-store.adoc[S3 Vector Store] - The https://aws.amazon.com/s3/features/vectors/[AWS S3] vector store.
* link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/SimpleVectorStore.java[SimpleVectorStore] - A simple implementation of persistent vector storage, good for educational purposes.

More implementations may be supported in future releases.
Expand Down
Loading