spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/index.html
Apache License 2.0
3.32k stars 850 forks source link

Error when doing filter-less similarity search with Chroma #1749

Closed habuma closed 1 day ago

habuma commented 4 days ago

When doing a simple similarity search against Chroma, I'm getting the following error:

org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request: "{"error":"InvalidArgumentError","message":"Expected where to have exactly one operator, got {}"}"
    at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:103) ~[spring-web-6.1.14.jar:6.1.14]
    at org.springframework.web.client.StatusHandler.lambda$defaultHandler$3(StatusHandler.java:86) ~[spring-web-6.1.14.jar:6.1.14]
    at org.springframework.web.client.StatusHandler.handle(StatusHandler.java:146) ~[spring-web-6.1.14.jar:6.1.14]
    at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.applyStatusHandlers(DefaultRestClient.java:707) ~[spring-web-6.1.14.jar:6.1.14]
    at org.springframework.web.client.DefaultRestClient.readWithMessageConverters(DefaultRestClient.java:200) ~[spring-web-6.1.14.jar:6.1.14]
    at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.readBody(DefaultRestClient.java:694) ~[spring-web-6.1.14.jar:6.1.14]
    at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.toEntityInternal(DefaultRestClient.java:664) ~[spring-web-6.1.14.jar:6.1.14]
    at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.toEntity(DefaultRestClient.java:653) ~[spring-web-6.1.14.jar:6.1.14]
    at org.springframework.ai.chroma.ChromaApi.queryCollection(ChromaApi.java:218) ~[spring-ai-chroma-store-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    at org.springframework.ai.vectorstore.ChromaVectorStore.doSimilaritySearch(ChromaVectorStore.java:182) ~[spring-ai-chroma-store-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    at org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore.lambda$similaritySearch$5(AbstractObservationVectorStore.java:98) ~[spring-ai-core-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    at io.micrometer.observation.Observation.observe(Observation.java:565) ~[micrometer-observation-1.13.6.jar:1.13.6]
    at org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore.similaritySearch(AbstractObservationVectorStore.java:97) ~[spring-ai-core-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    at org.springframework.ai.vectorstore.VectorStore.similaritySearch(VectorStore.java:75) ~[spring-ai-core-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    at com.example.vectorfun.VectorFunApplication.lambda$go$0(VectorFunApplication.java:23) ~[main/:na]
    at org.springframework.boot.SpringApplication.lambda$callRunner$4(SpringApplication.java:786) ~[spring-boot-3.3.5.jar:3.3.5]
    at org.springframework.util.function.ThrowingConsumer$1.acceptWithException(ThrowingConsumer.java:83) ~[spring-core-6.1.14.jar:6.1.14]
    at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60) ~[spring-core-6.1.14.jar:6.1.14]
    at org.springframework.util.function.ThrowingConsumer$1.accept(ThrowingConsumer.java:88) ~[spring-core-6.1.14.jar:6.1.14]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) ~[spring-boot-3.3.5.jar:3.3.5]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:786) ~[spring-boot-3.3.5.jar:3.3.5]
    at org.springframework.boot.SpringApplication.lambda$callRunners$3(SpringApplication.java:774) ~[spring-boot-3.3.5.jar:3.3.5]
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[na:na]
    at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:571) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560) ~[na:na]
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[na:na]
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) ~[na:na]
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:636) ~[na:na]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774) ~[spring-boot-3.3.5.jar:3.3.5]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:342) ~[spring-boot-3.3.5.jar:3.3.5]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.5.jar:3.3.5]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.5.jar:3.3.5]
    at com.example.vectorfun.VectorFunApplication.main(VectorFunApplication.java:16) ~[main/:na]

When I say "simple similarity search", I mean calling vectorStore.similaritySearch() with a String or with a SearchRequest without a filter expression. E.g., the following code:

vectorStore.add(List.of(Document.builder()
        .withContent("The sky is blue because of Rayleigh scattering.").build()));
List<Document> documents = vectorStore.similaritySearch("Why is the sky blue?");

I don't get that error when I provide a filter expression. And I tried it with Qdrant with no problems, so this narrows the issue down to Chroma.

I get the same problem with both 1.0.0-M3 and 1.0.0-SNAPSHOT, so it's not an entirely new issue. I only just now noticed it because I often do have a filter expression and was trying something without a filter expression for the first time in awhile.

cpage-pivotal commented 4 days ago

Your code will work in the 0.4.x releases of Chroma, but something changed in the 0.5.x releases, and ChromaVectorStore needs to be updated for compatibility

habuma commented 4 days ago

Ah, so...starting Chroma in a Docker Compose file with "chromadb/chroma:latest" is probably the culprit. Or at least explains why this has worked before, but not now.

A bit further investigation reveals that it works with "chromadb/chroma:0.5.16", but not with "chromadb/chroma:0.5.17" or newer. Whatever changed must have changed with 0.5.17.

ilayaperumalg commented 4 days ago

Yes, probably related to this change.