feat: add DocumentStoreConfig

This commit is contained in:
Michael Yang 2024-10-22 13:22:55 +08:00
parent 7d0db2ac31
commit 61b63770c2
9 changed files with 73 additions and 13 deletions

View File

@ -0,0 +1,8 @@
package com.agentsflex.core.store;
import java.io.Serializable;
public interface DocumentStoreConfig extends Serializable {
boolean checkAvailable();
}

View File

@ -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);
}
}

View File

@ -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());

View File

@ -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);
}
}

View File

@ -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 配置<a href="https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/getting-started-java.html">elasticsearch-java</a>
*
* @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);
}
}

View File

@ -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);
}
}

View File

@ -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 配置<a href="https://opensearch.org/docs/latest/clients/java/">opensearch-java</a>
@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}