This commit is contained in:
huangge1199 2025-07-12 13:08:59 +08:00
parent 6e91637ef2
commit fada2aab78
4 changed files with 29 additions and 14 deletions

10
pom.xml
View File

@ -55,11 +55,11 @@
<artifactId>langchain4j</artifactId>
<version>1.1.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>dev.langchain4j</groupId>-->
<!-- <artifactId>langchain4j-spring-boot-starter</artifactId>-->
<!-- <version>1.1.0-beta7</version>-->
<!-- </dependency>-->
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-spring-boot-starter</artifactId>
<version>1.1.0-beta7</version>
</dependency>
</dependencies>
<build>

View File

@ -40,22 +40,19 @@ public class RagConfig {
EmbeddingStoreIngestor ingestor = EmbeddingStoreIngestor.builder()
.documentSplitter(documentByParagraphSplitter)
.textSegmentTransformer(textSegment -> {
return TextSegment.from(
textSegment.metadata().getString("file_name") + "\n" + textSegment.text(),
textSegment.metadata()
);
})
.textSegmentTransformer(textSegment -> TextSegment.from(
textSegment.metadata().getString("file_name") + "\n" + textSegment.text(),
textSegment.metadata()
))
.embeddingModel(qwenEmbeddingModel)
.embeddingStore(embeddingStore)
.build();
ingestor.ingest(documents);
EmbeddingStoreContentRetriever contentRetriever = EmbeddingStoreContentRetriever.builder()
return EmbeddingStoreContentRetriever.builder()
.embeddingStore(embeddingStore)
.embeddingModel(qwenEmbeddingModel)
.maxResults(5)
.minScore(0.75)
.build();
return contentRetriever;
}
}

View File

@ -2,6 +2,7 @@ package com.huangge1199.ai.controller;
import com.huangge1199.ai.common.R;
import com.huangge1199.ai.service.LangChainService;
import dev.langchain4j.service.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -44,4 +45,16 @@ public class LangChainController {
LangChainService.Report result = langChainService.chatForReport(message);
return R.ok(result);
}
/**
* RAG
*
* @param message 输入信息
* @return ai返回结果
*/
@PostMapping("/chatWithRag")
public R<Result<String>> chatWithRag(@RequestBody String message) {
Result<String> result = langChainService.chatWithRag(message);
return R.ok(result);
}
}

View File

@ -1,5 +1,6 @@
package com.huangge1199.ai.service;
import dev.langchain4j.service.Result;
import dev.langchain4j.service.SystemMessage;
import java.util.List;
@ -18,5 +19,9 @@ public interface LangChainService {
@SystemMessage(fromResource = "system-prompt.txt")
Report chatForReport(String message);
record Report(String name, List<String> list){}
record Report(String name, List<String> list) {
}
@SystemMessage(fromResource = "system-prompt.txt")
Result<String> chatWithRag(String message);
}