Skip to content

Commit a98c042

Browse files
ilayaperumalgmarkpollack
authored andcommitted
Fix Chroma delete operation status check
Due to changes in Chroma v0.5.13 (chroma-core/chroma#2880), the delete operation no longer returns values. This impacts our ChromaVectorStore's delete functionality. Now we need to check the HTTP status code instead to properly verify if the delete operation succeeded. Test suite has been updated. Resolves #1529
1 parent 263fe2f commit a98c042

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/BaseOllamaIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.time.Duration;
2020

2121
import org.junit.jupiter.api.AfterAll;
22-
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
2322
import org.testcontainers.junit.jupiter.Testcontainers;
2423
import org.testcontainers.ollama.OllamaContainer;
2524

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.fasterxml.jackson.databind.ObjectMapper;
2929

3030
import org.springframework.ai.chroma.ChromaApi.QueryRequest.Include;
31-
import org.springframework.core.ParameterizedTypeReference;
3231
import org.springframework.http.HttpHeaders;
3332
import org.springframework.http.MediaType;
3433
import org.springframework.http.client.SimpleClientHttpRequestFactory;
@@ -188,17 +187,15 @@ public void upsertEmbeddings(String collectionId, AddEmbeddingsRequest embedding
188187
.toBodilessEntity();
189188
}
190189

191-
public List<String> deleteEmbeddings(String collectionId, DeleteEmbeddingsRequest deleteRequest) {
192-
190+
public int deleteEmbeddings(String collectionId, DeleteEmbeddingsRequest deleteRequest) {
193191
return this.restClient.post()
194192
.uri("/api/v1/collections/{collection_id}/delete", collectionId)
195193
.headers(this::httpHeaders)
196194
.body(deleteRequest)
197195
.retrieve()
198-
.toEntity(new ParameterizedTypeReference<List<String>>() {
199-
200-
})
201-
.getBody();
196+
.toEntity(String.class)
197+
.getStatusCode()
198+
.value();
202199
}
203200

204201
public Long countEmbeddings(String collectionId) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ public void doAdd(List<Document> documents) {
162162
@Override
163163
public Optional<Boolean> doDelete(List<String> idList) {
164164
Assert.notNull(idList, "Document id list must not be null");
165-
List<String> deletedIds = this.chromaApi.deleteEmbeddings(this.collectionId,
166-
new DeleteEmbeddingsRequest(idList));
167-
return Optional.of(deletedIds.size() == idList.size());
165+
int status = this.chromaApi.deleteEmbeddings(this.collectionId, new DeleteEmbeddingsRequest(idList));
166+
return Optional.of(status == 200);
168167
}
169168

170169
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
public final class ChromaImage {
2525

26-
public static final DockerImageName DEFAULT_IMAGE = DockerImageName.parse("ghcr.io/chroma-core/chroma:0.5.11");
26+
public static final DockerImageName DEFAULT_IMAGE = DockerImageName.parse("ghcr.io/chroma-core/chroma:0.5.16");
2727

2828
private ChromaImage() {
2929

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Collections;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.Optional;
2223
import java.util.UUID;
2324

2425
import org.junit.jupiter.api.Test;
@@ -83,7 +84,8 @@ public void addAndSearch() {
8384
assertThat(resultDoc.getMetadata()).containsKeys("meta2", "distance");
8485

8586
// Remove all documents from the store
86-
vectorStore.delete(this.documents.stream().map(doc -> doc.getId()).toList());
87+
assertThat(vectorStore.delete(this.documents.stream().map(doc -> doc.getId()).toList()))
88+
.isEqualTo(Optional.of(Boolean.TRUE));
8789

8890
List<Document> results2 = vectorStore.similaritySearch(SearchRequest.query("Great").withTopK(1));
8991
assertThat(results2).hasSize(0);

0 commit comments

Comments
 (0)