|
|
|
package org.jeecg.modules.airag.app.controller;
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.generator.SnowflakeGenerator;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import dev.langchain4j.internal.Json;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
...
|
...
|
@@ -20,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
...
|
...
|
@@ -63,7 +67,7 @@ public class QuestionEmbeddingController { |
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/add")
|
|
|
|
public Result<String> insert(@RequestBody QuestionEmbedding record) {
|
|
|
|
public Result<String> insert(@RequestBody QuestionEmbedding record) throws JsonProcessingException {
|
|
|
|
Map<String, String> airagKnowledgeMap = airagKnowledgeService.list()
|
|
|
|
.stream()
|
|
|
|
.collect(Collectors.toMap(AiragKnowledge::getId, AiragKnowledge::getName));
|
|
...
|
...
|
@@ -75,6 +79,18 @@ public class QuestionEmbeddingController { |
|
|
|
record.setKnowledgeName(knowledgeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
//1.创建matadata数据
|
|
|
|
Map<String, Object> metadata = new LinkedHashMap<>();
|
|
|
|
SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator();
|
|
|
|
metadata.put("docName", "");
|
|
|
|
String docId = String.valueOf(snowflakeGenerator.next());
|
|
|
|
metadata.put("docId", docId); // 自动生成唯一文档ID
|
|
|
|
metadata.put("knowledgeId", record.getKnowledgeId());
|
|
|
|
// 使用 Jackson 序列化 Map 到 JSON
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
String metadataJson = mapper.writeValueAsString(metadata);
|
|
|
|
// 2. 设置到embeddings对象
|
|
|
|
record.setMetadata(metadataJson);
|
|
|
|
|
|
|
|
int result = questionEmbeddingService.insert(record);
|
|
|
|
return result > 0 ? Result.OK("添加成功!") : Result.error("添加失败");
|
...
|
...
|
|