Skip to content
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

Use PropertyMapper in vector store auto-configurations #2552

Open
wants to merge 1 commit 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
@@ -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.
Expand Down Expand Up @@ -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
*/
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<String> metadataFields = properties.getMetadataFieldsToFilter();
if (!CollectionUtils.isEmpty(metadataFields)) {
Expand Down