From d71411ab5d82b2a73a0350f0c0fdaf97b1e951a3 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 369abb5b660..5a1ff2f8f9e 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 CosmosDBVectorStore cosmosDBVectorStore(ObservationRegistry observationRe .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 bfbf4af3e2f..3a2f3edc3e6 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 @@ private Builder(CosmosAsyncClient cosmosClient, EmbeddingModel embeddingModel) { * @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 Builder containerName(String containerName) { * @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 Builder databaseName(String databaseName) { * @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 Builder partitionKeyPath(String partitionKeyPath) { * @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 Builder vectorStoreThroughput(int vectorStoreThroughput) { * @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; }