From aa3e7d14800803361b8929f905cc5d88e537063a Mon Sep 17 00:00:00 2001 From: Martin7-1 <1754350460@qq.com> Date: Sun, 23 Jun 2024 00:01:08 +0800 Subject: [PATCH] unified IT --- .../pom.xml | 9 +++ ...archEmbeddingStoreAutoConfigurationIT.java | 62 ++++++------------- pom.xml | 12 ---- 3 files changed, 27 insertions(+), 56 deletions(-) diff --git a/langchian4j-elasticsearch-spring-boot-starter/pom.xml b/langchian4j-elasticsearch-spring-boot-starter/pom.xml index e519b978..b7e9cc43 100644 --- a/langchian4j-elasticsearch-spring-boot-starter/pom.xml +++ b/langchian4j-elasticsearch-spring-boot-starter/pom.xml @@ -58,6 +58,15 @@ test + + dev.langchain4j + langchain4j-spring-boot-core + ${project.version} + tests + test-jar + test + + org.testcontainers elasticsearch diff --git a/langchian4j-elasticsearch-spring-boot-starter/src/test/java/dev/langchain4j/store/embedding/elasticsearch/spring/ElasticsearchEmbeddingStoreAutoConfigurationIT.java b/langchian4j-elasticsearch-spring-boot-starter/src/test/java/dev/langchain4j/store/embedding/elasticsearch/spring/ElasticsearchEmbeddingStoreAutoConfigurationIT.java index f639ddc1..033c05f6 100644 --- a/langchian4j-elasticsearch-spring-boot-starter/src/test/java/dev/langchain4j/store/embedding/elasticsearch/spring/ElasticsearchEmbeddingStoreAutoConfigurationIT.java +++ b/langchian4j-elasticsearch-spring-boot-starter/src/test/java/dev/langchain4j/store/embedding/elasticsearch/spring/ElasticsearchEmbeddingStoreAutoConfigurationIT.java @@ -1,36 +1,23 @@ package dev.langchain4j.store.embedding.elasticsearch.spring; -import dev.langchain4j.data.embedding.Embedding; import dev.langchain4j.data.segment.TextSegment; -import dev.langchain4j.model.embedding.AllMiniLmL6V2QuantizedEmbeddingModel; -import dev.langchain4j.model.embedding.EmbeddingModel; -import dev.langchain4j.store.embedding.EmbeddingMatch; import dev.langchain4j.store.embedding.EmbeddingStore; import dev.langchain4j.store.embedding.elasticsearch.ElasticsearchEmbeddingStore; +import dev.langchain4j.store.embedding.spring.EmbeddingStoreAutoConfigurationIT; import lombok.SneakyThrows; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.elasticsearch.ElasticsearchContainer; -import java.util.List; - import static dev.langchain4j.internal.Utils.randomUUID; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.data.Percentage.withPercentage; -class ElasticsearchEmbeddingStoreAutoConfigurationIT { +class ElasticsearchEmbeddingStoreAutoConfigurationIT extends EmbeddingStoreAutoConfigurationIT { static ElasticsearchContainer elasticsearch = new ElasticsearchContainer("elasticsearch:8.9.0") .withEnv("xpack.security.enabled", "false") .waitingFor(Wait.defaultWaitStrategy()); - ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(ElasticsearchEmbeddingStoreAutoConfiguration.class)); - @BeforeAll static void beforeAll() { elasticsearch.start(); @@ -41,40 +28,27 @@ static void afterAll() { elasticsearch.stop(); } - @Test - void should_provide_elasticsearch_vector_store() { - TextSegment segment = TextSegment.from("hello"); - contextRunner - .withBean(AllMiniLmL6V2QuantizedEmbeddingModel.class) - .withPropertyValues( - "langchain4j.elasticsearch.serverUrl=" + elasticsearch.getHttpHostAddress(), - "langchain4j.elasticsearch.indexName=" + randomUUID() - ) - .run(context -> { - EmbeddingModel embeddingModel = context.getBean(AllMiniLmL6V2QuantizedEmbeddingModel.class); - Embedding embedding = embeddingModel.embed(segment.text()).content(); - - EmbeddingStore embeddingStore = context.getBean(ElasticsearchEmbeddingStore.class); - assertThat(embeddingStore).isInstanceOf(ElasticsearchEmbeddingStore.class); - - String id = embeddingStore.add(embedding, segment); - assertThat(id).isNotBlank(); - - awaitUntilPersisted(); + @Override + protected Class autoConfigurationClass() { + return ElasticsearchEmbeddingStoreAutoConfiguration.class; + } - List> relevant = embeddingStore.findRelevant(embedding, 10); - assertThat(relevant).hasSize(1); + @Override + protected Class> embeddingStoreClass() { + return ElasticsearchEmbeddingStore.class; + } - EmbeddingMatch match = relevant.get(0); - assertThat(match.score()).isCloseTo(1, withPercentage(1)); - assertThat(match.embeddingId()).isEqualTo(id); - assertThat(match.embedding()).isEqualTo(embedding); - assertThat(match.embedded()).isEqualTo(segment); - }); + @Override + protected String[] properties() { + return new String[]{ + "langchain4j.elasticsearch.serverUrl=" + elasticsearch.getHttpHostAddress(), + "langchain4j.elasticsearch.indexName=" + randomUUID() + }; } + @Override @SneakyThrows - private void awaitUntilPersisted() { + protected void awaitUntilPersisted() { Thread.sleep(1000); } } diff --git a/pom.xml b/pom.xml index d9587dde..1c9e0c83 100644 --- a/pom.xml +++ b/pom.xml @@ -75,18 +75,6 @@ 1.18.32 - - org.tinylog - tinylog-impl - ${tinylog.version} - - - - org.tinylog - slf4j-tinylog - ${tinylog.version} - - org.testcontainers testcontainers-bom