Skip to content

Commit af0179f

Browse files
committed
GH-1529 Fix ChromaVectorStore delete Ids operation
- As a result of the the change:chroma-core/chroma#2880 introduced in chroma:0.5.13,the delete operation doesn't return any values. Hence, we need to check the Http Client Response with the status code instead of return value. - Check the status code for successful delete operation - Update test Resolves #1529
1 parent 21fb629 commit af0179f

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-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: 5 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,16 @@ public void upsertEmbeddings(String collectionId, AddEmbeddingsRequest embedding
188187
.toBodilessEntity();
189188
}
190189

191-
public List<String> deleteEmbeddings(String collectionId, DeleteEmbeddingsRequest deleteRequest) {
190+
public String deleteEmbeddings(String collectionId, DeleteEmbeddingsRequest deleteRequest) {
192191

193-
return this.restClient.post()
192+
return String.valueOf(this.restClient.post()
194193
.uri("/api/v1/collections/{collection_id}/delete", collectionId)
195194
.headers(this::httpHeaders)
196195
.body(deleteRequest)
197196
.retrieve()
198-
.toEntity(new ParameterizedTypeReference<List<String>>() {
199-
200-
})
201-
.getBody();
197+
.toEntity(String.class)
198+
.getStatusCode()
199+
.value());
202200
}
203201

204202
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+
String status = this.chromaApi.deleteEmbeddings(this.collectionId, new DeleteEmbeddingsRequest(idList));
166+
return Optional.of(status.equals("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)