|
44 | 44 | * @author Theo van Kraay
|
45 | 45 | * @since 1.0.0
|
46 | 46 | */
|
47 |
| - |
48 | 47 | @EnabledIfEnvironmentVariable(named = "AZURE_COSMOSDB_ENDPOINT", matches = ".+")
|
49 | 48 | @EnabledIfEnvironmentVariable(named = "AZURE_COSMOSDB_KEY", matches = ".+")
|
50 | 49 | public class CosmosDBVectorStoreAutoConfigurationIT {
|
51 | 50 |
|
52 |
| - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() |
53 |
| - .withConfiguration(AutoConfigurations.of(CosmosDBVectorStoreAutoConfiguration.class)) |
54 |
| - .withPropertyValues("spring.ai.vectorstore.cosmosdb.databaseName=test-database") |
55 |
| - .withPropertyValues("spring.ai.vectorstore.cosmosdb.containerName=test-container") |
56 |
| - .withPropertyValues("spring.ai.vectorstore.cosmosdb.partitionKeyPath=/id") |
57 |
| - .withPropertyValues("spring.ai.vectorstore.cosmosdb.metadataFields=country,year,city") |
58 |
| - .withPropertyValues("spring.ai.vectorstore.cosmosdb.vectorStoreThroughput=1000") |
59 |
| - .withPropertyValues("spring.ai.vectorstore.cosmosdb.vectorDimensions=384") |
60 |
| - .withPropertyValues("spring.ai.vectorstore.cosmosdb.endpoint=" + System.getenv("AZURE_COSMOSDB_ENDPOINT")) |
61 |
| - .withPropertyValues("spring.ai.vectorstore.cosmosdb.key=" + System.getenv("AZURE_COSMOSDB_KEY")) |
62 |
| - .withUserConfiguration(Config.class); |
| 51 | + private final ApplicationContextRunner contextRunner; |
| 52 | + |
| 53 | + public CosmosDBVectorStoreAutoConfigurationIT() { |
| 54 | + String endpoint = System.getenv("AZURE_COSMOSDB_ENDPOINT"); |
| 55 | + String key = System.getenv("AZURE_COSMOSDB_KEY"); |
| 56 | + |
| 57 | + ApplicationContextRunner contextRunner = new ApplicationContextRunner() |
| 58 | + .withConfiguration(AutoConfigurations.of(CosmosDBVectorStoreAutoConfiguration.class)) |
| 59 | + .withPropertyValues("spring.ai.vectorstore.cosmosdb.databaseName=test-database") |
| 60 | + .withPropertyValues("spring.ai.vectorstore.cosmosdb.containerName=test-container") |
| 61 | + .withPropertyValues("spring.ai.vectorstore.cosmosdb.partitionKeyPath=/id") |
| 62 | + .withPropertyValues("spring.ai.vectorstore.cosmosdb.metadataFields=country,year,city") |
| 63 | + .withPropertyValues("spring.ai.vectorstore.cosmosdb.vectorStoreThroughput=1000") |
| 64 | + .withPropertyValues("spring.ai.vectorstore.cosmosdb.vectorDimensions=384"); |
| 65 | + |
| 66 | + if (endpoint != null && !"null".equalsIgnoreCase(endpoint)) { |
| 67 | + contextRunner = contextRunner.withPropertyValues("spring.ai.vectorstore.cosmosdb.endpoint=" + endpoint); |
| 68 | + } |
| 69 | + |
| 70 | + if (key != null && !"null".equalsIgnoreCase(key)) { |
| 71 | + contextRunner = contextRunner.withPropertyValues("spring.ai.vectorstore.cosmosdb.key=" + key); |
| 72 | + } |
| 73 | + |
| 74 | + this.contextRunner = contextRunner.withUserConfiguration(Config.class); |
| 75 | + } |
63 | 76 |
|
64 | 77 | private VectorStore vectorStore;
|
65 | 78 |
|
@@ -124,14 +137,15 @@ void testSimilaritySearchWithFilter() {
|
124 | 137 | metadata4.put("country", "US");
|
125 | 138 | metadata4.put("year", 2020);
|
126 | 139 | metadata4.put("city", "Sofia");
|
127 |
| - |
128 | 140 | Document document1 = new Document("1", "A document about the UK", metadata1);
|
129 | 141 | Document document2 = new Document("2", "A document about the Netherlands", metadata2);
|
130 | 142 | Document document3 = new Document("3", "A document about the US", metadata3);
|
131 | 143 | Document document4 = new Document("4", "A document about the US", metadata4);
|
132 | 144 |
|
133 | 145 | this.vectorStore.add(List.of(document1, document2, document3, document4));
|
| 146 | + |
134 | 147 | FilterExpressionBuilder b = new FilterExpressionBuilder();
|
| 148 | + |
135 | 149 | List<Document> results = this.vectorStore.similaritySearch(SearchRequest.builder()
|
136 | 150 | .query("The World")
|
137 | 151 | .topK(10)
|
@@ -190,7 +204,7 @@ public void autoConfigurationEnabledByDefault() {
|
190 | 204 |
|
191 | 205 | @Test
|
192 | 206 | public void autoConfigurationEnabledWhenTypeIsAzureCosmosDB() {
|
193 |
| - this.contextRunner.withPropertyValues("spring.ai.vectorstore.type=azure-cosmmos-db").run(context -> { |
| 207 | + this.contextRunner.withPropertyValues("spring.ai.vectorstore.type=azure-cosmos-db").run(context -> { |
194 | 208 | assertThat(context.getBeansOfType(CosmosDBVectorStoreProperties.class)).isNotEmpty();
|
195 | 209 | assertThat(context.getBeansOfType(VectorStore.class)).isNotEmpty();
|
196 | 210 | assertThat(context.getBean(VectorStore.class)).isInstanceOf(CosmosDBVectorStore.class);
|
|
0 commit comments