|
17 | 17 | package org.springframework.ai.autoconfigure.vectorstore.mongo; |
18 | 18 |
|
19 | 19 | import java.util.Arrays; |
| 20 | +import java.util.List; |
20 | 21 |
|
21 | 22 | import io.micrometer.observation.ObservationRegistry; |
22 | 23 |
|
23 | 24 | import org.springframework.ai.embedding.BatchingStrategy; |
24 | 25 | import org.springframework.ai.embedding.EmbeddingModel; |
25 | 26 | import org.springframework.ai.embedding.TokenCountBatchingStrategy; |
26 | | -import org.springframework.ai.vectorstore.MongoDBAtlasVectorStore; |
| 27 | +import org.springframework.ai.vectorstore.mongodb.atlas.MongoDBAtlasVectorStore; |
27 | 28 | import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention; |
28 | 29 | import org.springframework.beans.factory.ObjectProvider; |
29 | 30 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
|
34 | 35 | import org.springframework.core.convert.converter.Converter; |
35 | 36 | import org.springframework.data.mongodb.core.MongoTemplate; |
36 | 37 | import org.springframework.data.mongodb.core.convert.MongoCustomConversions; |
| 38 | +import org.springframework.util.CollectionUtils; |
37 | 39 | import org.springframework.util.MimeType; |
38 | 40 | import org.springframework.util.StringUtils; |
39 | 41 |
|
@@ -64,25 +66,35 @@ MongoDBAtlasVectorStore vectorStore(MongoTemplate mongoTemplate, EmbeddingModel |
64 | 66 | ObjectProvider<VectorStoreObservationConvention> customObservationConvention, |
65 | 67 | BatchingStrategy batchingStrategy) { |
66 | 68 |
|
67 | | - var builder = MongoDBAtlasVectorStore.MongoDBVectorStoreConfig.builder(); |
68 | | - |
69 | | - if (StringUtils.hasText(properties.getCollectionName())) { |
70 | | - builder.withCollectionName(properties.getCollectionName()); |
| 69 | + MongoDBAtlasVectorStore.MongoDBBuilder builder = MongoDBAtlasVectorStore.builder() |
| 70 | + .mongoTemplate(mongoTemplate) |
| 71 | + .embeddingModel(embeddingModel) |
| 72 | + .initializeSchema(properties.isInitializeSchema()) |
| 73 | + .observationRegistry(observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP)) |
| 74 | + .customObservationConvention(customObservationConvention.getIfAvailable(() -> null)) |
| 75 | + .batchingStrategy(batchingStrategy); |
| 76 | + |
| 77 | + String collectionName = properties.getCollectionName(); |
| 78 | + if (StringUtils.hasText(collectionName)) { |
| 79 | + builder.collectionName(collectionName); |
71 | 80 | } |
72 | | - if (StringUtils.hasText(properties.getPathName())) { |
73 | | - builder.withPathName(properties.getPathName()); |
| 81 | + |
| 82 | + String pathName = properties.getPathName(); |
| 83 | + if (StringUtils.hasText(pathName)) { |
| 84 | + builder.pathName(pathName); |
74 | 85 | } |
75 | | - if (StringUtils.hasText(properties.getIndexName())) { |
76 | | - builder.withVectorIndexName(properties.getIndexName()); |
| 86 | + |
| 87 | + String indexName = properties.getIndexName(); |
| 88 | + if (StringUtils.hasText(indexName)) { |
| 89 | + builder.vectorIndexName(indexName); |
77 | 90 | } |
78 | | - if (!properties.getMetadataFieldsToFilter().isEmpty()) { |
79 | | - builder.withMetadataFieldsToFilter(properties.getMetadataFieldsToFilter()); |
| 91 | + |
| 92 | + List<String> metadataFields = properties.getMetadataFieldsToFilter(); |
| 93 | + if (!CollectionUtils.isEmpty(metadataFields)) { |
| 94 | + builder.metadataFieldsToFilter(metadataFields); |
80 | 95 | } |
81 | | - MongoDBAtlasVectorStore.MongoDBVectorStoreConfig config = builder.build(); |
82 | 96 |
|
83 | | - return new MongoDBAtlasVectorStore(mongoTemplate, embeddingModel, config, properties.isInitializeSchema(), |
84 | | - observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP), |
85 | | - customObservationConvention.getIfAvailable(() -> null), batchingStrategy); |
| 97 | + return builder.build(); |
86 | 98 | } |
87 | 99 |
|
88 | 100 | @Bean |
|
0 commit comments