avichaym commented on code in PR #533: URL: https://github.com/apache/flink-agents/pull/533#discussion_r2872206330
########## integrations/vector-stores/s3vectors/src/main/java/org/apache/flink/agents/integrations/vectorstores/s3vectors/S3VectorsVectorStore.java: ########## @@ -0,0 +1,343 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://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.apache.flink.agents.integrations.vectorstores.s3vectors; + +import org.apache.flink.agents.api.embedding.model.BaseEmbeddingModelSetup; +import org.apache.flink.agents.api.resource.Resource; +import org.apache.flink.agents.api.resource.ResourceDescriptor; +import org.apache.flink.agents.api.resource.ResourceType; +import org.apache.flink.agents.api.vectorstores.BaseVectorStore; +import org.apache.flink.agents.api.vectorstores.Document; +import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.s3vectors.S3VectorsClient; +import software.amazon.awssdk.services.s3vectors.model.DeleteVectorsRequest; +import software.amazon.awssdk.services.s3vectors.model.GetOutputVector; +import software.amazon.awssdk.services.s3vectors.model.GetVectorsRequest; +import software.amazon.awssdk.services.s3vectors.model.GetVectorsResponse; +import software.amazon.awssdk.services.s3vectors.model.PutInputVector; +import software.amazon.awssdk.services.s3vectors.model.PutVectorsRequest; +import software.amazon.awssdk.services.s3vectors.model.QueryOutputVector; +import software.amazon.awssdk.services.s3vectors.model.QueryVectorsRequest; +import software.amazon.awssdk.services.s3vectors.model.QueryVectorsResponse; +import software.amazon.awssdk.services.s3vectors.model.VectorData; + +import javax.annotation.Nullable; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.function.BiFunction; + +/** + * Amazon S3 Vectors vector store for flink-agents. + * + * <p>Uses the S3 Vectors SDK for PutVectors/QueryVectors/GetVectors/DeleteVectors. PutVectors calls + * are chunked at 500 vectors per request (API limit). + * + * <p>Supported parameters: + * + * <ul> + * <li><b>embedding_model</b> (required): name of the embedding model resource + * <li><b>vector_bucket</b> (required): S3 Vectors bucket name + * <li><b>vector_index</b> (required): S3 Vectors index name + * <li><b>region</b> (optional): AWS region (default: us-east-1) + * </ul> + * + * <p>Example usage: + * + * <pre>{@code + * @VectorStore + * public static ResourceDescriptor s3VectorsStore() { + * return ResourceDescriptor.Builder.newBuilder(S3VectorsVectorStore.class.getName()) + * .addInitialArgument("embedding_model", "bedrockEmbeddingSetup") + * .addInitialArgument("vector_bucket", "my-vector-bucket") + * .addInitialArgument("vector_index", "my-index") + * .addInitialArgument("region", "us-east-1") + * .build(); + * } + * }</pre> + */ +public class S3VectorsVectorStore extends BaseVectorStore { + + private static final int MAX_PUT_VECTORS_BATCH = 500; + + private final S3VectorsClient client; + private final String vectorBucket; + private final String vectorIndex; + + public S3VectorsVectorStore( + ResourceDescriptor descriptor, BiFunction<String, ResourceType, Resource> getResource) { + super(descriptor, getResource); + + this.vectorBucket = descriptor.getArgument("vector_bucket"); + if (this.vectorBucket == null || this.vectorBucket.isBlank()) { + throw new IllegalArgumentException( + "vector_bucket is required for S3VectorsVectorStore"); + } + + this.vectorIndex = descriptor.getArgument("vector_index"); + if (this.vectorIndex == null || this.vectorIndex.isBlank()) { + throw new IllegalArgumentException("vector_index is required for S3VectorsVectorStore"); + } + + String regionStr = descriptor.getArgument("region"); + this.client = + S3VectorsClient.builder() + .region(Region.of(regionStr != null ? regionStr : "us-east-1")) + .credentialsProvider(DefaultCredentialsProvider.create()) Review Comment: Fixed in both OpenSearchVectorStore and S3VectorsVectorStore. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
