Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch / Redis / Milvus: Remove lombok and small update for IT #101

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading