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

update: analyticdb+postgresql vectore #74

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
18 changes: 18 additions & 0 deletions spring-ai-alibaba-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@
<version>4.12.0</version>
</dependency>

<dependency>
<groupId>com.aliyun</groupId>
<artifactId>gpdb20160503</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>


<!-- test dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.alibaba.cloud.ai.autoconfigure.redis;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
* @author HeYQ
* @version 1.0
* @date 2024-10-27 17:12
* @describe
*/
@Component
public class GetBeanUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext = null;

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (GetBeanUtil.applicationContext == null) {
GetBeanUtil.applicationContext = applicationContext;
}
}

/**
* @return ApplicationContext
*/
public static ApplicationContext getApplicationContext() {
return applicationContext;
}

/**
* @param beanName beanName
* @return bean
*/
public static Object getBean(String beanName) {
return applicationContext.getBean(beanName);
}

/**
* @param c c
* @param <T> 泛型
* @return bean
*/
public static <T> T getBean(Class<T> c) {
return applicationContext.getBean(c);
}

/**
* @param c c
* @param name
* @param <T>
* @return T
*/
public static <T> T getBean(String name, Class<T> c) {
return getApplicationContext().getBean(name, c);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

package com.alibaba.cloud.ai.autoconfigure.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;

/**
* Redis client<br>
* @author HeYQ
* @version
*/
@Component
public class RedisClientService {

@Autowired
RedisTemplate<String, Object> redisTemplate;

/**
* @param key
* @param releaseTime
* @return
*/
public boolean lock(String key, long releaseTime) {
// 尝试获取锁
Boolean boo = redisTemplate.opsForValue().setIfAbsent(key, "0", releaseTime, TimeUnit.SECONDS);
// 判断结果
return boo != null && boo;
}

/**
* @param key
*/
public void deleteLock(String key) {
// 删除key即可释放锁
redisTemplate.delete(key);
}

public void setKeyValue(String key, String value, int timeout) {
// Set the cache key to indicate the collection exists
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
}

public String getValueByKey(String key) {
return (String) redisTemplate.opsForValue().get(key);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.alibaba.cloud.ai.autoconfigure.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
* @author HeYQ
* @version 1.0
* @date 2024-10-27 17:36
* @describe
*/
@Configuration
public class RedisConfig {

@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);

template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());
template.afterPropertiesSet();

return template;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package com.alibaba.cloud.ai.dashscope.rag;

/**
* @author HeYQ
* @version 1.0
* @date 2024-10-23 20:22
* @describe
*/
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.HashMap;
import java.util.Map;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class AnalyticdbConfig {

private String accessKeyId;

private String accessKeySecret;

private String regionId;

private String DBInstanceId;

private String managerAccount;

private String managerAccountPassword;

private String namespace;

private String namespacePassword;

private String metrics = "cosine";

private Integer readTimeout = 60000;

private Long embeddingDimension = 1536L;

public AnalyticdbConfig() {

}


public AnalyticdbConfig(String accessKeyId, String accessKeySecret, String regionId, String DBInstanceId,
String managerAccount, String managerAccountPassword,
String namespace, String namespacePassword,
String metrics, Integer readTimeout, Long embeddingDimension) {
this.accessKeyId = accessKeyId;
this.accessKeySecret = accessKeySecret;
this.regionId = regionId;
this.DBInstanceId = DBInstanceId;
this.managerAccount = managerAccount;
this.managerAccountPassword = managerAccountPassword;
this.namespace = namespace;
this.namespacePassword = namespacePassword;
this.metrics = metrics;
this.readTimeout = readTimeout;
this.embeddingDimension = embeddingDimension;
}


public Map<String, Object> toAnalyticdbClientParams() {
Map<String, Object> params = new HashMap<>();
params.put("accessKeyId", this.accessKeyId);
params.put("accessKeySecret", this.accessKeySecret);
params.put("regionId", this.regionId);
params.put("readTimeout", this.readTimeout);
return params;
}

public String getAccessKeyId() {
return accessKeyId;
}

public void setAccessKeyId(String accessKeyId) {
this.accessKeyId = accessKeyId;
}

public String getAccessKeySecret() {
return accessKeySecret;
}

public void setAccessKeySecret(String accessKeySecret) {
this.accessKeySecret = accessKeySecret;
}

public String getRegionId() {
return regionId;
}

public void setRegionId(String regionId) {
this.regionId = regionId;
}

public String getDBInstanceId() {
return DBInstanceId;
}

public void setDBInstanceId(String DBInstanceId) {
this.DBInstanceId = DBInstanceId;
}

public String getManagerAccount() {
return managerAccount;
}

public void setManagerAccount(String managerAccount) {
this.managerAccount = managerAccount;
}

public String getManagerAccountPassword() {
return managerAccountPassword;
}

public void setManagerAccountPassword(String managerAccountPassword) {
this.managerAccountPassword = managerAccountPassword;
}

public String getNamespace() {
return namespace;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
}

public String getNamespacePassword() {
return namespacePassword;
}

public void setNamespacePassword(String namespacePassword) {
this.namespacePassword = namespacePassword;
}

public String getMetrics() {
return metrics;
}

public void setMetrics(String metrics) {
this.metrics = metrics;
}

public Integer getReadTimeout() {
return readTimeout;
}

public void setReadTimeout(Integer readTimeout) {
this.readTimeout = readTimeout;
}

public Long getEmbeddingDimension() {
return embeddingDimension;
}

public void setEmbeddingDimension(Long embeddingDimension) {
this.embeddingDimension = embeddingDimension;
}
}
Loading
Loading