20250329 简单的个人rag知识库构建

This commit is contained in:
liangjinglin 2025-03-29 22:57:09 +08:00
parent 1aabf305a4
commit 7e1e31e0bd
4 changed files with 43 additions and 6 deletions

View File

@ -36,6 +36,11 @@
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-easy-rag</artifactId>
<version>1.0.0-beta1</version>
</dependency>
<dependency> <dependency>
<groupId>dev.langchain4j</groupId> <groupId>dev.langchain4j</groupId>

View File

@ -2,26 +2,40 @@ package com.ai.config;
import com.ai.service.Assist; import com.ai.service.Assist;
import dev.langchain4j.community.model.dashscope.QwenChatModel; import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.memory.chat.MessageWindowChatMemory; import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel; import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
import dev.langchain4j.service.AiServices; import dev.langchain4j.service.AiServices;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.util.List;
@Configuration @Configuration
@RequiredArgsConstructor @RequiredArgsConstructor
public class AssistantInit { public class AssistantInit {
ChatLanguageModel qwenModel = QwenChatModel.builder() // All files in a directory, txt seems to be faster
.apiKey("sk-2f703a41fff0488e9b6888013d2ee58a")
.modelName("deepseek-v3")
.build();
@Bean @Bean
public Assist init() { public Assist init() {
ChatLanguageModel qwenModel = QwenChatModel.builder()
.apiKey("sk-2f703a41fff0488e9b6888013d2ee58a")
.modelName("deepseek-v3")
.build();
List<Document> documents = FileSystemDocumentLoader.loadDocuments("E:\\ideaProject\\liang-ai");
// for simplicity, we will use an in-memory one:
InMemoryEmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();
EmbeddingStoreIngestor.ingest(documents, embeddingStore);
return AiServices.builder(Assist.class) return AiServices.builder(Assist.class)
.chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10)) .chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))
.chatLanguageModel(qwenModel).build(); .chatLanguageModel(qwenModel)
.contentRetriever(EmbeddingStoreContentRetriever.from(embeddingStore)).build();
} }
} }

View File

@ -2,7 +2,7 @@
GET http://localhost:8080/langchain/chat?input=今天天气如何 GET http://localhost:8080/langchain/chat?input=今天天气如何
### 测试 LangChainController 的 highlevel chat 接口 ### 测试 LangChainController 的 highlevel chat 接口
GET http://localhost:8080/langchain/high/chat?input=评价一下路飞 GET http://localhost:8080/langchain/high/chat?input=请推荐3件DWALK商城的商品
### 测试 LangChainController 的 highlevel memory chat 接口 ### 测试 LangChainController 的 highlevel memory chat 接口
GET http://localhost:8080/langchain/high/memory-chat?memoryId=1&input=你好,我想要买电脑笔记本 GET http://localhost:8080/langchain/high/memory-chat?memoryId=1&input=你好,我想要买电脑笔记本

18
个人知识库 Normal file
View File

@ -0,0 +1,18 @@
梁靖林个人博客halo
地址halo.liangjl.top
账号liangjinglin
密码: 353912918a
DWALK商城 商品推荐优先级规则
1.根据本月销量推荐销量越高优先级越高考量占比50%
2.根据评分,评分越高,优先级越高 考量占比50%
3.根据评论数,评论数越多,优先级越高 考量占比10%
4.根据收藏数,收藏数越多,优先级越高 考量占比5%
DWALK商城商品情况
1.茅台 销量100 评分4 评论数100 收藏数100
2.meta50 销量200 评分5 评论数500 收藏数5000
3.机械革命 销量50 评分4.5 评论数80 收藏数100
4.潮汕牛肉丸 销量150 评分3 评论数100 收藏数20
5.风筒 销量80 评分3.5 评论数50 收藏数10
6.口红 销量30 评分4.5 评论数200 收藏数200