Skip to content

Commit

Permalink
Elasticsearch / Redis / Milvus: Remove lombok and small update for IT (
Browse files Browse the repository at this point in the history
…#101)

<!--
Thank you so much for your contribution!

Please fill in all the sections below.
Please open the PR as a draft initially. Once it is reviewed and
approved, we will ask you to add documentation and examples.
Please note that PRs with breaking changes or without tests will be
rejected.

Please note that PRs will be reviewed based on the priority of the
issues they address.
We ask for your patience. We are doing our best to review your PR as
quickly as possible.
Please refrain from pinging and asking when it will be reviewed. Thank
you for understanding!
-->

## Issue
<!-- Please specify the ID of the issue this PR is addressing. For
example: "Closes #1234" or "Fixes #1234" -->
Closes
[langchain4j#2336](langchain4j/langchain4j#2336)

## Change
<!-- Please describe the changes you made. -->

1. Remove `lombok` in Elasticsearch / Redis / Milvus
2. Configure `maven-source-plugin:test-jar-no-fork` for
`langchain4j-spring-boot-tests`, in order to see test source in
community repo.
3. Redis: update `prefix` parameter introducing in [this
PR](langchain4j/langchain4j#1981)

## General checklist
<!-- Please double-check the following points and mark them like this:
[X] -->
- [x] There are no breaking changes
- [ ] I have added unit and/or integration tests for my change
- [ ] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
  • Loading branch information
Martin7-1 authored Jan 3, 2025
1 parent 38346a6 commit c4fccf5
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 75 deletions.
7 changes: 0 additions & 7 deletions langchain4j-elasticsearch-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@
<optional>true</optional>
</dependency>

<!-- should be listed before spring-boot-configuration-processor -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<!-- needed to generate automatic metadata about available config properties -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package dev.langchain4j.store.embedding.elasticsearch.spring;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Getter
@Setter
@ConfigurationProperties(prefix = ElasticsearchEmbeddingStoreProperties.PREFIX)
public class ElasticsearchEmbeddingStoreProperties {

Expand All @@ -21,4 +17,60 @@ public class ElasticsearchEmbeddingStoreProperties {
private String indexName;
private Boolean checkSslCertificates;
private String caCertificateAsBase64String;

public String getServerUrl() {
return serverUrl;
}

public void setServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
}

public String getApiKey() {
return apiKey;
}

public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getIndexName() {
return indexName;
}

public void setIndexName(String indexName) {
this.indexName = indexName;
}

public Boolean getCheckSslCertificates() {
return checkSslCertificates;
}

public void setCheckSslCertificates(Boolean checkSslCertificates) {
this.checkSslCertificates = checkSslCertificates;
}

public String getCaCertificateAsBase64String() {
return caCertificateAsBase64String;
}

public void setCaCertificateAsBase64String(String caCertificateAsBase64String) {
this.caCertificateAsBase64String = caCertificateAsBase64String;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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.elasticsearch.client.Request;
import org.elasticsearch.client.RestClient;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -65,9 +64,12 @@ protected String dimensionPropertyKey() {
}

@Override
@SneakyThrows
protected void awaitUntilPersisted(ApplicationContext context) {
RestClient restClient = context.getBean(RestClient.class);
restClient.performRequest(new Request("POST", "/" + indexName + "/_refresh"));
try {
RestClient restClient = context.getBean(RestClient.class);
restClient.performRequest(new Request("POST", "/" + indexName + "/_refresh"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
7 changes: 0 additions & 7 deletions langchain4j-milvus-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
<optional>true</optional>
</dependency>

<!-- should be listed before spring-boot-configuration-processor -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<!-- needed to generate automatic metadata about available config properties -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
import io.milvus.common.clientenum.ConsistencyLevelEnum;
import io.milvus.param.IndexType;
import io.milvus.param.MetricType;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import static io.milvus.common.clientenum.ConsistencyLevelEnum.STRONG;

@Getter
@Setter
@ConfigurationProperties(prefix = MilvusEmbeddingStoreProperties.PREFIX)
public class MilvusEmbeddingStoreProperties {

Expand All @@ -34,4 +30,116 @@ public class MilvusEmbeddingStoreProperties {
private Boolean retrieveEmbeddingsOnSearch;
private Boolean autoFlushOnInsert;
private String databaseName;

public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}

public Integer getPort() {
return port;
}

public void setPort(Integer port) {
this.port = port;
}

public String getCollectionName() {
return collectionName;
}

public void setCollectionName(String collectionName) {
this.collectionName = collectionName;
}

public Integer getDimension() {
return dimension;
}

public void setDimension(Integer dimension) {
this.dimension = dimension;
}

public IndexType getIndexType() {
return indexType;
}

public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}

public MetricType getMetricType() {
return metricType;
}

public void setMetricType(MetricType metricType) {
this.metricType = metricType;
}

public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri = uri;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public ConsistencyLevelEnum getConsistencyLevel() {
return consistencyLevel;
}

public void setConsistencyLevel(ConsistencyLevelEnum consistencyLevel) {
this.consistencyLevel = consistencyLevel;
}

public Boolean getRetrieveEmbeddingsOnSearch() {
return retrieveEmbeddingsOnSearch;
}

public void setRetrieveEmbeddingsOnSearch(Boolean retrieveEmbeddingsOnSearch) {
this.retrieveEmbeddingsOnSearch = retrieveEmbeddingsOnSearch;
}

public Boolean getAutoFlushOnInsert() {
return autoFlushOnInsert;
}

public void setAutoFlushOnInsert(Boolean autoFlushOnInsert) {
this.autoFlushOnInsert = autoFlushOnInsert;
}

public String getDatabaseName() {
return databaseName;
}

public void setDatabaseName(String databaseName) {
this.databaseName = databaseName;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.onnx.allminilml6v2q.AllMiniLmL6V2QuantizedEmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.milvus.MilvusEmbeddingStore;
import dev.langchain4j.store.embedding.milvus.spring.MilvusEmbeddingStoreAutoConfiguration;
import dev.langchain4j.store.embedding.spring.EmbeddingStoreAutoConfigurationIT;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.testcontainers.milvus.MilvusContainer;

import static dev.langchain4j.internal.Utils.randomUUID;

class MilvusEmbeddingStoreAutoConfigurationIT extends EmbeddingStoreAutoConfigurationIT {

static MilvusContainer milvus = new MilvusContainer("milvusdb/milvus:v2.3.16");
static final String COLLECTION_NAME = "test_collection";

String collectionName;

@BeforeEach
void setCollectionName() {
collectionName = "langchain4j" + randomUUID().replace("-", "_");
}

@BeforeAll
static void beforeAll() {
Expand All @@ -26,20 +31,6 @@ static void afterAll() {
milvus.stop();
}

@BeforeEach
void beforeEach() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(autoConfigurationClass()));

contextRunner
.withBean(AllMiniLmL6V2QuantizedEmbeddingModel.class)
.withPropertyValues(properties())
.run(context -> {
MilvusEmbeddingStore embeddingStore = context.getBean(MilvusEmbeddingStore.class);
embeddingStore.dropCollection(COLLECTION_NAME);
});
}

@Override
protected Class<?> autoConfigurationClass() {
return MilvusEmbeddingStoreAutoConfiguration.class;
Expand All @@ -55,7 +46,7 @@ protected String[] properties() {
return new String[]{
"langchain4j.milvus.host=" + milvus.getHost(),
"langchain4j.milvus.port=" + milvus.getMappedPort(19530),
"langchain4j.milvus.collectionName=" + COLLECTION_NAME,
"langchain4j.milvus.collectionName=" + collectionName,
"langchain4j.milvus.retrieveEmbeddingsOnSearch=true"
};
}
Expand Down
11 changes: 2 additions & 9 deletions langchain4j-redis-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
<optional>true</optional>
</dependency>

<!-- should be listed before spring-boot-configuration-processor -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<!-- needed to generate automatic metadata about available config properties -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -68,9 +61,9 @@
</dependency>

<dependency>
<groupId>com.redis.testcontainers</groupId>
<groupId>com.redis</groupId>
<artifactId>testcontainers-redis</artifactId>
<version>1.6.4</version>
<version>2.2.2</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import java.util.List;
import java.util.Optional;

import static dev.langchain4j.store.embedding.redis.spring.RedisEmbeddingStoreProperties.PREFIX;
import static dev.langchain4j.store.embedding.redis.spring.RedisEmbeddingStoreProperties.CONFIG_PREFIX;

@AutoConfiguration
@EnableConfigurationProperties(RedisEmbeddingStoreProperties.class)
@ConditionalOnProperty(prefix = PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnProperty(prefix = CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
public class RedisEmbeddingStoreAutoConfiguration {

private static final String DEFAULT_HOST = "localhost";
Expand All @@ -39,6 +39,7 @@ public RedisEmbeddingStore redisEmbeddingStore(RedisEmbeddingStoreProperties pro
.port(port)
.user(properties.getUser())
.password(properties.getPassword())
.prefix(properties.getPrefix())
.indexName(indexName)
.dimension(dimension)
.metadataKeys(metadataKeys)
Expand Down
Loading

0 comments on commit c4fccf5

Please sign in to comment.