家居大模型联调,分析sop执行分析
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package com.rj.embedding;
|
||||
|
||||
import dev.langchain4j.community.store.embedding.redis.RedisEmbeddingStore;
|
||||
import dev.langchain4j.data.document.Document;
|
||||
import dev.langchain4j.data.document.DocumentSplitter;
|
||||
import dev.langchain4j.data.document.loader.ClassPathDocumentLoader;
|
||||
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
|
||||
import dev.langchain4j.data.document.parser.apache.pdfbox.ApachePdfBoxDocumentParser;
|
||||
import dev.langchain4j.data.document.splitter.DocumentSplitters;
|
||||
import dev.langchain4j.data.segment.TextSegment;
|
||||
@@ -19,16 +17,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -43,16 +32,18 @@ public class EnbedingModelConfig {
|
||||
@Lazy
|
||||
private EmbeddingModel embeddingModel;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
RedisEmbeddingStore redisEmbeddingStore;
|
||||
// 注释掉 RedisEmbeddingStore 的自动注入,避免启动时连接外部网络
|
||||
// 如果需要使用 Redis 向量数据库,请在需要时手动创建 Bean,而不是通过 @Autowired 注入
|
||||
// @Autowired
|
||||
// @Lazy
|
||||
// RedisEmbeddingStore redisEmbeddingStore;
|
||||
/**
|
||||
* 创建向量数据库操作对象
|
||||
* @return
|
||||
*/
|
||||
@Bean("myEmbeddingStoreInMemory")
|
||||
// @Primary
|
||||
public EmbeddingStore embeddingStoreInMemory() {
|
||||
public EmbeddingStore<TextSegment> embeddingStoreInMemory() {
|
||||
//1 , 加载知识库文档进 内存
|
||||
List<Document> documents =ClassPathDocumentLoader.loadDocuments("knowledge"); //暂时去掉 2025-09-20
|
||||
//2 , 构建向量数据库操作对象
|
||||
@@ -67,7 +58,7 @@ public class EnbedingModelConfig {
|
||||
|
||||
// @Bean("myEmbeddingStoreInMemory2")
|
||||
// @Primary
|
||||
public EmbeddingStore embeddingStoreInMemory2() throws IOException {
|
||||
public EmbeddingStore<TextSegment> embeddingStoreInMemory2() throws IOException {
|
||||
//1 , 加载知识库文档进 内存
|
||||
List<Document> documents1 = ClassPathDocumentLoader.loadDocuments("knowledge\\pdf",new ApachePdfBoxDocumentParser());
|
||||
// List<Document> documents2 = ClassPathDocumentLoader.loadDocuments("knowledge");
|
||||
@@ -91,7 +82,7 @@ public class EnbedingModelConfig {
|
||||
|
||||
// @Bean("myEmbeddingStoreInRedis") 不要打开,否则每次都会调用 阿里云的向量化模型 ,消耗token
|
||||
// @Primary
|
||||
public EmbeddingStore embeddingStoreInRedis(EmbeddingStore redisEmbeddingStore) throws IOException {
|
||||
public EmbeddingStore<TextSegment> embeddingStoreInRedis(EmbeddingStore<TextSegment> redisEmbeddingStore) throws IOException {
|
||||
//1 , 加载知识库文档进 内存
|
||||
List<Document> documents1 = ClassPathDocumentLoader.loadDocuments("knowledge\\pdf",new ApachePdfBoxDocumentParser());
|
||||
// List<Document> documents2 = ClassPathDocumentLoader.loadDocuments("knowledge");
|
||||
@@ -111,7 +102,7 @@ public class EnbedingModelConfig {
|
||||
|
||||
@Bean
|
||||
@Lazy
|
||||
public ContentRetriever contentRetriever(@Qualifier("myEmbeddingStoreInMemory")EmbeddingStore store){
|
||||
public ContentRetriever contentRetriever(@Qualifier("myEmbeddingStoreInMemory") EmbeddingStore<TextSegment> store){
|
||||
// 使用 @Lazy 注解延迟初始化,避免启动时连接阿里云
|
||||
// embeddingModel 也是 @Lazy 的,只有在实际使用 RAG 功能时才会初始化并连接
|
||||
EmbeddingStoreContentRetriever contentRetriever = EmbeddingStoreContentRetriever.builder()
|
||||
|
||||
Reference in New Issue
Block a user