diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 8456c3586..3ce6086f3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -7,14 +7,24 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up JDK + + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: 'maven' + - name: Build with JDK 8 (excluding modules requiring JDK 11) + run: mvn --batch-mode install -DskipITs -pl !langchain4j-opensearch + + - name: Set up JDK 11 uses: actions/setup-java@v3 with: java-version: '11' - distribution: 'adopt' - - name: Test - run: mvn --batch-mode test - + distribution: 'temurin' + cache: 'maven' + - name: Build modules requiring JDK 11 + run: mvn --batch-mode install -DskipITs -pl langchain4j-opensearch # For checking some compliance things (require a recent JDK due to plugins so in a separate step) compliance: @@ -26,6 +36,7 @@ jobs: with: java-version: '17' distribution: 'temurin' + cache: 'maven' # Check we only rely on permissive licenses in the main parts of the library: - name: License Compliance run: mvn -P compliance org.honton.chas:license-maven-plugin:compliance diff --git a/langchain4j-elasticsearch/src/main/java/dev/langchain4j/store/embedding/elasticsearch/ElasticsearchEmbeddingStore.java b/langchain4j-elasticsearch/src/main/java/dev/langchain4j/store/embedding/elasticsearch/ElasticsearchEmbeddingStore.java index c5fb45046..ecf008b62 100644 --- a/langchain4j-elasticsearch/src/main/java/dev/langchain4j/store/embedding/elasticsearch/ElasticsearchEmbeddingStore.java +++ b/langchain4j-elasticsearch/src/main/java/dev/langchain4j/store/embedding/elasticsearch/ElasticsearchEmbeddingStore.java @@ -1,34 +1,5 @@ package dev.langchain4j.store.embedding.elasticsearch; -import static dev.langchain4j.internal.Utils.isCollectionEmpty; -import static dev.langchain4j.internal.Utils.isNullOrBlank; -import static dev.langchain4j.internal.Utils.randomUUID; -import static dev.langchain4j.internal.ValidationUtils.ensureNotNull; -import static dev.langchain4j.internal.ValidationUtils.ensureTrue; -import static java.util.Collections.singletonList; -import static java.util.stream.Collectors.toList; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import org.apache.http.Header; -import org.apache.http.HttpHost; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.message.BasicHeader; -import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestClientBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.InlineScript; import co.elastic.clients.elasticsearch._types.mapping.DenseVectorProperty; @@ -48,11 +19,36 @@ import co.elastic.clients.json.jackson.JacksonJsonpMapper; import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.endpoints.BooleanResponse; import co.elastic.clients.transport.rest_client.RestClientTransport; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import dev.langchain4j.data.document.Metadata; import dev.langchain4j.data.embedding.Embedding; import dev.langchain4j.data.segment.TextSegment; import dev.langchain4j.store.embedding.EmbeddingMatch; import dev.langchain4j.store.embedding.EmbeddingStore; +import org.apache.http.Header; +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.message.BasicHeader; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestClientBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static dev.langchain4j.internal.Utils.*; +import static dev.langchain4j.internal.ValidationUtils.ensureNotNull; +import static dev.langchain4j.internal.ValidationUtils.ensureTrue; +import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.toList; /** * Represents an Elasticsearch index as an embedding store. @@ -103,9 +99,9 @@ public class ElasticsearchEmbeddingStore implements EmbeddingStore this.objectMapper = new ObjectMapper(); } - public ElasticsearchEmbeddingStore(RestClient client, String indexName) { + public ElasticsearchEmbeddingStore(RestClient restClient, String indexName) { JsonpMapper mapper = new JacksonJsonpMapper(); - ElasticsearchTransport transport = new RestClientTransport(client, mapper); + ElasticsearchTransport transport = new RestClientTransport(restClient, mapper); this.client = new ElasticsearchClient(transport); this.indexName = ensureNotNull(indexName, "indexName"); @@ -122,11 +118,12 @@ public class ElasticsearchEmbeddingStore implements EmbeddingStore private String apiKey; private String userName; private String password; - private RestClient client; + private RestClient restClient; private String indexName = "default"; /** * @param serverUrl Elasticsearch Server URL + * @return builder */ public Builder serverUrl(String serverUrl) { this.serverUrl = serverUrl; @@ -162,16 +159,18 @@ public class ElasticsearchEmbeddingStore implements EmbeddingStore /** * @param restClient Elasticsearch RestClient (optional). - * Effectively overrides all other connection parameters serverUrl, etc. + * Effectively overrides all other connection parameters like serverUrl, etc. + * @return builder */ - public Builder restClient(RestClient client) { - this.client = client; + public Builder restClient(RestClient restClient) { + this.restClient = restClient; return this; } /** * @param indexName Elasticsearch index name (optional). * Default value: "default". + * @return builder */ public Builder indexName(String indexName) { this.indexName = indexName; @@ -179,8 +178,8 @@ public class ElasticsearchEmbeddingStore implements EmbeddingStore } public ElasticsearchEmbeddingStore build() { - if (client != null) { - return new ElasticsearchEmbeddingStore(client, indexName); + if (restClient != null) { + return new ElasticsearchEmbeddingStore(restClient, indexName); } else { return new ElasticsearchEmbeddingStore(serverUrl, apiKey, userName, password, indexName); } diff --git a/langchain4j-parent/pom.xml b/langchain4j-parent/pom.xml index 5583c8e5a..a0e8e751e 100644 --- a/langchain4j-parent/pom.xml +++ b/langchain4j-parent/pom.xml @@ -200,12 +200,6 @@ ${spring-boot.version} - - org.springframework.boot - spring-boot-configuration-processor - ${spring-boot.version} - - org.apache.httpcomponents.client5 httpclient5