From 413210277ee560bb7a2665472cd5f6c55033223c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Wed, 6 Mar 2024 22:14:08 -0600 Subject: [PATCH 1/3] Use Testcontainers Vector DBs modules in autoconfiguartion module --- spring-ai-spring-boot-autoconfigure/pom.xml | 23 ++++++- .../ChromaVectorStoreAutoConfigurationIT.java | 10 +-- .../MilvusVectorStoreAutoConfigurationIT.java | 41 +++--------- ...iateVectorStoreAutoConfigurationTests.java | 13 ++-- .../test/resources/milvus/docker-compose.yml | 62 ------------------- 5 files changed, 38 insertions(+), 111 deletions(-) delete mode 100644 spring-ai-spring-boot-autoconfigure/src/test/resources/milvus/docker-compose.yml diff --git a/spring-ai-spring-boot-autoconfigure/pom.xml b/spring-ai-spring-boot-autoconfigure/pom.xml index 19161a0887..1e0ed10ec7 100644 --- a/spring-ai-spring-boot-autoconfigure/pom.xml +++ b/spring-ai-spring-boot-autoconfigure/pom.xml @@ -295,10 +295,31 @@ test + + org.testcontainers + chromadb + 1.19.7 + test + + + + org.testcontainers + milvus + 1.19.7 + test + + org.testcontainers qdrant - 1.19.6 + 1.19.7 + test + + + + org.testcontainers + weaviate + 1.19.7 test diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/chroma/ChromaVectorStoreAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/chroma/ChromaVectorStoreAutoConfigurationIT.java index def4dd9707..7a2c1173f5 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/chroma/ChromaVectorStoreAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/chroma/ChromaVectorStoreAutoConfigurationIT.java @@ -19,7 +19,7 @@ import java.util.Map; import org.junit.jupiter.api.Test; -import org.testcontainers.containers.GenericContainer; +import org.testcontainers.chromadb.ChromaDBContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; @@ -37,19 +37,19 @@ /** * @author Christian Tzolov + * @author Eddú Meléndez */ @Testcontainers public class ChromaVectorStoreAutoConfigurationIT { @Container - static GenericContainer chromaContainer = new GenericContainer<>("ghcr.io/chroma-core/chroma:0.4.15") - .withExposedPorts(8000); + static ChromaDBContainer chroma = new ChromaDBContainer("ghcr.io/chroma-core/chroma:0.4.15"); private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(ChromaVectorStoreAutoConfiguration.class)) .withUserConfiguration(Config.class) - .withPropertyValues("spring.ai.vectorstore.chroma.client.host=http://" + chromaContainer.getHost(), - "spring.ai.vectorstore.chroma.client.port=" + chromaContainer.getMappedPort(8000), + .withPropertyValues("spring.ai.vectorstore.chroma.client.host=http://" + chroma.getHost(), + "spring.ai.vectorstore.chroma.client.port=" + chroma.getMappedPort(8000), "spring.ai.vectorstore.chroma.store.collectionName=TestCollection"); @Test diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreAutoConfigurationIT.java index a8500ed391..46f5efcdc6 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/milvus/MilvusVectorStoreAutoConfigurationIT.java @@ -15,17 +15,11 @@ */ package org.springframework.ai.autoconfigure.vectorstore.milvus; -import java.io.File; -import java.time.Duration; import java.util.List; import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.testcontainers.containers.DockerComposeContainer; -import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.springframework.ai.ResourceUtils; @@ -38,46 +32,25 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.util.FileSystemUtils; +import org.testcontainers.milvus.MilvusContainer; import static org.assertj.core.api.Assertions.assertThat; /** * @author Christian Tzolov + * @author Eddú Meléndez */ @Testcontainers public class MilvusVectorStoreAutoConfigurationIT { - private static DockerComposeContainer milvusContainer; - - private static final File TEMP_FOLDER = new File("target/test-" + UUID.randomUUID().toString()); + @Container + private static MilvusContainer milvus = new MilvusContainer("milvusdb/milvus:v2.3.8"); List documents = List.of( new Document(ResourceUtils.getText("classpath:/test/data/spring.ai.txt"), Map.of("spring", "great")), new Document(ResourceUtils.getText("classpath:/test/data/time.shelter.txt")), new Document( ResourceUtils.getText("classpath:/test/data/great.depression.txt"), Map.of("depression", "bad"))); - @BeforeAll - public static void beforeAll() { - FileSystemUtils.deleteRecursively(TEMP_FOLDER); - TEMP_FOLDER.mkdirs(); - - milvusContainer = new DockerComposeContainer(new File("src/test/resources/milvus/docker-compose.yml")) - .withEnv("DOCKER_VOLUME_DIRECTORY", TEMP_FOLDER.getAbsolutePath()) - .withExposedService("standalone", 19530) - .withExposedService("standalone", 9091, - Wait.forHttp("/healthz").forPort(9091).forStatusCode(200).forStatusCode(401)) - .waitingFor("standalone", Wait.forLogMessage(".*Proxy successfully started.*\\s", 1) - .withStartupTimeout(Duration.ofSeconds(100))); - milvusContainer.start(); - } - - @AfterAll - public static void afterAll() { - milvusContainer.stop(); - FileSystemUtils.deleteRecursively(TEMP_FOLDER); - } - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(MilvusVectorStoreAutoConfiguration.class)) .withUserConfiguration(Config.class); @@ -90,8 +63,8 @@ public void addAndSearch() { "spring.ai.vectorstore.milvus.embeddingDimension=384", "spring.ai.vectorstore.milvus.collectionName=myTestCollection", - "spring.ai.vectorstore.milvus.client.host=" + milvusContainer.getServiceHost("standalone", 19530), - "spring.ai.vectorstore.milvus.client.port=" + milvusContainer.getServicePort("standalone", 19530)) + "spring.ai.vectorstore.milvus.client.host=" + milvus.getHost(), + "spring.ai.vectorstore.milvus.client.port=" + milvus.getMappedPort(19530)) .run(context -> { VectorStore vectorStore = context.getBean(VectorStore.class); vectorStore.add(documents); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/weaviate/WeaviateVectorStoreAutoConfigurationTests.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/weaviate/WeaviateVectorStoreAutoConfigurationTests.java index 87b69c4615..676eea80c0 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/weaviate/WeaviateVectorStoreAutoConfigurationTests.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/weaviate/WeaviateVectorStoreAutoConfigurationTests.java @@ -19,7 +19,6 @@ import java.util.Map; import org.junit.jupiter.api.Test; -import org.testcontainers.containers.GenericContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; @@ -33,29 +32,25 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.testcontainers.weaviate.WeaviateContainer; import static org.assertj.core.api.Assertions.assertThat; /** * @author Christian Tzolov + * @author Eddú Meléndez */ @Testcontainers public class WeaviateVectorStoreAutoConfigurationTests { @Container - static GenericContainer weaviateContainer = new GenericContainer<>("semitechnologies/weaviate:1.22.4") - .withEnv("AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED", "true") - .withEnv("PERSISTENCE_DATA_PATH", "/var/lib/weaviate") - .withEnv("QUERY_DEFAULTS_LIMIT", "25") - .withEnv("DEFAULT_VECTORIZER_MODULE", "none") - .withEnv("CLUSTER_HOSTNAME", "node1") - .withExposedPorts(8080); + static WeaviateContainer weaviate = new WeaviateContainer("semitechnologies/weaviate:1.22.4"); private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(WeaviateVectorStoreAutoConfiguration.class)) .withUserConfiguration(Config.class) .withPropertyValues("spring.ai.vectorstore.weaviate.scheme=http", - "spring.ai.vectorstore.weaviate.host=localhost:" + weaviateContainer.getMappedPort(8080), + "spring.ai.vectorstore.weaviate.host=" + weaviate.getHttpHostAddress(), "spring.ai.vectorstore.weaviate.filter-field.country=TEXT", "spring.ai.vectorstore.weaviate.filter-field.year=NUMBER", "spring.ai.vectorstore.weaviate.filter-field.active=BOOLEAN", diff --git a/spring-ai-spring-boot-autoconfigure/src/test/resources/milvus/docker-compose.yml b/spring-ai-spring-boot-autoconfigure/src/test/resources/milvus/docker-compose.yml deleted file mode 100644 index 3648477ae0..0000000000 --- a/spring-ai-spring-boot-autoconfigure/src/test/resources/milvus/docker-compose.yml +++ /dev/null @@ -1,62 +0,0 @@ -version: '3.5' - -services: - etcd: - image: quay.io/coreos/etcd:v3.5.5 - ports: - - "2379:2379" - environment: - - ETCD_AUTO_COMPACTION_MODE=revision - - ETCD_AUTO_COMPACTION_RETENTION=1000 - - ETCD_QUOTA_BACKEND_BYTES=4294967296 - - ETCD_SNAPSHOT_COUNT=50000 - volumes: - - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd - command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd - healthcheck: - test: ["CMD", "etcdctl", "endpoint", "health"] - interval: 30s - timeout: 20s - retries: 3 - - minio: - image: minio/minio:RELEASE.2023-11-11T08-14-41Z - environment: - MINIO_ACCESS_KEY: minioadmin - MINIO_SECRET_KEY: minioadmin - ports: - - "9001:9001" - - "9000:9000" - volumes: - - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/minio:/minio_data - command: minio server /minio_data --console-address ":9001" - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] - interval: 30s - timeout: 20s - retries: 3 - - standalone: - image: milvusdb/milvus:v2.3.5 - command: ["milvus", "run", "standalone"] - environment: - ETCD_ENDPOINTS: etcd:2379 - MINIO_ADDRESS: minio:9000 - volumes: - - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"] - interval: 30s - start_period: 90s - timeout: 20s - retries: 3 - ports: - - "19530:19530" - - "9091:9091" - depends_on: - - "etcd" - - "minio" - -networks: - default: - name: milvus From 167562abe0ac009fc8b1a6c427f67371e35c53b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Wed, 6 Mar 2024 23:17:34 -0600 Subject: [PATCH 2/3] Update testcontainers version --- pom.xml | 2 +- spring-ai-spring-boot-autoconfigure/pom.xml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 57a62fd27e..d387185c45 100644 --- a/pom.xml +++ b/pom.xml @@ -131,7 +131,7 @@ 1.7.1 - 1.19.6 + 1.19.7 0.0.4 diff --git a/spring-ai-spring-boot-autoconfigure/pom.xml b/spring-ai-spring-boot-autoconfigure/pom.xml index 1e0ed10ec7..2c0f680a09 100644 --- a/spring-ai-spring-boot-autoconfigure/pom.xml +++ b/spring-ai-spring-boot-autoconfigure/pom.xml @@ -298,28 +298,28 @@ org.testcontainers chromadb - 1.19.7 + ${testcontainers.version} test org.testcontainers milvus - 1.19.7 + ${testcontainers.version} test org.testcontainers qdrant - 1.19.7 + ${testcontainers.version} test org.testcontainers weaviate - 1.19.7 + ${testcontainers.version} test From 80b6bd542d5f63851d7a906919ad0a0e55a092dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Mon, 6 May 2024 00:53:59 +0100 Subject: [PATCH 3/3] Cleanup --- spring-ai-spring-boot-autoconfigure/pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/spring-ai-spring-boot-autoconfigure/pom.xml b/spring-ai-spring-boot-autoconfigure/pom.xml index 102c832084..b47351338e 100644 --- a/spring-ai-spring-boot-autoconfigure/pom.xml +++ b/spring-ai-spring-boot-autoconfigure/pom.xml @@ -351,14 +351,12 @@ org.testcontainers chromadb - ${testcontainers.version} test org.testcontainers milvus - ${testcontainers.version} test