From 61b63770c24c219da5566eba5bce8a7db8ca1075 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Tue, 22 Oct 2024 13:22:55 +0800 Subject: [PATCH] feat: add DocumentStoreConfig --- .../agentsflex/core/store/DocumentStoreConfig.java | 8 ++++++++ .../java/com/agentsflex/core/util/StringUtil.java | 11 +++++++++++ .../boot/store/aliyun/AliyunAutoConfiguration.java | 2 +- .../store/aliyun/AliyunVectorStoreConfig.java | 11 +++++++++-- .../ElasticSearchVectorStoreConfig.java | 10 ++++++++-- .../store/milvus/MilvusVectorStoreConfig.java | 11 +++++++++-- .../opensearch/OpenSearchVectorStoreConfig.java | 12 ++++++++++-- .../store/qcloud/QCloudVectorStoreConfig.java | 10 ++++++++-- .../store/redis/RedisVectorStoreConfig.java | 11 +++++++++-- 9 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 agents-flex-core/src/main/java/com/agentsflex/core/store/DocumentStoreConfig.java diff --git a/agents-flex-core/src/main/java/com/agentsflex/core/store/DocumentStoreConfig.java b/agents-flex-core/src/main/java/com/agentsflex/core/store/DocumentStoreConfig.java new file mode 100644 index 0000000..899a9d8 --- /dev/null +++ b/agents-flex-core/src/main/java/com/agentsflex/core/store/DocumentStoreConfig.java @@ -0,0 +1,8 @@ +package com.agentsflex.core.store; + +import java.io.Serializable; + +public interface DocumentStoreConfig extends Serializable { + + boolean checkAvailable(); +} diff --git a/agents-flex-core/src/main/java/com/agentsflex/core/util/StringUtil.java b/agents-flex-core/src/main/java/com/agentsflex/core/util/StringUtil.java index 23e6219..d1fadff 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/core/util/StringUtil.java +++ b/agents-flex-core/src/main/java/com/agentsflex/core/util/StringUtil.java @@ -25,6 +25,15 @@ public class StringUtil { return string != null && !string.isEmpty() && containsText(string); } + public static boolean hasText(String... strings) { + for (String string : strings) { + if (!hasText(string)) { + return false; + } + } + return true; + } + private static boolean containsText(CharSequence str) { for (int i = 0; i < str.length(); i++) { if (!Character.isWhitespace(str.charAt(i))) { @@ -55,4 +64,6 @@ public class StringUtil { public static boolean notJsonObject(String jsonString) { return !isJsonObject(jsonString); } + + } diff --git a/agents-flex-spring-boot-starter/src/main/java/com/agentsflex/spring/boot/store/aliyun/AliyunAutoConfiguration.java b/agents-flex-spring-boot-starter/src/main/java/com/agentsflex/spring/boot/store/aliyun/AliyunAutoConfiguration.java index 32fb654..3986353 100644 --- a/agents-flex-spring-boot-starter/src/main/java/com/agentsflex/spring/boot/store/aliyun/AliyunAutoConfiguration.java +++ b/agents-flex-spring-boot-starter/src/main/java/com/agentsflex/spring/boot/store/aliyun/AliyunAutoConfiguration.java @@ -20,7 +20,7 @@ public class AliyunAutoConfiguration { @Bean @ConditionalOnMissingBean public AliyunVectorStore aliyunVectorStore(AliyunProperties properties) { - AliyunVectorStoreConfig config = new AliyunVectorStoreConfig(); + AliyunVectorStoreConfig config = AliyunVectorStoreConfig.createAliyunVectorStoreConfig(); config.setApiKey(properties.getApiKey()); config.setEndpoint(properties.getEndpoint()); config.setDatabase(properties.getDatabase()); diff --git a/agents-flex-store/agents-flex-store-aliyun/src/main/java/com/agentsflex/store/aliyun/AliyunVectorStoreConfig.java b/agents-flex-store/agents-flex-store-aliyun/src/main/java/com/agentsflex/store/aliyun/AliyunVectorStoreConfig.java index 059d6b8..86293e3 100644 --- a/agents-flex-store/agents-flex-store-aliyun/src/main/java/com/agentsflex/store/aliyun/AliyunVectorStoreConfig.java +++ b/agents-flex-store/agents-flex-store-aliyun/src/main/java/com/agentsflex/store/aliyun/AliyunVectorStoreConfig.java @@ -15,17 +15,19 @@ */ package com.agentsflex.store.aliyun; -import java.io.Serializable; +import com.agentsflex.core.store.DocumentStoreConfig; +import com.agentsflex.core.util.StringUtil; /** * https://help.aliyun.com/document_detail/2510317.html */ -public class AliyunVectorStoreConfig implements Serializable { +public class AliyunVectorStoreConfig implements DocumentStoreConfig { private String endpoint; private String apiKey; private String database; private String defaultCollectionName; + public String getEndpoint() { return endpoint; } @@ -57,4 +59,9 @@ public class AliyunVectorStoreConfig implements Serializable { public void setDefaultCollectionName(String defaultCollectionName) { this.defaultCollectionName = defaultCollectionName; } + + @Override + public boolean checkAvailable() { + return StringUtil.hasText(this.endpoint, this.apiKey, this.database, this.defaultCollectionName); + } } diff --git a/agents-flex-store/agents-flex-store-elasticsearch/src/main/java/com/agentsflex/store/elasticsearch/ElasticSearchVectorStoreConfig.java b/agents-flex-store/agents-flex-store-elasticsearch/src/main/java/com/agentsflex/store/elasticsearch/ElasticSearchVectorStoreConfig.java index f95c376..e03e3cd 100644 --- a/agents-flex-store/agents-flex-store-elasticsearch/src/main/java/com/agentsflex/store/elasticsearch/ElasticSearchVectorStoreConfig.java +++ b/agents-flex-store/agents-flex-store-elasticsearch/src/main/java/com/agentsflex/store/elasticsearch/ElasticSearchVectorStoreConfig.java @@ -15,14 +15,15 @@ */ package com.agentsflex.store.elasticsearch; -import java.io.Serializable; +import com.agentsflex.core.store.DocumentStoreConfig; +import com.agentsflex.core.util.StringUtil; /** * 连接 elasticsearch 配置:elasticsearch-java * * @author songyinyin */ -public class ElasticSearchVectorStoreConfig implements Serializable { +public class ElasticSearchVectorStoreConfig implements DocumentStoreConfig { private String serverUrl = "https://localhost:9200"; @@ -73,4 +74,9 @@ public class ElasticSearchVectorStoreConfig implements Serializable { public void setDefaultIndexName(String defaultIndexName) { this.defaultIndexName = defaultIndexName; } + + @Override + public boolean checkAvailable() { + return StringUtil.hasText(this.serverUrl, this.apiKey, this.defaultIndexName); + } } diff --git a/agents-flex-store/agents-flex-store-milvus/src/main/java/com/agentsflex/store/milvus/MilvusVectorStoreConfig.java b/agents-flex-store/agents-flex-store-milvus/src/main/java/com/agentsflex/store/milvus/MilvusVectorStoreConfig.java index a4f4789..b7753fe 100644 --- a/agents-flex-store/agents-flex-store-milvus/src/main/java/com/agentsflex/store/milvus/MilvusVectorStoreConfig.java +++ b/agents-flex-store/agents-flex-store-milvus/src/main/java/com/agentsflex/store/milvus/MilvusVectorStoreConfig.java @@ -15,12 +15,13 @@ */ package com.agentsflex.store.milvus; -import java.io.Serializable; +import com.agentsflex.core.store.DocumentStoreConfig; +import com.agentsflex.core.util.StringUtil; /** * https://milvus.io/docs/install-java.md */ -public class MilvusVectorStoreConfig implements Serializable { +public class MilvusVectorStoreConfig implements DocumentStoreConfig { private String uri; private String token; private String databaseName = "default"; @@ -87,4 +88,10 @@ public class MilvusVectorStoreConfig implements Serializable { public void setPassword(String password) { this.password = password; } + + @Override + public boolean checkAvailable() { + return StringUtil.hasText(this.uri, this.token) + || StringUtil.hasText(this.uri, this.username, this.password); + } } diff --git a/agents-flex-store/agents-flex-store-opensearch/src/main/java/com/agentsflex/store/opensearch/OpenSearchVectorStoreConfig.java b/agents-flex-store/agents-flex-store-opensearch/src/main/java/com/agentsflex/store/opensearch/OpenSearchVectorStoreConfig.java index 4ff9392..2f7adaf 100644 --- a/agents-flex-store/agents-flex-store-opensearch/src/main/java/com/agentsflex/store/opensearch/OpenSearchVectorStoreConfig.java +++ b/agents-flex-store/agents-flex-store-opensearch/src/main/java/com/agentsflex/store/opensearch/OpenSearchVectorStoreConfig.java @@ -15,7 +15,8 @@ */ package com.agentsflex.store.opensearch; -import java.io.Serializable; +import com.agentsflex.core.store.DocumentStoreConfig; +import com.agentsflex.core.util.StringUtil; /** * 连接 open search 配置:opensearch-java @@ -23,7 +24,7 @@ import java.io.Serializable; * @author songyinyin * @since 2024/8/10 下午8:39 */ -public class OpenSearchVectorStoreConfig implements Serializable { +public class OpenSearchVectorStoreConfig implements DocumentStoreConfig { private String serverUrl = "https://localhost:9200"; @@ -74,4 +75,11 @@ public class OpenSearchVectorStoreConfig implements Serializable { public void setDefaultIndexName(String defaultIndexName) { this.defaultIndexName = defaultIndexName; } + + + @Override + public boolean checkAvailable() { + return StringUtil.hasText(this.serverUrl, this.apiKey) + || StringUtil.hasText(this.serverUrl, this.username, this.password); + } } diff --git a/agents-flex-store/agents-flex-store-qcloud/src/main/java/com/agentsflex/store/qcloud/QCloudVectorStoreConfig.java b/agents-flex-store/agents-flex-store-qcloud/src/main/java/com/agentsflex/store/qcloud/QCloudVectorStoreConfig.java index be4a609..84f994b 100644 --- a/agents-flex-store/agents-flex-store-qcloud/src/main/java/com/agentsflex/store/qcloud/QCloudVectorStoreConfig.java +++ b/agents-flex-store/agents-flex-store-qcloud/src/main/java/com/agentsflex/store/qcloud/QCloudVectorStoreConfig.java @@ -15,9 +15,10 @@ */ package com.agentsflex.store.qcloud; -import java.io.Serializable; +import com.agentsflex.core.store.DocumentStoreConfig; +import com.agentsflex.core.util.StringUtil; -public class QCloudVectorStoreConfig implements Serializable { +public class QCloudVectorStoreConfig implements DocumentStoreConfig { private String host; private String apiKey; @@ -65,5 +66,10 @@ public class QCloudVectorStoreConfig implements Serializable { public void setDefaultCollectionName(String defaultCollectionName) { this.defaultCollectionName = defaultCollectionName; } + + @Override + public boolean checkAvailable() { + return StringUtil.hasText(this.host, this.apiKey, this.account, this.database, this.defaultCollectionName); + } } diff --git a/agents-flex-store/agents-flex-store-redis/src/main/java/com/agentsflex/store/redis/RedisVectorStoreConfig.java b/agents-flex-store/agents-flex-store-redis/src/main/java/com/agentsflex/store/redis/RedisVectorStoreConfig.java index 4f94d81..896569f 100644 --- a/agents-flex-store/agents-flex-store-redis/src/main/java/com/agentsflex/store/redis/RedisVectorStoreConfig.java +++ b/agents-flex-store/agents-flex-store-redis/src/main/java/com/agentsflex/store/redis/RedisVectorStoreConfig.java @@ -15,9 +15,11 @@ */ package com.agentsflex.store.redis; -import java.io.Serializable; +import com.agentsflex.core.store.DocumentStoreConfig; +import com.agentsflex.core.util.StringUtil; -public class RedisVectorStoreConfig implements Serializable { + +public class RedisVectorStoreConfig implements DocumentStoreConfig { private String uri; @@ -48,4 +50,9 @@ public class RedisVectorStoreConfig implements Serializable { public void setDefaultCollectionName(String defaultCollectionName) { this.defaultCollectionName = defaultCollectionName; } + + @Override + public boolean checkAvailable() { + return StringUtil.hasText(this.uri); + } }