Skip to content

Commit aa8c385

Browse files
committed
Fix Chroma API 0.4.22+ compatiblity issues
- Makes upsert a void metod. - Fix affected test. - Replac getEmebedding with complex filters test by query Embedding. Resolves #224
1 parent eb42912 commit aa8c385

File tree

8 files changed

+27
-46
lines changed

8 files changed

+27
-46
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/chroma.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Add these dependencies to your project:
3636
<dependency>
3737
<groupId>org.springframework.ai</groupId>
3838
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
39-
<version>0.7.0-SNAPSHOT</version>
39+
<version>0.8.0-SNAPSHOT</version>
4040
</dependency>
4141
----
4242

@@ -47,7 +47,7 @@ Add these dependencies to your project:
4747
<dependency>
4848
<groupId>org.springframework.ai</groupId>
4949
<artifactId>spring-ai-chroma-store</artifactId>
50-
<version>0.7.0-SNAPSHOT</version>
50+
<version>0.8.0-SNAPSHOT</version>
5151
</dependency>
5252
----
5353

vector-stores/spring-ai-chroma/pom.xml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,4 @@
6262

6363
</dependencies>
6464

65-
<!-- <build>
66-
<plugins>
67-
<plugin>
68-
<groupId>io.swagger.codegen.v3</groupId>
69-
<artifactId>swagger-codegen-maven-plugin</artifactId>
70-
<version>3.0.50</version>
71-
<executions>
72-
<execution>
73-
<goals>
74-
<goal>generate</goal>
75-
</goals>
76-
<configuration>
77-
<inputSpec>src/test/resources/api.yaml</inputSpec>
78-
<language>java</language>
79-
<configOptions>
80-
<sourceFolder>src/gen/java/main</sourceFolder>
81-
</configOptions>
82-
</configuration>
83-
</execution>
84-
</executions>
85-
</plugin>
86-
</plugins>
87-
</build> -->
88-
89-
9065
</project>

