Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)) {
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception handling logic checks ex.getCause() for HttpClientErrorException.NotFound, but if chromaApi.getCollection() directly throws HttpClientErrorException.NotFound (not wrapped), this check will fail and re-throw the exception incorrectly. Consider also checking if ex itself is an instance of HttpClientErrorException.NotFound before checking the cause: if (!(ex instanceof HttpClientErrorException.NotFound || ex.getCause() instanceof HttpClientErrorException.NotFound))

Suggested change
if (!(ex.getCause() instanceof HttpClientErrorException.NotFound)) {
if (!(ex instanceof HttpClientErrorException.NotFound || ex.getCause() instanceof HttpClientErrorException.NotFound)) {

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this check be part of ChromaApi:233?

If I am not mistaken, the ChromaApi still contains the exception message check.
That exception message check will also still prevent ChromaApi#getCollection() from returning null, when a collection not exists, although returning null seems to be the expected behavior.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I’ve looked into this further and realized the issue is in Spring AI’s own Chroma client implementation.

The error message check on line 233 currently uses:

String.format("Collection [%s] does not exists", collectionName)

However, the actual response from the Chroma server is:

Collection [...] does not exist

Since the Chroma HTTP API returns "does not exist" ,As a result, the null-return path for missing collections is never triggered.

The fix is simply to update the expected message::

if (String.format("Collection [%s] does not exist", collectionName).equals(msg)) {
    return null;
}

I’m happy to submit a quick PR if that would be helpful!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the expected message would break compatibility with older Chroma versions.

Checking the type of the exception, as you already did in this Pull Request, might be the better approach.

But that is just my opinion. I am waiting for the same fix to be able to update Chroma in my applications :-)

throw ex;
}
}
if (collection == null) {
if (this.initializeSchema) {
var tenant = this.chromaApi.getTenant(this.tenantName);
Expand Down