RAG
This commit is contained in:
parent
6e91637ef2
commit
fada2aab78
10
pom.xml
10
pom.xml
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user