From fcc56f4abfc53c9d13fa1641079180560ea033f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Murib=C3=B8?= Date: Mon, 17 Feb 2025 13:47:13 +0100 Subject: [PATCH] Fix issue with CosmosDBVectorStore.Builder where the different Assert.hasText(..., "... must not be empty") evaluates the current value (null) rather than the argument passes to each builder function. Fix issue where partitionKeyPath is required, yet is never configured via CosmosDBVectorStoreAutoConfiguration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Muribø --- .../cosmosdb/CosmosDBVectorStoreAutoConfiguration.java | 1 + .../ai/vectorstore/cosmosdb/CosmosDBVectorStore.java | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/cosmosdb/CosmosDBVectorStoreAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/cosmosdb/CosmosDBVectorStoreAutoConfiguration.java index 369abb5b6..5a1ff2f8f 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/cosmosdb/CosmosDBVectorStoreAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/cosmosdb/CosmosDBVectorStoreAutoConfiguration.java @@ -77,6 +77,7 @@ public class CosmosDBVectorStoreAutoConfiguration { .metadataFields(List.of(properties.getMetadataFields())) .vectorStoreThroughput(properties.getVectorStoreThroughput()) .vectorDimensions(properties.getVectorDimensions()) + .partitionKeyPath(properties.getPartitionKeyPath()) .build(); } diff --git a/vector-stores/spring-ai-azure-cosmos-db-store/src/main/java/org/springframework/ai/vectorstore/cosmosdb/CosmosDBVectorStore.java b/vector-stores/spring-ai-azure-cosmos-db-store/src/main/java/org/springframework/ai/vectorstore/cosmosdb/CosmosDBVectorStore.java index bfbf4af3e..3a2f3edc3 100644 --- a/vector-stores/spring-ai-azure-cosmos-db-store/src/main/java/org/springframework/ai/vectorstore/cosmosdb/CosmosDBVectorStore.java +++ b/vector-stores/spring-ai-azure-cosmos-db-store/src/main/java/org/springframework/ai/vectorstore/cosmosdb/CosmosDBVectorStore.java @@ -416,7 +416,7 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen * @throws IllegalArgumentException if containerName is null or empty */ public Builder containerName(String containerName) { - Assert.hasText(this.containerName, "Container name must not be empty"); + Assert.hasText(containerName, "Container name must not be empty"); this.containerName = containerName; return this; } @@ -428,7 +428,7 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen * @throws IllegalArgumentException if databaseName is null or empty */ public Builder databaseName(String databaseName) { - Assert.hasText(this.databaseName, "Database name must not be empty"); + Assert.hasText(databaseName, "Database name must not be empty"); this.databaseName = databaseName; return this; } @@ -440,7 +440,7 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen * @throws IllegalArgumentException if partitionKeyPath is null or empty */ public Builder partitionKeyPath(String partitionKeyPath) { - Assert.hasText(this.partitionKeyPath, "Partition key path must not be empty"); + Assert.hasText(partitionKeyPath, "Partition key path must not be empty"); this.partitionKeyPath = partitionKeyPath; return this; } @@ -452,7 +452,7 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen * @throws IllegalArgumentException if vectorStoreThroughput is not positive */ public Builder vectorStoreThroughput(int vectorStoreThroughput) { - Assert.isTrue(this.vectorStoreThroughput > 0, "Vector store throughput must be positive"); + Assert.isTrue(vectorStoreThroughput > 0, "Vector store throughput must be positive"); this.vectorStoreThroughput = vectorStoreThroughput; return this; } @@ -464,7 +464,7 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen * @throws IllegalArgumentException if vectorDimensions is not positive */ public Builder vectorDimensions(long vectorDimensions) { - Assert.isTrue(this.vectorDimensions > 0, "Vector dimensions must be positive"); + Assert.isTrue(vectorDimensions > 0, "Vector dimensions must be positive"); this.vectorDimensions = vectorDimensions; return this; }