diff --git a/vector-stores/spring-ai-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java b/vector-stores/spring-ai-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java index bb9468cd285..850f780ada6 100644 --- a/vector-stores/spring-ai-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java +++ b/vector-stores/spring-ai-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java @@ -48,6 +48,7 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; +import org.springframework.web.client.HttpClientErrorException; /** * {@link ChromaVectorStore} is a concrete implementation of the {@link VectorStore} @@ -117,7 +118,16 @@ public static Builder builder(ChromaApi chromaApi, EmbeddingModel embeddingModel @Override public void afterPropertiesSet() throws Exception { if (!this.initialized) { - var collection = this.chromaApi.getCollection(this.tenantName, this.databaseName, this.collectionName); + //if the collection doesn't exist, chromaApi.getCollection will throw an exception + ChromaApi.Collection collection = null; + try { + collection = this.chromaApi.getCollection(this.tenantName, this.databaseName, this.collectionName); + } + catch (Exception ex) { + if (!(ex.getCause() instanceof HttpClientErrorException.NotFound)) { + throw ex; + } + } if (collection == null) { if (this.initializeSchema) { var tenant = this.chromaApi.getTenant(this.tenantName);