Skip to content

Commit f461bd6

Browse files
CodingNowPlsmarkpollack
authored andcommitted
Add support for multiple types in Chroma metadata
- Change Chroma collection metadata to Map<String, Object> - Allows integer and other value types to be passed in Fixes #1548
1 parent d0c5339 commit f461bd6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public ChromaApi withBasicAuthCredentials(String username, String password) {
106106
* @param name The name of the collection.
107107
* @param metadata Metadata associated with the collection.
108108
*/
109-
public record Collection(String id, String name, Map<String, String> metadata) {
109+
public record Collection(String id, String name, Map<String, Object> metadata) {
110110
}
111111

112112
/**
@@ -115,7 +115,7 @@ public record Collection(String id, String name, Map<String, String> metadata) {
115115
* @param name The name of the collection to create.
116116
* @param metadata Optional metadata to associate with the collection.
117117
*/
118-
public record CreateCollectionRequest(String name, Map<String, String> metadata) {
118+
public record CreateCollectionRequest(String name, Map<String, Object> metadata) {
119119
public CreateCollectionRequest(String name) {
120120
this(name, new HashMap<>(Map.of("hnsw:space", "cosine")));
121121
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public void beforeEach() {
5555
chroma.listCollections().stream().forEach(c -> chroma.deleteCollection(c.name()));
5656
}
5757

58+
@Test
59+
public void testClientWithMetadata() {
60+
Map<String, Object> metadata = Map.of("hnsw:space", "cosine", "hnsw:M", 5);
61+
var newCollection = chroma.createCollection(new ChromaApi.CreateCollectionRequest("TestCollection", metadata));
62+
assertThat(newCollection).isNotNull();
63+
assertThat(newCollection.name()).isEqualTo("TestCollection");
64+
}
65+
5866
@Test
5967
public void testClient() {
6068
var newCollection = chroma.createCollection(new ChromaApi.CreateCollectionRequest("TestCollection"));

0 commit comments

Comments
 (0)