Use PropertyMapper in vector store auto-configurations
Signed-off-by: Eddú Meléndez <eddu.melendez@gmail.com>
This commit is contained in:
committed by
Soby Chacko
parent
4be10028b0
commit
5127662f2c
@@ -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.
|
||||
@@ -39,6 +39,7 @@ import java.util.List;
|
||||
* {@link AutoConfiguration Auto-configuration} for CosmosDB Vector Store.
|
||||
*
|
||||
* @author Theo van Kraay
|
||||
* @author Eddú Meléndez
|
||||
* @author Soby Chacko
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@@ -49,10 +50,6 @@ import java.util.List;
|
||||
matchIfMissing = true)
|
||||
public class CosmosDBVectorStoreAutoConfiguration {
|
||||
|
||||
String endpoint;
|
||||
|
||||
String key;
|
||||
|
||||
@Bean
|
||||
public CosmosAsyncClient cosmosClient(CosmosDBVectorStoreProperties properties) {
|
||||
return new CosmosClientBuilder().endpoint(properties.getEndpoint())
|
||||
|
||||
@@ -23,11 +23,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
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 class CouchbaseSearchVectorStoreAutoConfiguration {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
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.
|
||||
@@ -68,18 +68,10 @@ public class ElasticsearchVectorStoreAutoConfiguration {
|
||||
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());
|
||||
}
|
||||
if (properties.getEmbeddingFieldName() != null) {
|
||||
elasticsearchVectorStoreOptions.setEmbeddingFieldName(properties.getEmbeddingFieldName());
|
||||
}
|
||||
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)
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
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.
|
||||
@@ -110,32 +110,15 @@ public class MilvusVectorStoreAutoConfiguration {
|
||||
.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());
|
||||
|
||||
@@ -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.
|
||||
@@ -33,13 +33,13 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
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.
|
||||
@@ -76,20 +76,10 @@ public class MongoDBAtlasVectorStoreAutoConfiguration {
|
||||
.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)) {
|
||||
|
||||
Reference in New Issue
Block a user