vector-stores/spring-ai-chroma/src/main/java/org/springframework/ai/chroma/ChromaApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ public List<Collection> listCollections() {
316316
// Chroma Collection API (https://docs.trychroma.com/js_reference/Collection)
317317
//
318318

319-
public Boolean upsertEmbeddings(String collectionId, AddEmbeddingsRequest embedding) {
319+
public void upsertEmbeddings(String collectionId, AddEmbeddingsRequest embedding) {
320320

321-
return this.restTemplate
321+
this.restTemplate
322322
.exchange(this.baseUrl + "/api/v1/collections/{collection_id}/upsert", HttpMethod.POST,
323323
this.getHttpEntityFor(embedding), Boolean.class, collectionId)
324324
.getBody();

vector-stores/spring-ai-chroma/src/main/java/org/springframework/ai/vectorsore/ChromaVectorStore.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,8 @@ public void add(List<Document> documents) {
100100
embeddings.add(JsonUtils.toFloatArray(document.getEmbedding()));
101101
}
102102

103-
var success = this.chromaApi.upsertEmbeddings(this.collectionId,
103+
this.chromaApi.upsertEmbeddings(this.collectionId,
104104
new AddEmbeddingsRequest(ids, embeddings, metadatas, contents));
105-
106-
if (!success) {
107-
throw new RuntimeException("Unsuccessful storing!");
108-
}
109105
}
110106

111107
@Override

vector-stores/spring-ai-chroma/src/test/java/org/springframework/ai/chroma/ChromaApiIT.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
public class ChromaApiIT {
4646

4747
@Container
48-
static GenericContainer<?> chromaContainer = new GenericContainer<>("ghcr.io/chroma-core/chroma:0.4.15")
48+
static GenericContainer<?> chromaContainer = new GenericContainer<>("ghcr.io/chroma-core/chroma:0.4.22.dev44")
4949
.withExposedPorts(8000);
5050

5151
@Autowired
@@ -85,9 +85,7 @@ public void testCollection() {
8585
List.of(Map.of(), Map.of("key1", "value1", "key2", true, "key3", 23.4)),
8686
List.of("Hello World", "Big World"));
8787

88-
var success = chroma.upsertEmbeddings(newCollection.id(), addEmbeddingRequest);
89-
90-
assertThat(success).isTrue();
88+
chroma.upsertEmbeddings(newCollection.id(), addEmbeddingRequest);
9189

9290
var addEmbeddingRequest2 = new AddEmbeddingsRequest("id3", new float[] { 3f, 3f, 3f },
9391
Map.of("key1", "value1", "key2", true, "key3", 23.4), "Big World");
@@ -96,18 +94,30 @@ public void testCollection() {
9694

9795
assertThat(chroma.countEmbeddings(newCollection.id())).isEqualTo(3);
9896

97+
var queryResult = chroma.queryCollection(newCollection.id(),
98+
new QueryRequest(List.of(1f, 1f, 1f), 3, chroma.where("""
99+
{
100+
"key2" : { "$eq": true }
101+
}
102+
""")));
103+
assertThat(queryResult.ids().get(0)).hasSize(2);
104+
assertThat(queryResult.ids().get(0)).containsExactlyInAnyOrder("id2", "id3");
105+
99106
// Update existing embedding.
100107
chroma.upsertEmbeddings(newCollection.id(), new AddEmbeddingsRequest("id3", new float[] { 6f, 6f, 6f },
101108
Map.of("key1", "value2", "key2", false, "key4", 23.4), "Small World"));
102109

103110
var result = chroma.getEmbeddings(newCollection.id(), new GetEmbeddingsRequest(List.of("id2")));
104111
assertThat(result.ids().get(0)).isEqualTo("id2");
105112

106-
result = chroma.getEmbeddings(newCollection.id(), new GetEmbeddingsRequest(List.of(), chroma.where("""
107-
{ "key2" : { "$eq": true} }
108-
""")));
109-
110-
assertThat(result.ids()).containsExactlyInAnyOrder("id2");
113+
queryResult = chroma.queryCollection(newCollection.id(),
114+
new QueryRequest(List.of(1f, 1f, 1f), 3, chroma.where("""
115+
{
116+
"key2" : { "$eq": true }
117+
}
118+
""")));
119+
assertThat(queryResult.ids().get(0)).hasSize(1);
120+
assertThat(queryResult.ids().get(0)).containsExactlyInAnyOrder("id2");
111121
}
112122

113123
@Test

vector-stores/spring-ai-chroma/src/test/java/org/springframework/ai/vectorstore/BasicAuthChromaWhereIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class BasicAuthChromaWhereIT {
5555
* https://docs.trychroma.com/usage-guide#basic-authentication
5656
*/
5757
@Container
58-
static GenericContainer<?> chromaContainer = new GenericContainer<>("ghcr.io/chroma-core/chroma:0.4.15")
58+
static GenericContainer<?> chromaContainer = new GenericContainer<>("ghcr.io/chroma-core/chroma:0.4.22")
5959
.withEnv("CHROMA_SERVER_AUTH_CREDENTIALS_FILE", "server.htpasswd")
6060
.withEnv("CHROMA_SERVER_AUTH_CREDENTIALS_PROVIDER",
6161
"chromadb.auth.providers.HtpasswdFileServerAuthCredentialsProvider")

vector-stores/spring-ai-chroma/src/test/java/org/springframework/ai/vectorstore/ChromaVectorStoreIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
public class ChromaVectorStoreIT {
4747

4848
@Container
49-
static GenericContainer<?> chromaContainer = new GenericContainer<>("ghcr.io/chroma-core/chroma:0.4.15")
49+
static GenericContainer<?> chromaContainer = new GenericContainer<>("ghcr.io/chroma-core/chroma:0.4.22")
5050
.withExposedPorts(8000);
5151

5252
List<Document> documents = List.of(

vector-stores/spring-ai-chroma/src/test/java/org/springframework/ai/vectorstore/TokenSecuredChromaWhereIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class TokenSecuredChromaWhereIT {
5757
* https://docs.trychroma.com/usage-guide#static-api-token-authentication
5858
*/
5959
@Container
60-
static GenericContainer<?> chromaContainer = new GenericContainer<>("ghcr.io/chroma-core/chroma:0.4.15")
60+
static GenericContainer<?> chromaContainer = new GenericContainer<>("ghcr.io/chroma-core/chroma:0.4.22")
6161
.withEnv("CHROMA_SERVER_AUTH_CREDENTIALS", CHROMA_SERVER_AUTH_CREDENTIALS)
6262
.withEnv("CHROMA_SERVER_AUTH_CREDENTIALS_PROVIDER",
6363
"chromadb.auth.token.TokenConfigServerAuthCredentialsProvider")

0 commit comments

Comments
 (0)