Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

feat(s3vectors): add S3 Vectors service support (#1435)

Prakhar Kapoor93782c0142a6
diff --git a/compatibility-tests/sdk-test-java/pom.xml b/compatibility-tests/sdk-test-java/pom.xml
index 746ea3aba3..791c778388 100644
--- a/compatibility-tests/sdk-test-java/pom.xml
+++ b/compatibility-tests/sdk-test-java/pom.xml
@@ -281,6 +281,11 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>appsync</artifactId>
</dependency>
+ <!-- S3 Vectors client -->
+ <dependency>
+ <groupId>software.amazon.awssdk</groupId>
+ <artifactId>s3vectors</artifactId>
+ </dependency>
<!-- AppConfig and AppConfigData clients -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
index cb24e70748..c54222f3db 100644
--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
@@ -58,6 +58,7 @@ import software.amazon.awssdk.services.appconfigdata.AppConfigDataClient;
import software.amazon.awssdk.services.backup.BackupClient;
import software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client;
import software.amazon.awssdk.services.appsync.AppSyncClient;
+import software.amazon.awssdk.services.s3vectors.S3VectorsClient;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.services.lambda.model.CreateFunctionRequest;
@@ -687,4 +688,12 @@ public final class TestFixtures {
.credentialsProvider(CREDENTIALS)
.build();
}
+
+ public static S3VectorsClient s3vectorsClient() {
+ return S3VectorsClient.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(CREDENTIALS)
+ .build();
+ }
}
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3VectorsTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3VectorsTest.java
new file mode 100644
index 0000000000..9c0f0a9de7
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3VectorsTest.java
@@ -0,0 +1,240 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.*;
+import software.amazon.awssdk.core.document.Document;
+import software.amazon.awssdk.services.s3vectors.S3VectorsClient;
+import software.amazon.awssdk.services.s3vectors.model.*;
+
+import static org.assertj.core.api.Assertions.*;
+
+import java.util.List;
+import java.util.Map;
+
+@DisplayName("S3 Vectors Compatibility Tests")
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class S3VectorsTest {
+
+ private static S3VectorsClient client;
+ private static String bucketName;
+ private static String indexName;
+
+ @BeforeAll
+ static void setup() {
+ client = TestFixtures.s3vectorsClient();
+ bucketName = TestFixtures.uniqueName("bucket");
+ indexName = TestFixtures.uniqueName("index");
+ }
+
+ @AfterAll
+ static void cleanup() {
+ if (client != null) {
+ try {
+ client.deleteIndex(DeleteIndexRequest.builder()
+ .vectorBucketName(bucketName)
+ .indexName(indexName)
+ .build());
+ } catch (Exception ignored) {}
+ try {
+ client.deleteVectorBucket(DeleteVectorBucketRequest.builder()
+ .vectorBucketName(bucketName)
+ .build());
+ } catch (Exception ignored) {}
+ client.close();
+ }
+ }
+
+ @Test
+ @Order(1)
+ void createVectorBucket() {
+ CreateVectorBucketResponse response = client.createVectorBucket(
+ CreateVectorBucketRequest.builder()
+ .vectorBucketName(bucketName)
+ .build()
+ );
+ assertThat(response.vectorBucketArn()).isNotBlank().contains("arn:aws:s3vectors:");
+ }
+
+ @Test
+ @Order(2)
+ void getVectorBucket() {
+ GetVectorBucketResponse response = client.getVectorBucket(
+ GetVectorBucketRequest.builder()
+ .vectorBucketName(bucketName)
+ .build()
+ );
+ assertThat(response.vectorBucket().vectorBucketName()).isEqualTo(bucketName);
+ assertThat(response.vectorBucket().vectorBucketArn()).isNotBlank();
+ }
+
+ @Test
+ @Order(3)
+ void listVectorBuckets() {
+ ListVectorBucketsResponse response = client.listVectorBuckets(
+ ListVectorBucketsRequest.builder().build()
+ );
+ assertThat(response.vectorBuckets())
+ .anyMatch(b -> bucketName.equals(b.vectorBucketName()));
+ }
+
+ @Test
+ @Order(4)
+ void createIndex() {
+ CreateIndexResponse response = client.createIndex(
+ CreateIndexRequest.builder()
+ .vectorBucketName(bucketName)
+ .indexName(indexName)
+ .dimension(3)
+ .distanceMetric("cosine")
+ .dataType("float32")
+ .build()
+ );
+ assertThat(response.indexArn()).isNotBlank().contains("arn:aws:s3vectors:");
+ }
+
+ @Test
+ @Order(5)
+ void getIndex() {
+ GetIndexResponse response = client.getIndex(
+ GetIndexRequest.builder()
+ .vectorBucketName(bucketName)
+ .indexName(indexName)
+ .build()
+ );
+ assertThat(response.index().indexName()).isEqualTo(indexName);
+ assertThat(response.index().dimension()).isEqualTo(3);
+ assertThat(response.index().distanceMetric().toString()).isEqualTo("cosine");
+ }
+
+ @Test
+ @Order(6)
+ void listIndexes() {
+ ListIndexesResponse response = client.listIndexes(
+ ListIndexesRequest.builder()
+ .vectorBucketName(bucketName)
+ .build()
+ );
+ assertThat(response.indexes())
+ .anyMatch(i -> indexName.equals(i.indexName()));
+ }
+
+ @Test
+ @Order(7)
+ void putVectors() {
+ PutVectorsResponse response = client.putVectors(
+ PutVectorsRequest.builder()
+ .vectorBucketName(bucketName)
+ .indexName(indexName)
+ .vectors(
+ PutInputVector.builder()
+ .key("v1")
+ .data(VectorData.builder().float32(1.0f, 0.0f, 0.0f).build())
+ .metadata(Document.fromMap(Map.of("label", Document.fromString("first"))))
+ .build(),
+ PutInputVector.builder()
+ .key("v2")
+ .data(VectorData.builder().float32(0.0f, 1.0f, 0.0f).build())
+ .metadata(Document.fromMap(Map.of("label", Document.fromString("second"))))
+ .build()
+ )
+ .build()
+ );
+ assertThat(response).isNotNull();
+ }
+
+ @Test
+ @Order(8)
+ void getVectors() {
+ GetVectorsResponse response = client.getVectors(
+ GetVectorsRequest.builder()
+ .vectorBucketName(bucketName)
+ .indexName(indexName)
+ .keys("v1", "v2")
+ .returnData(true)
+ .returnMetadata(true)
+ .build()
+ );
+ assertThat(response.vectors()).hasSize(2);
+ GetOutputVector v1 = response.vectors().stream()
+ .filter(v -> "v1".equals(v.key()))
+ .findFirst()
+ .orElse(null);
+ assertThat(v1).isNotNull();
+ assertThat(v1.data().float32()).containsExactly(1.0f, 0.0f, 0.0f);
+ assertThat(v1.metadata().asMap().get("label").asString()).isEqualTo("first");
+ }
+
+ @Test
+ @Order(9)
+ void queryVectors() {
+ QueryVectorsResponse response = client.queryVectors(
+ QueryVectorsRequest.builder()
+ .vectorBucketName(bucketName)
+ .indexName(indexName)
+ .queryVector(VectorData.builder().float32(1.0f, 0.1f, 0.0f).build())
+ .topK(1)
+ .returnMetadata(true)
+ .build()
+ );
+ assertThat(response.vectors()).hasSize(1);
+ QueryOutputVector res = response.vectors().get(0);
+ assertThat(res.key()).isEqualTo("v1");
+ assertThat(res.distance()).isNotNull();
+ assertThat(res.metadata().asMap().get("label").asString()).isEqualTo("first");
+ }
+
+ @Test
+ @Order(10)
+ void deleteVectors() {
+ client.deleteVectors(
+ DeleteVectorsRequest.builder()
+ .vectorBucketName(bucketName)
+ .indexName(indexName)
+ .keys("v1")
+ .build()
+ );
+
+ GetVectorsResponse response = client.getVectors(
+ GetVectorsRequest.builder()
+ .vectorBucketName(bucketName)
+ .indexName(indexName)
+ .keys("v1")
+ .returnData(true)
+ .build()
+ );
+ assertThat(response.vectors()).isEmpty();
+ }
+
+ @Test
+ @Order(11)
+ void testConflictException() {
+ assertThatThrownBy(() -> client.createVectorBucket(
+ CreateVectorBucketRequest.builder()
+ .vectorBucketName(bucketName)
+ .build()
+ )).isInstanceOf(ConflictException.class);
+ }
+
+ @Test
+ @Order(12)
+ void testNotFoundException() {
+ assertThatThrownBy(() -> client.getVectorBucket(
+ GetVectorBucketRequest.builder()
+ .vectorBucketName("non-existent-bucket")
+ .build()
+ )).isInstanceOf(NotFoundException.class);
+ }
+
+ @Test
+ @Order(13)
+ void testValidationException() {
+ assertThatThrownBy(() -> client.createIndex(
+ CreateIndexRequest.builder()
+ .vectorBucketName(bucketName)
+ .indexName("invalid-metric-index")
+ .dimension(3)
+ .distanceMetric("invalid_metric")
+ .dataType("float32")
+ .build()
+ )).isInstanceOf(ValidationException.class);
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index 9b81c67e2a..6909a28b6d 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -175,6 +175,7 @@ public interface EmulatorConfig {
CloudFrontStorageConfig cloudfront();
AppSyncStorageConfig appsync();
BatchStorageConfig batch();
+ S3VectorsStorageConfig s3vectors();
}
interface SsmStorageConfig {
@@ -313,6 +314,13 @@ public interface EmulatorConfig {
long flushIntervalMs();
}
+ interface S3VectorsStorageConfig {
+ Optional<String> mode();
+
+ @WithDefault("5000")
+ long flushIntervalMs();
+ }
+
interface WalConfig {
@WithDefault("30000")
long compactionIntervalMs();
@@ -395,6 +403,7 @@ public interface EmulatorConfig {
AppSyncServiceConfig appsync();
BatchServiceConfig batch();
UiServiceConfig ui();
+ S3VectorsServiceConfig s3vectors();
}
interface CloudTrailServiceConfig {
@@ -402,6 +411,11 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface S3VectorsServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface TransferServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index ba7e1ab6b5..0cc8da640f 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
@@ -17,6 +17,7 @@ import io.github.hectorvent.floci.services.route53.Route53Controller;
import io.github.hectorvent.floci.services.ses.SesController;
import io.github.hectorvent.floci.services.appsync.AppSyncController;
import io.github.hectorvent.floci.services.rdsdata.RdsDataController;
+import io.github.hectorvent.floci.services.s3vectors.S3VectorsController;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -325,7 +326,12 @@ public class ResolvedServiceCatalog {
"appsync", storageMode(config.storage().services().appsync().mode(), config.storage().mode()),
config.storage().services().appsync().flushIntervalMs(), null, ServiceProtocol.REST_JSON,
protocols(ServiceProtocol.REST_JSON),
- Set.of(), Set.of("appsync"), Set.of(), Set.of(AppSyncController.class))
+ Set.of(), Set.of("appsync"), Set.of(), Set.of(AppSyncController.class)),
+ descriptor("s3vectors", "s3vectors", config.services().s3vectors().enabled(), true,
+ "s3vectors", storageMode(config.storage().services().s3vectors().mode(), config.storage().mode()),
+ config.storage().services().s3vectors().flushIntervalMs(), null, ServiceProtocol.REST_JSON,
+ protocols(ServiceProtocol.REST_JSON),
+ Set.of(), Set.of("s3vectors"), Set.of(), Set.of(S3VectorsController.class))
));
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsController.java b/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsController.java
new file mode 100644
index 0000000000..24b1778c41
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsController.java
@@ -0,0 +1,408 @@
+package io.github.hectorvent.floci.services.s3vectors;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorBucket;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorData;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorIndex;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import org.jboss.logging.Logger;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Path("/")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class S3VectorsController {
+
+ private static final Logger LOG = Logger.getLogger(S3VectorsController.class);
+
+ private final S3VectorsService service;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public S3VectorsController(S3VectorsService service, RegionResolver regionResolver, ObjectMapper objectMapper) {
+ this.service = service;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ }
+
+ @RegisterForReflection
+ public record CreateVectorBucketRequest(
+ String vectorBucketName,
+ Object encryptionConfiguration
+ ) {}
+
+ @RegisterForReflection
+ public record CreateVectorBucketResponse(
+ String vectorBucketArn
+ ) {}
+
+ @RegisterForReflection
+ public record GetVectorBucketRequest(
+ String vectorBucketName,
+ String vectorBucketArn
+ ) {}
+
+ @RegisterForReflection
+ public record GetVectorBucketResponse(
+ VectorBucketRepresentation vectorBucket
+ ) {}
+
+ @RegisterForReflection
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public record VectorBucketRepresentation(
+ String vectorBucketName,
+ String vectorBucketArn,
+ Object encryptionConfiguration
+ ) {}
+
+ @RegisterForReflection
+ public record ListVectorBucketsRequest(
+ Integer maxResults,
+ String nextToken,
+ String prefix
+ ) {}
+
+ @RegisterForReflection
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public record ListVectorBucketsResponse(
+ List<VectorBucketRepresentation> vectorBuckets,
+ String nextToken
+ ) {}
+
+ @RegisterForReflection
+ public record DeleteVectorBucketRequest(
+ String vectorBucketName,
+ String vectorBucketArn
+ ) {}
+
+ @RegisterForReflection
+ public record CreateIndexRequest(
+ String vectorBucketName,
+ String vectorBucketArn,
+ String indexName,
+ String dataType,
+ int dimension,
+ String distanceMetric,
+ Object metadataConfiguration,
+ Object encryptionConfiguration
+ ) {}
+
+ @RegisterForReflection
+ public record CreateIndexResponse(
+ String indexArn
+ ) {}
+
+ @RegisterForReflection
+ public record GetIndexRequest(
+ String vectorBucketName,
+ String indexName,
+ String indexArn
+ ) {}
+
+ @RegisterForReflection
+ public record GetIndexResponse(
+ IndexRepresentation index
+ ) {}
+
+ @RegisterForReflection
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public record IndexRepresentation(
+ String vectorBucketName,
+ String indexName,
+ String indexArn,
+ String dataType,
+ int dimension,
+ String distanceMetric,
+ Object metadataConfiguration,
+ Object encryptionConfiguration
+ ) {}
+
+ @RegisterForReflection
+ public record ListIndexesRequest(
+ String vectorBucketName,
+ String vectorBucketArn,
+ Integer maxResults,
+ String nextToken,
+ String prefix
+ ) {}
+
+ @RegisterForReflection
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public record ListIndexesResponse(
+ List<IndexRepresentation> indexes,
+ String nextToken
+ ) {}
+
+ @RegisterForReflection
+ public record DeleteIndexRequest(
+ String vectorBucketName,
+ String indexName,
+ String indexArn
+ ) {}
+
+ @RegisterForReflection
+ public record PutVectorsRequest(
+ String vectorBucketName,
+ String indexName,
+ String indexArn,
+ List<VectorRepresentation> vectors
+ ) {}
+
+ @RegisterForReflection
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public record VectorRepresentation(
+ String key,
+ VectorDataRepresentation data,
+ Map<String, Object> metadata
+ ) {}
+
+ @RegisterForReflection
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public record VectorDataRepresentation(
+ List<Float> float32
+ ) {}
+
+ @RegisterForReflection
+ public record GetVectorsRequest(
+ String vectorBucketName,
+ String indexName,
+ String indexArn,
+ List<String> keys,
+ Boolean returnData,
+ Boolean returnMetadata
+ ) {}
+
+ @RegisterForReflection
+ public record GetVectorsResponse(
+ List<VectorGetResponseRepresentation> vectors
+ ) {}
+
+ @RegisterForReflection
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public record VectorGetResponseRepresentation(
+ String key,
+ VectorDataRepresentation data,
+ Map<String, Object> metadata
+ ) {}
+
+ @RegisterForReflection
+ public record DeleteVectorsRequest(
+ String vectorBucketName,
+ String indexName,
+ String indexArn,
+ List<String> keys
+ ) {}
+
+ @RegisterForReflection
+ public record QueryVectorsRequest(
+ String vectorBucketName,
+ String indexName,
+ String indexArn,
+ int topK,
+ VectorDataRepresentation queryVector,
+ Object filter,
+ Boolean returnMetadata,
+ Boolean returnDistance
+ ) {}
+
+ @RegisterForReflection
+ public record QueryVectorsResponse(
+ List<QueryResultRepresentation> vectors,
+ String distanceMetric
+ ) {}
+
+ @RegisterForReflection
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public record QueryResultRepresentation(
+ String key,
+ Double distance,
+ Map<String, Object> metadata
+ ) {}
+
+ @POST
+ @Path("/CreateVectorBucket")
+ public Response createVectorBucket(@Context HttpHeaders headers, CreateVectorBucketRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ VectorBucket bucket = service.createVectorBucket(request.vectorBucketName(), request.encryptionConfiguration(), region);
+ return Response.ok(new CreateVectorBucketResponse(bucket.getVectorBucketArn())).build();
+ }
+
+ @POST
+ @Path("/GetVectorBucket")
+ public Response getVectorBucket(@Context HttpHeaders headers, GetVectorBucketRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ VectorBucket bucket = service.getVectorBucket(request.vectorBucketName(), region);
+ VectorBucketRepresentation rep = new VectorBucketRepresentation(bucket.getVectorBucketName(), bucket.getVectorBucketArn(), bucket.getEncryptionConfiguration());
+ return Response.ok(new GetVectorBucketResponse(rep)).build();
+ }
+
+ @POST
+ @Path("/ListVectorBuckets")
+ public Response listVectorBuckets(@Context HttpHeaders headers, ListVectorBucketsRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ List<VectorBucket> buckets = service.listVectorBuckets(region);
+ List<VectorBucketRepresentation> reps = buckets.stream()
+ .map(b -> new VectorBucketRepresentation(b.getVectorBucketName(), b.getVectorBucketArn(), b.getEncryptionConfiguration()))
+ .toList();
+ return Response.ok(new ListVectorBucketsResponse(reps, null)).build();
+ }
+
+ @POST
+ @Path("/DeleteVectorBucket")
+ public Response deleteVectorBucket(@Context HttpHeaders headers, DeleteVectorBucketRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ service.deleteVectorBucket(request.vectorBucketName(), region);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ @POST
+ @Path("/CreateIndex")
+ public Response createIndex(@Context HttpHeaders headers, CreateIndexRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ VectorIndex index = service.createIndex(
+ request.vectorBucketName(),
+ request.indexName(),
+ request.dimension(),
+ request.dataType() != null ? request.dataType() : "float32",
+ request.distanceMetric() != null ? request.distanceMetric() : "cosine",
+ List.of(),
+ region
+ );
+ return Response.ok(new CreateIndexResponse(index.getIndexArn())).build();
+ }
+
+ @POST
+ @Path("/GetIndex")
+ public Response getIndex(@Context HttpHeaders headers, GetIndexRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ VectorIndex index = service.getIndex(request.vectorBucketName(), request.indexName(), region);
+ IndexRepresentation rep = new IndexRepresentation(
+ index.getVectorBucketName(),
+ index.getIndexName(),
+ index.getIndexArn(),
+ index.getDataType(),
+ index.getDimension(),
+ index.getDistanceMetric(),
+ null,
+ null
+ );
+ return Response.ok(new GetIndexResponse(rep)).build();
+ }
+
+ @POST
+ @Path("/ListIndexes")
+ public Response listIndexes(@Context HttpHeaders headers, ListIndexesRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ List<VectorIndex> indexes = service.listIndexes(request.vectorBucketName(), region);
+ List<IndexRepresentation> reps = indexes.stream()
+ .map(i -> new IndexRepresentation(
+ i.getVectorBucketName(),
+ i.getIndexName(),
+ i.getIndexArn(),
+ i.getDataType(),
+ i.getDimension(),
+ i.getDistanceMetric(),
+ null,
+ null
+ ))
+ .toList();
+ return Response.ok(new ListIndexesResponse(reps, null)).build();
+ }
+
+ @POST
+ @Path("/DeleteIndex")
+ public Response deleteIndex(@Context HttpHeaders headers, DeleteIndexRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ service.deleteIndex(request.vectorBucketName(), request.indexName(), region);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ @POST
+ @Path("/PutVectors")
+ public Response putVectors(@Context HttpHeaders headers, PutVectorsRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ List<VectorData> vectors = new ArrayList<>();
+ if (request.vectors() != null) {
+ for (VectorRepresentation vRep : request.vectors()) {
+ List<Float> floatList = (vRep.data() != null && vRep.data().float32() != null)
+ ? vRep.data().float32()
+ : List.of();
+ Map<String, Object> metadata = vRep.metadata() != null ? vRep.metadata() : Map.of();
+ vectors.add(new VectorData(vRep.key(), floatList, metadata));
+ }
+ }
+ service.putVectors(request.vectorBucketName(), request.indexName(), vectors, region);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ @POST
+ @Path("/GetVectors")
+ public Response getVectors(@Context HttpHeaders headers, GetVectorsRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ List<VectorData> vectors = service.getVectors(request.vectorBucketName(), request.indexName(), request.keys(), region);
+
+ boolean returnData = request.returnData() != null && request.returnData();
+ boolean returnMetadata = request.returnMetadata() != null && request.returnMetadata();
+
+ List<VectorGetResponseRepresentation> reps = vectors.stream()
+ .map(v -> {
+ VectorDataRepresentation data = returnData ? new VectorDataRepresentation(v.getData()) : null;
+ Map<String, Object> metadata = returnMetadata ? v.getMetadata() : null;
+ return new VectorGetResponseRepresentation(v.getKey(), data, metadata);
+ })
+ .toList();
+
+ return Response.ok(new GetVectorsResponse(reps)).build();
+ }
+
+ @POST
+ @Path("/DeleteVectors")
+ public Response deleteVectors(@Context HttpHeaders headers, DeleteVectorsRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ service.deleteVectors(request.vectorBucketName(), request.indexName(), request.keys(), region);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ @POST
+ @Path("/QueryVectors")
+ public Response queryVectors(@Context HttpHeaders headers, QueryVectorsRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ List<Float> queryVector = (request.queryVector() != null && request.queryVector().float32() != null)
+ ? request.queryVector().float32()
+ : List.of();
+ List<S3VectorsService.QueryResult> results = service.queryVectors(
+ request.vectorBucketName(),
+ request.indexName(),
+ queryVector,
+ request.topK() > 0 ? request.topK() : 10,
+ region
+ );
+
+ boolean returnMetadata = request.returnMetadata() != null && request.returnMetadata();
+
+ List<QueryResultRepresentation> reps = results.stream()
+ .map(res -> {
+ Map<String, Object> metadata = returnMetadata ? res.getVector().getMetadata() : null;
+ return new QueryResultRepresentation(res.getVector().getKey(), res.getDistance(), metadata);
+ })
+ .toList();
+
+ VectorIndex index = service.getIndex(request.vectorBucketName(), request.indexName(), region);
+ return Response.ok(new QueryVectorsResponse(reps, index.getDistanceMetric())).build();
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsService.java b/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsService.java
new file mode 100644
index 0000000000..4cf8cbe2f2
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsService.java
@@ -0,0 +1,250 @@
+package io.github.hectorvent.floci.services.s3vectors;
+
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.storage.StorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorBucket;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorIndex;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorData;
+import com.fasterxml.jackson.core.type.TypeReference;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+@ApplicationScoped
+public class S3VectorsService {
+ private static final Logger LOG = Logger.getLogger(S3VectorsService.class);
+
+ private final StorageBackend<String, VectorBucket> store;
+ private final RegionResolver regionResolver;
+
+ @Inject
+ public S3VectorsService(StorageFactory factory, RegionResolver regionResolver) {
+ this.store = factory.create("s3vectors", "s3vectors.json",
+ new TypeReference<Map<String, VectorBucket>>() {});
+ this.regionResolver = regionResolver;
+ }
+
+ private String buildStorageKey(String region, String bucketName) {
+ return region + "::" + bucketName;
+ }
+
+ private String buildBucketArn(String region, String bucketName) {
+ return AwsArnUtils.Arn.of("s3vectors", region, regionResolver.getAccountId(), "bucket/" + bucketName).toString();
+ }
+
+ private String buildIndexArn(String region, String bucketName, String indexName) {
+ return buildBucketArn(region, bucketName) + "/index/" + indexName;
+ }
+
+ public VectorBucket createVectorBucket(String bucketName, Object encryptionConfiguration, String region) {
+ String key = buildStorageKey(region, bucketName);
+ if (store.get(key).isPresent()) {
+ throw new AwsException("ConflictException", "The vector bucket " + bucketName + " already exists.", 409);
+ }
+ String arn = buildBucketArn(region, bucketName);
+ VectorBucket bucket = new VectorBucket(bucketName, arn, encryptionConfiguration);
+ store.put(key, bucket);
+ LOG.infov("Created Vector Bucket: {0} in region {1}", bucketName, region);
+ return bucket;
+ }
+
+ public VectorBucket getVectorBucket(String bucketName, String region) {
+ String key = buildStorageKey(region, bucketName);
+ return store.get(key).orElseThrow(() ->
+ new AwsException("NotFoundException", "The vector bucket " + bucketName + " does not exist.", 404));
+ }
+
+ public List<VectorBucket> listVectorBuckets(String region) {
+ return store.scan(k -> k.startsWith(region + "::")).stream()
+ .sorted(Comparator.comparing(VectorBucket::getVectorBucketName))
+ .collect(Collectors.toList());
+ }
+
+ public void deleteVectorBucket(String bucketName, String region) {
+ String key = buildStorageKey(region, bucketName);
+ VectorBucket bucket = store.get(key).orElseThrow(() ->
+ new AwsException("NotFoundException", "The vector bucket " + bucketName + " does not exist.", 404));
+
+ if (!bucket.getIndexes().isEmpty()) {
+ throw new AwsException("ConflictException", "The vector bucket " + bucketName + " is not empty.", 409);
+ }
+ store.delete(key);
+ LOG.infov("Deleted Vector Bucket: {0}", bucketName);
+ }
+
+ public VectorIndex createIndex(String bucketName, String indexName, int dimension, String dataType,
+ String distanceMetric, List<String> nonFilterableMetadataKeys, String region) {
+ if (!"float32".equals(dataType)) {
+ throw new AwsException("ValidationException", "Unsupported dataType: " + dataType + ". Only float32 is supported.", 400);
+ }
+ if (!"cosine".equals(distanceMetric) && !"euclidean".equals(distanceMetric)) {
+ throw new AwsException("ValidationException", "Unsupported distanceMetric: " + distanceMetric + ". Supported metrics are cosine and euclidean.", 400);
+ }
+
+ VectorBucket bucket = getVectorBucket(bucketName, region);
+ if (bucket.getIndexes().containsKey(indexName)) {
+ throw new AwsException("ConflictException", "The index " + indexName + " already exists.", 409);
+ }
+
+ String arn = buildIndexArn(region, bucketName, indexName);
+ VectorIndex index = new VectorIndex(indexName, arn, bucketName, dimension, dataType, distanceMetric);
+ bucket.getIndexes().put(indexName, index);
+ store.put(buildStorageKey(region, bucketName), bucket);
+ LOG.infov("Created Index: {0} in bucket {1}", indexName, bucketName);
+ return index;
+ }
+
+ public VectorIndex getIndex(String bucketName, String indexName, String region) {
+ VectorBucket bucket = getVectorBucket(bucketName, region);
+ VectorIndex index = bucket.getIndexes().get(indexName);
+ if (index == null) {
+ throw new AwsException("NotFoundException", "The index " + indexName + " does not exist in bucket " + bucketName + ".", 404);
+ }
+ return index;
+ }
+
+ public List<VectorIndex> listIndexes(String bucketName, String region) {
+ VectorBucket bucket = getVectorBucket(bucketName, region);
+ return bucket.getIndexes().values().stream()
+ .sorted(Comparator.comparing(VectorIndex::getIndexName))
+ .collect(Collectors.toList());
+ }
+
+ public void deleteIndex(String bucketName, String indexName, String region) {
+ VectorBucket bucket = getVectorBucket(bucketName, region);
+ if (!bucket.getIndexes().containsKey(indexName)) {
+ throw new AwsException("NotFoundException", "The index " + indexName + " does not exist.", 404);
+ }
+ bucket.getIndexes().remove(indexName);
+ store.put(buildStorageKey(region, bucketName), bucket);
+ LOG.infov("Deleted Index: {0}", indexName);
+ }
+
+ public void putVectors(String bucketName, String indexName, List<VectorData> vectors, String region) {
+ VectorBucket bucket = getVectorBucket(bucketName, region);
+ VectorIndex index = getIndex(bucketName, indexName, region);
+
+ for (VectorData v : vectors) {
+ if (v.getData() != null && v.getData().size() != index.getDimension()) {
+ throw new AwsException("ValidationException",
+ "Vector dimension " + v.getData().size() + " does not match index dimension " + index.getDimension(), 400);
+ }
+ index.getVectors().put(v.getKey(), v);
+ }
+ store.put(buildStorageKey(region, bucketName), bucket);
+ LOG.infov("Put {0} vectors into index {1}", vectors.size(), indexName);
+ }
+
+ public List<VectorData> getVectors(String bucketName, String indexName, List<String> keys, String region) {
+ VectorIndex index = getIndex(bucketName, indexName, region);
+ List<VectorData> result = new ArrayList<>();
+ for (String key : keys) {
+ VectorData v = index.getVectors().get(key);
+ if (v != null) {
+ result.add(v);
+ }
+ }
+ return result;
+ }
+
+ public void deleteVectors(String bucketName, String indexName, List<String> keys, String region) {
+ VectorBucket bucket = getVectorBucket(bucketName, region);
+ VectorIndex index = getIndex(bucketName, indexName, region);
+ for (String key : keys) {
+ index.getVectors().remove(key);
+ }
+ store.put(buildStorageKey(region, bucketName), bucket);
+ LOG.infov("Deleted {0} vectors from index {1}", keys.size(), indexName);
+ }
+
+ public List<QueryResult> queryVectors(String bucketName, String indexName, List<Float> queryVector, int topK, String region) {
+ VectorIndex index = getIndex(bucketName, indexName, region);
+ if (queryVector.size() != index.getDimension()) {
+ throw new AwsException("ValidationException",
+ "Query vector dimension " + queryVector.size() + " does not match index dimension " + index.getDimension(), 400);
+ }
+
+ String metric = index.getDistanceMetric() != null ? index.getDistanceMetric().toLowerCase() : "cosine";
+ List<QueryResult> results = new ArrayList<>();
+
+ for (VectorData v : index.getVectors().values()) {
+ double distance = 0.0;
+ switch (metric) {
+ case "euclidean":
+ distance = calculateEuclideanDistance(queryVector, v.getData());
+ break;
+ case "cosine":
+ default:
+ distance = calculateCosineSimilarity(queryVector, v.getData());
+ break;
+ }
+ results.add(new QueryResult(v, distance));
+ }
+
+ // Sorting:
+ // For Euclidean distance, smaller distance is closer (ascending)
+ // For Cosine similarity, larger score is closer (descending)
+ if ("euclidean".equals(metric)) {
+ results.sort(Comparator.comparingDouble(QueryResult::getDistance));
+ } else {
+ results.sort((r1, r2) -> Double.compare(r2.getDistance(), r1.getDistance()));
+ }
+
+ return results.stream().limit(topK).collect(Collectors.toList());
+ }
+
+ private double calculateCosineSimilarity(List<Float> v1, List<Float> v2) {
+ if (v1 == null || v2 == null || v1.size() != v2.size()) return 0.0;
+ double dotProduct = 0.0;
+ double normA = 0.0;
+ double normB = 0.0;
+ for (int i = 0; i < v1.size(); i++) {
+ float a = v1.get(i);
+ float b = v2.get(i);
+ dotProduct += a * b;
+ normA += a * a;
+ normB += b * b;
+ }
+ if (normA == 0.0 || normB == 0.0) return 0.0;
+ return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
+ }
+
+ private double calculateEuclideanDistance(List<Float> v1, List<Float> v2) {
+ if (v1 == null || v2 == null || v1.size() != v2.size()) return Double.MAX_VALUE;
+ double sum = 0.0;
+ for (int i = 0; i < v1.size(); i++) {
+ double diff = v1.get(i) - v2.get(i);
+ sum += diff * diff;
+ }
+ return Math.sqrt(sum);
+ }
+
+ private double calculateDotProduct(List<Float> v1, List<Float> v2) {
+ if (v1 == null || v2 == null || v1.size() != v2.size()) return 0.0;
+ double dotProduct = 0.0;
+ for (int i = 0; i < v1.size(); i++) {
+ dotProduct += v1.get(i) * v2.get(i);
+ }
+ return dotProduct;
+ }
+
+ public static class QueryResult {
+ private final VectorData vector;
+ private final double distance;
+
+ public QueryResult(VectorData vector, double distance) {
+ this.vector = vector;
+ this.distance = distance;
+ }
+
+ public VectorData getVector() { return vector; }
+ public double getDistance() { return distance; }
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3vectors/model/VectorBucket.java b/src/main/java/io/github/hectorvent/floci/services/s3vectors/model/VectorBucket.java
new file mode 100644
index 0000000000..b0f47997d1
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/s3vectors/model/VectorBucket.java
@@ -0,0 +1,33 @@
+package io.github.hectorvent.floci.services.s3vectors.model;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@RegisterForReflection
+public class VectorBucket {
+ private String vectorBucketName;
+ private String vectorBucketArn;
+ private Object encryptionConfiguration;
+ private Map<String, VectorIndex> indexes = new ConcurrentHashMap<>();
+
+ public VectorBucket() {}
+
+ public VectorBucket(String vectorBucketName, String vectorBucketArn, Object encryptionConfiguration) {
+ this.vectorBucketName = vectorBucketName;
+ this.vectorBucketArn = vectorBucketArn;
+ this.encryptionConfiguration = encryptionConfiguration;
+ }
+
+ public String getVectorBucketName() { return vectorBucketName; }
+ public void setVectorBucketName(String vectorBucketName) { this.vectorBucketName = vectorBucketName; }
+
+ public String getVectorBucketArn() { return vectorBucketArn; }
+ public void setVectorBucketArn(String vectorBucketArn) { this.vectorBucketArn = vectorBucketArn; }
+
+ public Object getEncryptionConfiguration() { return encryptionConfiguration; }
+ public void setEncryptionConfiguration(Object encryptionConfiguration) { this.encryptionConfiguration = encryptionConfiguration; }
+
+ public Map<String, VectorIndex> getIndexes() { return indexes; }
+ public void setIndexes(Map<String, VectorIndex> indexes) { this.indexes = indexes; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3vectors/model/VectorData.java b/src/main/java/io/github/hectorvent/floci/services/s3vectors/model/VectorData.java
new file mode 100644
index 0000000000..7f47c6cbce
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/s3vectors/model/VectorData.java
@@ -0,0 +1,29 @@
+package io.github.hectorvent.floci.services.s3vectors.model;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import java.util.List;
+import java.util.Map;
+
+@RegisterForReflection
+public class VectorData {
+ private String key;
+ private List<Float> data;
+ private Map<String, Object> metadata;
+
+ public VectorData() {}
+
+ public VectorData(String key, List<Float> data, Map<String, Object> metadata) {
+ this.key = key;
+ this.data = data;
+ this.metadata = metadata;
+ }
+
+ public String getKey() { return key; }
+ public void setKey(String key) { this.key = key; }
+
+ public List<Float> getData() { return data; }
+ public void setData(List<Float> data) { this.data = data; }
+
+ public Map<String, Object> getMetadata() { return metadata; }
+ public void setMetadata(Map<String, Object> metadata) { this.metadata = metadata; }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3vectors/model/VectorIndex.java b/src/main/java/io/github/hectorvent/floci/services/s3vectors/model/VectorIndex.java
new file mode 100644
index 0000000000..fbae01ab02
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/s3vectors/model/VectorIndex.java
@@ -0,0 +1,48 @@
+package io.github.hectorvent.floci.services.s3vectors.model;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@RegisterForReflection
+public class VectorIndex {
+ private String indexName;
+ private String indexArn;
+ private String vectorBucketName;
+ private int dimension;
+ private String dataType;
+ private String distanceMetric;
+ private Map<String, VectorData> vectors = new ConcurrentHashMap<>();
+
+ public VectorIndex() {}
+
+ public VectorIndex(String indexName, String indexArn, String vectorBucketName, int dimension, String dataType, String distanceMetric) {
+ this.indexName = indexName;
+ this.indexArn = indexArn;
+ this.vectorBucketName = vectorBucketName;
+ this.dimension = dimension;
+ this.dataType = dataType;
+ this.distanceMetric = distanceMetric;
+ }
+
+ public String getIndexName() { return indexName; }
+ public void setIndexName(String indexName) { this.indexName = indexName; }
+
+ public String getIndexArn() { return indexArn; }
+ public void setIndexArn(String indexArn) { this.indexArn = indexArn; }
+
+ public String getVectorBucketName() { return vectorBucketName; }
+ public void setVectorBucketName(String vectorBucketName) { this.vectorBucketName = vectorBucketName; }
+
+ public int getDimension() { return dimension; }
+ public void setDimension(int dimension) { this.dimension = dimension; }
+
+ public String getDataType() { return dataType; }
+ public void setDataType(String dataType) { this.dataType = dataType; }
+
+ public String getDistanceMetric() { return distanceMetric; }
+ public void setDistanceMetric(String distanceMetric) { this.distanceMetric = distanceMetric; }
+
+ public Map<String, VectorData> getVectors() { return vectors; }
+ public void setVectors(Map<String, VectorData> vectors) { this.vectors = vectors; }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 832a1b100c..f3b7e8aecc 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -94,6 +94,8 @@ floci:
flush-interval-ms: 5000
batch:
flush-interval-ms: 5000
+ s3vectors:
+ flush-interval-ms: 5000
rds:
# Override storage mode for RDS (memory = no Docker volumes; hybrid/persistent = named volume per instance)
# mode: memory
@@ -359,3 +361,6 @@ floci:
enabled: true
appsync:
enabled: true
+ s3vectors:
+ enabled: true
+
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsIntegrationTest.java
new file mode 100644
index 0000000000..9b837fb47b
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsIntegrationTest.java
@@ -0,0 +1,317 @@
+package io.github.hectorvent.floci.services.s3vectors;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.*;
+
+@QuarkusTest
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+class S3VectorsIntegrationTest {
+
+ private static final String JSON_CONTENT_TYPE = "application/json";
+ private static final String BUCKET_NAME = "my-vector-bucket";
+ private static final String INDEX_NAME = "my-vector-index";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ @Test
+ @Order(1)
+ void createVectorBucket() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s"
+ }
+ """.formatted(BUCKET_NAME))
+ .when()
+ .post("/CreateVectorBucket")
+ .then()
+ .statusCode(200)
+ .body("vectorBucketArn", containsString("arn:aws:s3vectors:"));
+ }
+
+ @Test
+ @Order(2)
+ void getVectorBucket() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s"
+ }
+ """.formatted(BUCKET_NAME))
+ .when()
+ .post("/GetVectorBucket")
+ .then()
+ .statusCode(200)
+ .body("vectorBucket.vectorBucketName", equalTo(BUCKET_NAME))
+ .body("vectorBucket.vectorBucketArn", containsString("arn:aws:s3vectors:"));
+ }
+
+ @Test
+ @Order(3)
+ void listVectorBuckets() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("{}")
+ .when()
+ .post("/ListVectorBuckets")
+ .then()
+ .statusCode(200)
+ .body("vectorBuckets", notNullValue())
+ .body("vectorBuckets.size()", greaterThanOrEqualTo(1));
+ }
+
+ @Test
+ @Order(4)
+ void createIndex() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s",
+ "indexName": "%s",
+ "dimension": 3,
+ "distanceMetric": "cosine",
+ "dataType": "float32"
+ }
+ """.formatted(BUCKET_NAME, INDEX_NAME))
+ .when()
+ .post("/CreateIndex")
+ .then()
+ .statusCode(200)
+ .body("indexArn", containsString("arn:aws:s3vectors:"));
+ }
+
+ @Test
+ @Order(5)
+ void getIndex() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s",
+ "indexName": "%s"
+ }
+ """.formatted(BUCKET_NAME, INDEX_NAME))
+ .when()
+ .post("/GetIndex")
+ .then()
+ .statusCode(200)
+ .body("index.indexName", equalTo(INDEX_NAME))
+ .body("index.dimension", equalTo(3))
+ .body("index.distanceMetric", equalTo("cosine"));
+ }
+
+ @Test
+ @Order(6)
+ void listIndexes() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s"
+ }
+ """.formatted(BUCKET_NAME))
+ .when()
+ .post("/ListIndexes")
+ .then()
+ .statusCode(200)
+ .body("indexes", notNullValue())
+ .body("indexes.size()", greaterThanOrEqualTo(1));
+ }
+
+ @Test
+ @Order(7)
+ void putVectors() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s",
+ "indexName": "%s",
+ "vectors": [
+ {
+ "key": "v1",
+ "data": {
+ "float32": [1.0, 0.0, 0.0]
+ },
+ "metadata": {
+ "label": "first"
+ }
+ },
+ {
+ "key": "v2",
+ "data": {
+ "float32": [0.0, 1.0, 0.0]
+ },
+ "metadata": {
+ "label": "second"
+ }
+ }
+ ]
+ }
+ """.formatted(BUCKET_NAME, INDEX_NAME))
+ .when()
+ .post("/PutVectors")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ @Order(8)
+ void getVectors() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s",
+ "indexName": "%s",
+ "keys": ["v1", "v2"],
+ "returnData": true,
+ "returnMetadata": true
+ }
+ """.formatted(BUCKET_NAME, INDEX_NAME))
+ .when()
+ .post("/GetVectors")
+ .then()
+ .statusCode(200)
+ .body("vectors", hasSize(2))
+ .body("vectors.find { it.key == 'v1' }.data.float32", contains(1.0f, 0.0f, 0.0f))
+ .body("vectors.find { it.key == 'v2' }.metadata.label", equalTo("second"));
+ }
+
+ @Test
+ @Order(9)
+ void queryVectorsCosine() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s",
+ "indexName": "%s",
+ "queryVector": {
+ "float32": [1.0, 0.1, 0.0]
+ },
+ "topK": 1,
+ "returnMetadata": true
+ }
+ """.formatted(BUCKET_NAME, INDEX_NAME))
+ .when()
+ .post("/QueryVectors")
+ .then()
+ .statusCode(200)
+ .body("vectors", hasSize(1))
+ .body("vectors[0].key", equalTo("v1"))
+ .body("vectors[0].distance", notNullValue())
+ .body("vectors[0].metadata.label", equalTo("first"));
+ }
+
+ @Test
+ @Order(10)
+ void deleteVectors() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s",
+ "indexName": "%s",
+ "keys": ["v1"]
+ }
+ """.formatted(BUCKET_NAME, INDEX_NAME))
+ .when()
+ .post("/DeleteVectors")
+ .then()
+ .statusCode(200);
+
+ // Verify key is gone
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s",
+ "indexName": "%s",
+ "keys": ["v1"],
+ "returnData": true
+ }
+ """.formatted(BUCKET_NAME, INDEX_NAME))
+ .when()
+ .post("/GetVectors")
+ .then()
+ .statusCode(200)
+ .body("vectors", hasSize(0));
+ }
+
+ @Test
+ @Order(11)
+ void deleteIndex() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s",
+ "indexName": "%s"
+ }
+ """.formatted(BUCKET_NAME, INDEX_NAME))
+ .when()
+ .post("/DeleteIndex")
+ .then()
+ .statusCode(200);
+
+ // Verify index is gone
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s",
+ "indexName": "%s"
+ }
+ """.formatted(BUCKET_NAME, INDEX_NAME))
+ .when()
+ .post("/GetIndex")
+ .then()
+ .statusCode(404);
+ }
+
+ @Test
+ @Order(12)
+ void deleteVectorBucket() {
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s"
+ }
+ """.formatted(BUCKET_NAME))
+ .when()
+ .post("/DeleteVectorBucket")
+ .then()
+ .statusCode(200);
+
+ // Verify bucket is gone
+ given()
+ .contentType(JSON_CONTENT_TYPE)
+ .body("""
+ {
+ "vectorBucketName": "%s"
+ }
+ """.formatted(BUCKET_NAME))
+ .when()
+ .post("/GetVectorBucket")
+ .then()
+ .statusCode(404);
+ }
+}
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index 6406980ed8..5a12be90fe 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -38,6 +38,8 @@ floci:
flush-interval-ms: 60000
batch:
flush-interval-ms: 60000
+ s3vectors:
+ flush-interval-ms: 60000
cloudfront:
auth:
@@ -226,3 +228,6 @@ floci:
enabled: true
appsync:
enabled: true
+ s3vectors:
+ enabled: true
+