docs/docs/integrations/embedding-stores/amazon-s3-vectors.md
The Amazon S3 Vectors Embedding Store integrates with Amazon S3 Vectors, a purpose-built vector storage capability within Amazon S3 designed for storing and querying vector embeddings at scale.
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-s3-vectors</artifactId>
<version>${latest version here}</version>
</dependency>
S3VectorsEmbeddingStoreS3VectorsEmbeddingStore embeddingStore = S3VectorsEmbeddingStore.builder()
.vectorBucketName("my-vector-bucket") // S3 Vectors bucket name (required)
.indexName("my-index") // Index name within the bucket (required)
.region("us-west-2") // AWS region (default: us-east-1)
.distanceMetric(DistanceMetric.COSINE) // Distance metric (default: COSINE)
.createIndexIfNotExists(true) // Auto-create index (default: true)
.timeout(Duration.ofSeconds(60)) // API call timeout (default: 30 seconds)
.credentialsProvider(myCredentialsProvider) // Custom AWS credentials
.build();
If you already have a configured S3VectorsClient, you can pass it directly to the builder:
S3VectorsClient customClient = S3VectorsClient.builder()
.region(Region.US_WEST_2)
.credentialsProvider(myCredentialsProvider)
.build();
S3VectorsEmbeddingStore embeddingStore = S3VectorsEmbeddingStore.builder()
.s3VectorsClient(customClient)
.vectorBucketName("my-vector-bucket")
.indexName("my-index")
.build();
S3 Vectors embedding store supports two distance metrics. The distance values are automatically converted to relevance scores in the range [0, 1], where 1 represents the most relevant match.
Best for: Text embeddings, semantic similarity search
score = (1 - distance + 1) / 2.distanceMetric(DistanceMetric.COSINE) // Default, recommended for text embeddings
Best for: When both direction and magnitude matter
score = 1 / (1 + distance).distanceMetric(DistanceMetric.EUCLIDEAN)
S3 Vectors embedding store supports filtering search results by metadata fields.
isEqualTo: Equal comparisonisNotEqualTo: Not equal comparisonisGreaterThan: Greater than comparisonisGreaterThanOrEqualTo: Greater than or equal comparisonisLessThan: Less than comparisonisLessThanOrEqualTo: Less than or equal comparisonisIn: IN operator (multiple values)isNotIn: NOT IN operatorAnd: Logical ANDOr: Logical ORNot: Logical NOTBy default, the store uses DefaultCredentialsProvider which follows the standard AWS credential resolution chain (environment variables, system properties, credential files, EC2 instance profile, etc.). You can provide a custom AwsCredentialsProvider via the builder.
When createIndexIfNotExists is set to true (default), the index is created automatically on the first embedding insertion. The index dimension and distance metric are set based on the first embedding added and the configured distance metric.
S3VectorsEmbeddingStore implements AutoCloseable. When you're done using the store, call close() to release the underlying S3VectorsClient resources, or use try-with-resources.
removeAll(Filter) is not supported; use removeAll(Collection<String> ids) insteadremoveAll() deletes the entire index