diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/cosmosdb/CosmosDBVectorStoreAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/cosmosdb/CosmosDBVectorStoreAutoConfiguration.java index 5a1ff2f8f9e..47b2a268c09 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/cosmosdb/CosmosDBVectorStoreAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/cosmosdb/CosmosDBVectorStoreAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * 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. @@ -37,6 +37,7 @@ * {@link AutoConfiguration Auto-configuration} for CosmosDB Vector Store. * * @author Theo van Kraay + * @author Eddú Meléndez * @author Soby Chacko * @since 1.0.0 */ @@ -45,10 +46,6 @@ @EnableConfigurationProperties(CosmosDBVectorStoreProperties.class) public class CosmosDBVectorStoreAutoConfiguration { - String endpoint; - - String key; - @Bean public CosmosAsyncClient cosmosClient(CosmosDBVectorStoreProperties properties) { return new CosmosClientBuilder().endpoint(properties.getEndpoint()) diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/couchbase/CouchbaseSearchVectorStoreAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/couchbase/CouchbaseSearchVectorStoreAutoConfiguration.java index 30cb8dad5cc..50d9611f772 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/couchbase/CouchbaseSearchVectorStoreAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/couchbase/CouchbaseSearchVectorStoreAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 2024 the original author or authors. + * 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. @@ -23,11 +23,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.context.annotation.Bean; -import org.springframework.util.StringUtils; /** * @author Laurent Doguin + * @author Eddú Meléndez * @since 1.0.0 */ @AutoConfiguration(after = CouchbaseAutoConfiguration.class) @@ -41,27 +42,15 @@ public CouchbaseSearchVectorStore vectorStore(CouchbaseSearchVectorStoreProperti EmbeddingModel embeddingModel) { var builder = CouchbaseSearchVectorStore.builder(cluster, embeddingModel); - if (StringUtils.hasText(properties.getIndexName())) { - builder.vectorIndexName(properties.getIndexName()); - } - if (StringUtils.hasText(properties.getBucketName())) { - builder.bucketName(properties.getBucketName()); - } - if (StringUtils.hasText(properties.getScopeName())) { - builder.scopeName(properties.getScopeName()); - } - if (StringUtils.hasText(properties.getCollectionName())) { - builder.collectionName(properties.getCollectionName()); - } - if (properties.getDimensions() != null) { - builder.dimensions(properties.getDimensions()); - } - if (properties.getSimilarity() != null) { - builder.similarityFunction(properties.getSimilarity()); - } - if (properties.getOptimization() != null) { - builder.indexOptimization(properties.getOptimization()); - } + PropertyMapper mapper = PropertyMapper.get(); + mapper.from(properties::getIndexName).whenHasText().to(builder::vectorIndexName); + mapper.from(properties::getBucketName).whenHasText().to(builder::bucketName); + mapper.from(properties::getScopeName).whenHasText().to(builder::scopeName); + mapper.from(properties::getCollectionName).whenHasText().to(builder::collectionName); + mapper.from(properties::getDimensions).whenNonNull().to(builder::dimensions); + mapper.from(properties::getSimilarity).whenNonNull().to(builder::similarityFunction); + mapper.from(properties::getOptimization).whenNonNull().to(builder::indexOptimization); + return builder.initializeSchema(properties.isInitializeSchema()).build(); } diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/elasticsearch/ElasticsearchVectorStoreAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/elasticsearch/ElasticsearchVectorStoreAutoConfiguration.java index 8541e8e833a..2c758ae0b65 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/elasticsearch/ElasticsearchVectorStoreAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/elasticsearch/ElasticsearchVectorStoreAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * 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. @@ -31,8 +31,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.context.annotation.Bean; -import org.springframework.util.StringUtils; /** * {@link AutoConfiguration Auto-configuration} for Elasticsearch Vector Store. @@ -63,15 +63,10 @@ ElasticsearchVectorStore vectorStore(ElasticsearchVectorStoreProperties properti BatchingStrategy batchingStrategy) { ElasticsearchVectorStoreOptions elasticsearchVectorStoreOptions = new ElasticsearchVectorStoreOptions(); - if (StringUtils.hasText(properties.getIndexName())) { - elasticsearchVectorStoreOptions.setIndexName(properties.getIndexName()); - } - if (properties.getDimensions() != null) { - elasticsearchVectorStoreOptions.setDimensions(properties.getDimensions()); - } - if (properties.getSimilarity() != null) { - elasticsearchVectorStoreOptions.setSimilarity(properties.getSimilarity()); - } + PropertyMapper mapper = PropertyMapper.get(); + mapper.from(properties::getIndexName).whenHasText().to(elasticsearchVectorStoreOptions::setIndexName); + mapper.from(properties::getDimensions).whenNonNull().to(elasticsearchVectorStoreOptions::setDimensions); + mapper.from(properties::getSimilarity).whenNonNull().to(elasticsearchVectorStoreOptions::setSimilarity); return ElasticsearchVectorStore.builder(restClient, embeddingModel) .options(elasticsearchVectorStoreOptions) diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreAutoConfiguration.java index bb432b135ff..18cf740cb75 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * 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. @@ -34,8 +34,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.context.annotation.Bean; -import org.springframework.util.StringUtils; /** * {@link AutoConfiguration Auto-configuration} for Milvus Vector Store. @@ -106,32 +106,15 @@ public MilvusServiceClient milvusClient(MilvusVectorStoreProperties serverProper .withIdleTimeout(clientProperties.getIdleTimeoutMs(), TimeUnit.MILLISECONDS) .withAuthorization(clientProperties.getUsername(), clientProperties.getPassword()); - if (clientProperties.isSecure() && StringUtils.hasText(clientProperties.getUri())) { - builder.withUri(clientProperties.getUri()); - } - - if (clientProperties.isSecure() && StringUtils.hasText(clientProperties.getToken())) { - builder.withToken(clientProperties.getToken()); - } - - if (clientProperties.isSecure() && StringUtils.hasText(clientProperties.getClientKeyPath())) { - builder.withClientKeyPath(clientProperties.getClientKeyPath()); - } - - if (clientProperties.isSecure() && StringUtils.hasText(clientProperties.getClientPemPath())) { - builder.withClientPemPath(clientProperties.getClientPemPath()); - } - - if (clientProperties.isSecure() && StringUtils.hasText(clientProperties.getCaPemPath())) { - builder.withCaPemPath(clientProperties.getCaPemPath()); - } - - if (clientProperties.isSecure() && StringUtils.hasText(clientProperties.getServerPemPath())) { - builder.withServerPemPath(clientProperties.getServerPemPath()); - } - - if (clientProperties.isSecure() && StringUtils.hasText(clientProperties.getServerName())) { - builder.withServerName(clientProperties.getServerName()); + if (clientProperties.isSecure()) { + PropertyMapper mapper = PropertyMapper.get(); + mapper.from(clientProperties::getUri).whenHasText().to(builder::withUri); + mapper.from(clientProperties::getToken).whenHasText().to(builder::withToken); + mapper.from(clientProperties::getClientKeyPath).whenHasText().to(builder::withClientKeyPath); + mapper.from(clientProperties::getClientPemPath).whenHasText().to(builder::withClientPemPath); + mapper.from(clientProperties::getCaPemPath).whenHasText().to(builder::withCaPemPath); + mapper.from(clientProperties::getServerPemPath).whenHasText().to(builder::withServerPemPath); + mapper.from(clientProperties::getServerName).whenHasText().to(builder::withServerName); } return new MilvusServiceClient(builder.build()); diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/mongo/MongoDBAtlasVectorStoreAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/mongo/MongoDBAtlasVectorStoreAutoConfiguration.java index 495cc04d3f3..a626f6a1887 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/mongo/MongoDBAtlasVectorStoreAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/mongo/MongoDBAtlasVectorStoreAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * 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. @@ -31,13 +31,13 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.context.annotation.Bean; import org.springframework.core.convert.converter.Converter; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.convert.MongoCustomConversions; import org.springframework.util.CollectionUtils; import org.springframework.util.MimeType; -import org.springframework.util.StringUtils; /** * {@link AutoConfiguration Auto-configuration} for MongoDB Atlas Vector Store. @@ -72,20 +72,10 @@ MongoDBAtlasVectorStore vectorStore(MongoTemplate mongoTemplate, EmbeddingModel .customObservationConvention(customObservationConvention.getIfAvailable(() -> null)) .batchingStrategy(batchingStrategy); - String collectionName = properties.getCollectionName(); - if (StringUtils.hasText(collectionName)) { - builder.collectionName(collectionName); - } - - String pathName = properties.getPathName(); - if (StringUtils.hasText(pathName)) { - builder.pathName(pathName); - } - - String indexName = properties.getIndexName(); - if (StringUtils.hasText(indexName)) { - builder.vectorIndexName(indexName); - } + PropertyMapper mapper = PropertyMapper.get(); + mapper.from(properties::getCollectionName).whenHasText().to(builder::collectionName); + mapper.from(properties::getPathName).whenHasText().to(builder::pathName); + mapper.from(properties::getIndexName).whenHasText().to(builder::vectorIndexName); List metadataFields = properties.getMetadataFieldsToFilter(); if (!CollectionUtils.isEmpty(metadataFields)) {