Skip to content

Commit 218c967

Browse files
sobychackomarkpollack
authored andcommitted
Add builder pattern for MilvusVectorStore
Introduces a fluent builder API to improve configuration readability and type safety when creating MilvusVectorStore instances. This replaces the existing configuration object approach which was less intuitive and harder to maintain. The builder pattern provides better encapsulation of configuration logic and validation, while maintaining backward compatibility through a deprecated config class. This change makes the codebase more maintainable and the API more discoverable for users. Key changes: - Replace configuration object with fluent builder pattern - Move Milvus-related classes to dedicated milvus package - Deprecate MilvusVectorStoreConfig in favor of builder - Update constructor to use builder internally - Maintain backward compatibility with deprecated config - Add comprehensive builder methods with validation
1 parent 5b11501 commit 218c967

File tree

11 files changed

+496
-139
lines changed

11 files changed

+496
-139
lines changed

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreAutoConfiguration.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.springframework.ai.embedding.BatchingStrategy;
2828
import org.springframework.ai.embedding.EmbeddingModel;
2929
import org.springframework.ai.embedding.TokenCountBatchingStrategy;
30-
import org.springframework.ai.vectorstore.MilvusVectorStore;
31-
import org.springframework.ai.vectorstore.MilvusVectorStore.MilvusVectorStoreConfig;
30+
import org.springframework.ai.milvus.vectorstore.MilvusVectorStore;
31+
import org.springframework.ai.milvus.vectorstore.MilvusVectorStore.MilvusVectorStoreConfig;
3232
import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention;
3333
import org.springframework.beans.factory.ObjectProvider;
3434
import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -71,23 +71,14 @@ public MilvusVectorStore vectorStore(MilvusServiceClient milvusClient, Embedding
7171
ObjectProvider<ObservationRegistry> observationRegistry,
7272
ObjectProvider<VectorStoreObservationConvention> customObservationConvention) {
7373

74-
MilvusVectorStoreConfig config = MilvusVectorStoreConfig.builder()
75-
.withCollectionName(properties.getCollectionName())
76-
.withDatabaseName(properties.getDatabaseName())
77-
.withIndexType(IndexType.valueOf(properties.getIndexType().name()))
78-
.withMetricType(MetricType.valueOf(properties.getMetricType().name()))
79-
.withIndexParameters(properties.getIndexParameters())
80-
.withEmbeddingDimension(properties.getEmbeddingDimension())
81-
.withIDFieldName(properties.getIdFieldName())
82-
.withAutoId(properties.isAutoId())
83-
.withContentFieldName(properties.getContentFieldName())
84-
.withMetadataFieldName(properties.getMetadataFieldName())
85-
.withEmbeddingFieldName(properties.getEmbeddingFieldName())
74+
return MilvusVectorStore.builder()
75+
.milvusClient(milvusClient)
76+
.embeddingModel(embeddingModel)
77+
.initializeSchema(properties.isInitializeSchema())
78+
.batchingStrategy(batchingStrategy)
79+
.observationRegistry(observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP))
80+
.customObservationConvention(customObservationConvention.getIfAvailable(() -> null))
8681
.build();
87-
88-
return new MilvusVectorStore(milvusClient, embeddingModel, config, properties.isInitializeSchema(),
89-
batchingStrategy, observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP),
90-
customObservationConvention.getIfAvailable(() -> null));
9182
}
9283

9384
@Bean

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.ai.autoconfigure.vectorstore.milvus;
1818

1919
import org.springframework.ai.autoconfigure.vectorstore.CommonVectorStoreProperties;
20-
import org.springframework.ai.vectorstore.MilvusVectorStore;
20+
import org.springframework.ai.milvus.vectorstore.MilvusVectorStore;
2121
import org.springframework.boot.context.properties.ConfigurationProperties;
2222
import org.springframework.util.Assert;
2323

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ai.vectorstore;
17+
package org.springframework.ai.milvus.vectorstore;
1818

1919
import org.springframework.ai.vectorstore.filter.Filter.Expression;
2020
import org.springframework.ai.vectorstore.filter.Filter.ExpressionType;

0 commit comments

Comments
 (0)