mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-15 10:04:59 +08:00
【代码优化】AI:向量化的集成
This commit is contained in:
parent
f8d1fa9b49
commit
b453856864
@ -7,7 +7,6 @@ package cn.iocoder.yudao.module.ai.service.knowledge;
|
|||||||
*/
|
*/
|
||||||
public interface DocService {
|
public interface DocService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向量化文档
|
* 向量化文档
|
||||||
*/
|
*/
|
||||||
|
@ -21,24 +21,23 @@ import java.util.List;
|
|||||||
public class DocServiceImpl implements DocService {
|
public class DocServiceImpl implements DocService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
RedisVectorStore vectorStore;
|
private RedisVectorStore vectorStore;
|
||||||
@Resource
|
@Resource
|
||||||
TokenTextSplitter tokenTextSplitter;
|
private TokenTextSplitter tokenTextSplitter;
|
||||||
|
|
||||||
// TODO @xin 临时测试用,后续删
|
// TODO @xin 临时测试用,后续删
|
||||||
@Value("classpath:/webapp/test/Fel.pdf")
|
@Value("classpath:/webapp/test/Fel.pdf")
|
||||||
private org.springframework.core.io.Resource data;
|
private org.springframework.core.io.Resource data;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void embeddingDoc() {
|
public void embeddingDoc() {
|
||||||
// 读取文件
|
// 读取文件
|
||||||
org.springframework.core.io.Resource file = data;
|
TikaDocumentReader loader = new TikaDocumentReader(data);
|
||||||
TikaDocumentReader loader = new TikaDocumentReader(file);
|
|
||||||
List<Document> documents = loader.get();
|
List<Document> documents = loader.get();
|
||||||
// 文档分段
|
// 文档分段
|
||||||
List<Document> segments = tokenTextSplitter.apply(documents);
|
List<Document> segments = tokenTextSplitter.apply(documents);
|
||||||
// 向量化并存储
|
// 向量化并存储
|
||||||
vectorStore.add(segments);
|
vectorStore.add(segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
<version>${spring-ai.version}</version>
|
<version>${spring-ai.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 向量化,基于 Redis 存储,Tika 解析内容 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ai</groupId>
|
<groupId>org.springframework.ai</groupId>
|
||||||
<artifactId>spring-ai-transformers-spring-boot-starter</artifactId>
|
<artifactId>spring-ai-transformers-spring-boot-starter</artifactId>
|
||||||
@ -55,13 +56,14 @@
|
|||||||
<artifactId>spring-ai-redis-store</artifactId>
|
<artifactId>spring-ai-redis-store</artifactId>
|
||||||
<version>${spring-ai.version}</version>
|
<version>${spring-ai.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- TODO @xin:引入我们项目的 starter -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-redis</artifactId>
|
<artifactId>spring-data-redis</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.iocoder.boot</groupId>
|
<groupId>cn.iocoder.boot</groupId>
|
||||||
<artifactId>yudao-common</artifactId>
|
<artifactId>yudao-common</artifactId>
|
||||||
|
@ -30,6 +30,8 @@ import redis.clients.jedis.JedisPooled;
|
|||||||
/**
|
/**
|
||||||
* TODO @xin 先拿 spring-ai 最新代码覆盖,1.0.0-M1 跟 redis 自动配置会冲突
|
* TODO @xin 先拿 spring-ai 最新代码覆盖,1.0.0-M1 跟 redis 自动配置会冲突
|
||||||
*
|
*
|
||||||
|
* TODO 这个官方,有说啥时候 fix 哇?
|
||||||
|
*
|
||||||
* @author Christian Tzolov
|
* @author Christian Tzolov
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
*/
|
*/
|
||||||
@ -39,8 +41,6 @@ import redis.clients.jedis.JedisPooled;
|
|||||||
@EnableConfigurationProperties(RedisVectorStoreProperties.class)
|
@EnableConfigurationProperties(RedisVectorStoreProperties.class)
|
||||||
public class RedisVectorStoreAutoConfiguration {
|
public class RedisVectorStoreAutoConfiguration {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public RedisVectorStore vectorStore(EmbeddingModel embeddingModel, RedisVectorStoreProperties properties,
|
public RedisVectorStore vectorStore(EmbeddingModel embeddingModel, RedisVectorStoreProperties properties,
|
||||||
|
@ -153,7 +153,7 @@ spring:
|
|||||||
|
|
||||||
spring:
|
spring:
|
||||||
ai:
|
ai:
|
||||||
vectorstore:
|
vectorstore: # 向量存储
|
||||||
redis:
|
redis:
|
||||||
index: default-index
|
index: default-index
|
||||||
prefix: "default:"
|
prefix: "default:"
|
||||||
|
Loading…
Reference in New Issue
Block a user