Skip to content

Commit e3884f7

Browse files
committed
Switch to the upstream ChromaEmbeddingStore impl, support V2 API
1 parent 60fe7fa commit e3884f7

File tree

23 files changed

+238
-849
lines changed

23 files changed

+238
-849
lines changed

docs/modules/ROOT/examples/io/quarkiverse/langchain4j/samples/IngestorExampleWithChroma.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import dev.langchain4j.data.document.Document;
1111
import dev.langchain4j.model.embedding.EmbeddingModel;
1212
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
13-
import io.quarkiverse.langchain4j.chroma.ChromaEmbeddingStore;
13+
import dev.langchain4j.store.embedding.chroma.ChromaEmbeddingStore;
1414

1515
@ApplicationScoped
1616
public class IngestorExampleWithChroma {

docs/modules/ROOT/pages/includes/quarkus-langchain4j-chroma.adoc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ endif::add-copy-button-to-config-props[]
3838

3939
[.description]
4040
--
41-
The container image name to use, for container based DevServices providers. If you want to use Redis Stack modules (bloom, graph, search...), use: `redis/redis-stack:latest`.
41+
The container image name to use, for container based DevServices providers.
4242

4343

4444
ifdef::add-copy-button-to-env-var[]
@@ -49,7 +49,7 @@ Environment variable: `+++QUARKUS_LANGCHAIN4J_CHROMA_DEVSERVICES_IMAGE_NAME+++`
4949
endif::add-copy-button-to-env-var[]
5050
--
5151
|string
52-
|`ghcr.io/chroma-core/chroma:0.4.15`
52+
|`ghcr.io/chroma-core/chroma:1.3.0`
5353

5454
a|icon:lock[title=Fixed at build time] [[quarkus-langchain4j-chroma_quarkus-langchain4j-chroma-devservices-port]] [.property-path]##link:#quarkus-langchain4j-chroma_quarkus-langchain4j-chroma-devservices-port[`quarkus.langchain4j.chroma.devservices.port`]##
5555
ifdef::add-copy-button-to-config-props[]
@@ -82,7 +82,7 @@ endif::add-copy-button-to-config-props[]
8282

8383
[.description]
8484
--
85-
Indicates if the Redis server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for Redis starts a new container.
85+
Indicates if the Chroma server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for Chroma starts a new container.
8686

8787
The discovery uses the `quarkus-dev-service-chroma` label. The value is configured using the `service-name` property.
8888

@@ -107,7 +107,7 @@ endif::add-copy-button-to-config-props[]
107107

108108
[.description]
109109
--
110-
The value of the `quarkus-dev-service-chroma` label attached to the started container. This property is used when `shared` is set to `true`. In this case, before starting a container, Dev Services for Redis looks for a container with the `quarkus-dev-service-chroma` label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it starts a new container with the `quarkus-dev-service-chroma` label set to the specified value.
110+
The value of the `quarkus-dev-service-chroma` label attached to the started container. This property is used when `shared` is set to `true`. In this case, before starting a container, Dev Services for Chroma looks for a container with the `quarkus-dev-service-chroma` label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it starts a new container with the `quarkus-dev-service-chroma` label set to the specified value.
111111

112112
This property is used when you need multiple shared Chroma servers.
113113

@@ -248,6 +248,27 @@ endif::add-copy-button-to-env-var[]
248248
|boolean
249249
|`false`
250250

251+
a| [[quarkus-langchain4j-chroma_quarkus-langchain4j-chroma-api-version]] [.property-path]##link:#quarkus-langchain4j-chroma_quarkus-langchain4j-chroma-api-version[`quarkus.langchain4j.chroma.api-version`]##
252+
ifdef::add-copy-button-to-config-props[]
253+
config_property_copy_button:+++quarkus.langchain4j.chroma.api-version+++[]
254+
endif::add-copy-button-to-config-props[]
255+
256+
257+
[.description]
258+
--
259+
The Chroma API version to use. V1 is deprecated (Chroma 0.x) and its support will be removed in the future. Please use Chroma 1.x which uses the V2 API.
260+
261+
262+
ifdef::add-copy-button-to-env-var[]
263+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_CHROMA_API_VERSION+++[]
264+
endif::add-copy-button-to-env-var[]
265+
ifndef::add-copy-button-to-env-var[]
266+
Environment variable: `+++QUARKUS_LANGCHAIN4J_CHROMA_API_VERSION+++`
267+
endif::add-copy-button-to-env-var[]
268+
--
269+
a|`v1`, `v2`
270+
|`v2`
271+
251272
|===
252273

253274
ifndef::no-duration-note[]

docs/modules/ROOT/pages/includes/quarkus-langchain4j-chroma_quarkus.langchain4j.adoc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ endif::add-copy-button-to-config-props[]
3838

3939
[.description]
4040
--
41-
The container image name to use, for container based DevServices providers. If you want to use Redis Stack modules (bloom, graph, search...), use: `redis/redis-stack:latest`.
41+
The container image name to use, for container based DevServices providers.
4242

4343

4444
ifdef::add-copy-button-to-env-var[]
@@ -49,7 +49,7 @@ Environment variable: `+++QUARKUS_LANGCHAIN4J_CHROMA_DEVSERVICES_IMAGE_NAME+++`
4949
endif::add-copy-button-to-env-var[]
5050
--
5151
|string
52-
|`ghcr.io/chroma-core/chroma:0.4.15`
52+
|`ghcr.io/chroma-core/chroma:1.3.0`
5353

5454
a|icon:lock[title=Fixed at build time] [[quarkus-langchain4j-chroma_quarkus-langchain4j-chroma-devservices-port]] [.property-path]##link:#quarkus-langchain4j-chroma_quarkus-langchain4j-chroma-devservices-port[`quarkus.langchain4j.chroma.devservices.port`]##
5555
ifdef::add-copy-button-to-config-props[]
@@ -82,7 +82,7 @@ endif::add-copy-button-to-config-props[]
8282

8383
[.description]
8484
--
85-
Indicates if the Redis server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for Redis starts a new container.
85+
Indicates if the Chroma server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for Chroma starts a new container.
8686

8787
The discovery uses the `quarkus-dev-service-chroma` label. The value is configured using the `service-name` property.
8888

@@ -107,7 +107,7 @@ endif::add-copy-button-to-config-props[]
107107

108108
[.description]
109109
--
110-
The value of the `quarkus-dev-service-chroma` label attached to the started container. This property is used when `shared` is set to `true`. In this case, before starting a container, Dev Services for Redis looks for a container with the `quarkus-dev-service-chroma` label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it starts a new container with the `quarkus-dev-service-chroma` label set to the specified value.
110+
The value of the `quarkus-dev-service-chroma` label attached to the started container. This property is used when `shared` is set to `true`. In this case, before starting a container, Dev Services for Chroma looks for a container with the `quarkus-dev-service-chroma` label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it starts a new container with the `quarkus-dev-service-chroma` label set to the specified value.
111111

112112
This property is used when you need multiple shared Chroma servers.
113113

@@ -248,6 +248,27 @@ endif::add-copy-button-to-env-var[]
248248
|boolean
249249
|`false`
250250

251+
a| [[quarkus-langchain4j-chroma_quarkus-langchain4j-chroma-api-version]] [.property-path]##link:#quarkus-langchain4j-chroma_quarkus-langchain4j-chroma-api-version[`quarkus.langchain4j.chroma.api-version`]##
252+
ifdef::add-copy-button-to-config-props[]
253+
config_property_copy_button:+++quarkus.langchain4j.chroma.api-version+++[]
254+
endif::add-copy-button-to-config-props[]
255+
256+
257+
[.description]
258+
--
259+
The Chroma API version to use. V1 is deprecated (Chroma 0.x) and its support will be removed in the future. Please use Chroma 1.x which uses the V2 API.
260+
261+
262+
ifdef::add-copy-button-to-env-var[]
263+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_CHROMA_API_VERSION+++[]
264+
endif::add-copy-button-to-env-var[]
265+
ifndef::add-copy-button-to-env-var[]
266+
Environment variable: `+++QUARKUS_LANGCHAIN4J_CHROMA_API_VERSION+++`
267+
endif::add-copy-button-to-env-var[]
268+
--
269+
a|`v1`, `v2`
270+
|`v2`
271+
251272
|===
252273

253274
ifndef::no-duration-note[]

embedding-stores/chroma/deployment/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
<groupId>org.testcontainers</groupId>
3030
<artifactId>chromadb</artifactId>
3131
</dependency>
32+
<dependency>
33+
<groupId>dev.langchain4j</groupId>
34+
<artifactId>langchain4j-chroma</artifactId>
35+
</dependency>
3236
<dependency>
3337
<groupId>io.quarkiverse.langchain4j</groupId>
3438
<artifactId>quarkus-langchain4j-core-deployment</artifactId>

embedding-stores/chroma/deployment/src/main/java/io/quarkiverse/langchain4j/chroma/deployment/ChromaBuildConfig.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ interface ChromaDevServicesBuildTimeConfig {
3434

3535
/**
3636
* The container image name to use, for container based DevServices providers.
37-
* If you want to use Redis Stack modules (bloom, graph, search...), use:
38-
* {@code redis/redis-stack:latest}.
3937
*/
40-
@WithDefault("ghcr.io/chroma-core/chroma:0.4.15")
38+
@WithDefault("ghcr.io/chroma-core/chroma:1.3.0")
4139
String imageName();
4240

4341
/**
@@ -48,10 +46,10 @@ interface ChromaDevServicesBuildTimeConfig {
4846
OptionalInt port();
4947

5048
/**
51-
* Indicates if the Redis server managed by Quarkus Dev Services is shared.
49+
* Indicates if the Chroma server managed by Quarkus Dev Services is shared.
5250
* When shared, Quarkus looks for running containers using label-based service discovery.
5351
* If a matching container is found, it is used, and so a second one is not started.
54-
* Otherwise, Dev Services for Redis starts a new container.
52+
* Otherwise, Dev Services for Chroma starts a new container.
5553
* <p>
5654
* The discovery uses the {@code quarkus-dev-service-chroma} label.
5755
* The value is configured using the {@code service-name} property.
@@ -64,7 +62,7 @@ interface ChromaDevServicesBuildTimeConfig {
6462
/**
6563
* The value of the {@code quarkus-dev-service-chroma} label attached to the started container.
6664
* This property is used when {@code shared} is set to {@code true}.
67-
* In this case, before starting a container, Dev Services for Redis looks for a container with the
65+
* In this case, before starting a container, Dev Services for Chroma looks for a container with the
6866
* {@code quarkus-dev-service-chroma} label
6967
* set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it
7068
* starts a new container with the {@code quarkus-dev-service-chroma} label set to the specified value.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.quarkiverse.langchain4j.chroma.deployment;
2+
3+
import org.testcontainers.containers.GenericContainer;
4+
import org.testcontainers.containers.wait.strategy.Wait;
5+
import org.testcontainers.utility.ComparableVersion;
6+
import org.testcontainers.utility.DockerImageName;
7+
8+
/**
9+
* Overriding the ChromaDBContainer from Testcontainers 1.20.x to support the v2 chroma api.
10+
* FIXME: This is temporary until we upgrade to Testcontainers 1.21.
11+
*/
12+
public class ChromaDBContainer extends GenericContainer<org.testcontainers.chromadb.ChromaDBContainer> {
13+
14+
private static final DockerImageName DEFAULT_DOCKER_IMAGE = DockerImageName.parse("chromadb/chroma");
15+
16+
private static final DockerImageName GHCR_DOCKER_IMAGE = DockerImageName.parse("ghcr.io/chroma-core/chroma");
17+
18+
public ChromaDBContainer(String dockerImageName) {
19+
this(DockerImageName.parse(dockerImageName));
20+
}
21+
22+
public ChromaDBContainer(DockerImageName dockerImageName) {
23+
this(dockerImageName, isVersion2(dockerImageName.getVersionPart()));
24+
}
25+
26+
public ChromaDBContainer(DockerImageName dockerImageName, boolean isVersion2) {
27+
super(dockerImageName);
28+
String apiPath = isVersion2 ? "/api/v2/heartbeat" : "/api/v1/heartbeat";
29+
dockerImageName.assertCompatibleWith(DEFAULT_DOCKER_IMAGE, GHCR_DOCKER_IMAGE);
30+
withExposedPorts(8000);
31+
waitingFor(Wait.forHttp(apiPath));
32+
}
33+
34+
public String getEndpoint() {
35+
return "http://" + getHost() + ":" + getFirstMappedPort();
36+
}
37+
38+
private static boolean isVersion2(String version) {
39+
if (version.equals("latest")) {
40+
return true;
41+
}
42+
43+
ComparableVersion comparableVersion = new ComparableVersion(version);
44+
if (comparableVersion.isGreaterThanOrEqualTo("1.0.0")) {
45+
return true;
46+
}
47+
48+
return false;
49+
}
50+
}

embedding-stores/chroma/deployment/src/main/java/io/quarkiverse/langchain4j/chroma/deployment/ChromaDevServicesProcessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.function.Supplier;
1111

1212
import org.jboss.logging.Logger;
13-
import org.testcontainers.chromadb.ChromaDBContainer;
1413
import org.testcontainers.utility.DockerImageName;
1514

1615
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;

embedding-stores/chroma/deployment/src/main/java/io/quarkiverse/langchain4j/chroma/deployment/ChromaProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import dev.langchain4j.data.segment.TextSegment;
1010
import dev.langchain4j.store.embedding.EmbeddingStore;
11-
import io.quarkiverse.langchain4j.chroma.ChromaEmbeddingStore;
11+
import dev.langchain4j.store.embedding.chroma.ChromaEmbeddingStore;
1212
import io.quarkiverse.langchain4j.chroma.runtime.ChromaRecorder;
1313
import io.quarkiverse.langchain4j.deployment.EmbeddingStoreBuildItem;
1414
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
@@ -43,6 +43,7 @@ public void createBean(
4343
beanProducer.produce(SyntheticBeanBuildItem
4444
.configure(CHROMA_EMBEDDING_STORE)
4545
.types(ClassType.create(EmbeddingStore.class),
46+
ClassType.create(ChromaEmbeddingStore.class),
4647
ParameterizedType.create(EmbeddingStore.class, ClassType.create(TextSegment.class)))
4748
.defaultBean()
4849
.setRuntimeInit()

embedding-stores/chroma/deployment/src/test/java/io/quarkiverse/langchain4j/chroma/deployment/ChromaEmbeddingStoreCDITest.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

embedding-stores/chroma/deployment/src/test/java/io/quarkiverse/langchain4j/chroma/deployment/ChromaEmbeddingStoreTest.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)