|
|
|
@ -1,16 +1,19 @@
|
|
|
|
|
package com.supervision.manage.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.date.TimeInterval;
|
|
|
|
|
import com.supervision.dto.QaKnowledgeDTO;
|
|
|
|
|
import com.supervision.manage.feign.QaKnowledgeManageClient;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import com.supervision.manage.service.QaKnowledgeManageService;
|
|
|
|
|
import com.supervision.model.AskTemplateQuestionLibrary;
|
|
|
|
|
import com.supervision.model.AskTemplateQuestionSimilarity;
|
|
|
|
|
import com.supervision.service.AskTemplateQuestionLibraryService;
|
|
|
|
|
import com.supervision.service.AskTemplateQuestionSimilarityService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.ai.document.Document;
|
|
|
|
|
import org.springframework.ai.vectorstore.RedisVectorStore;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@ -19,12 +22,32 @@ public class QaKnowledgeManageServiceImpl implements QaKnowledgeManageService {
|
|
|
|
|
|
|
|
|
|
private final AskTemplateQuestionLibraryService askTemplateQuestionLibraryService;
|
|
|
|
|
|
|
|
|
|
private final QaKnowledgeManageClient qaKnowledgeManageClient;
|
|
|
|
|
private final AskTemplateQuestionSimilarityService askTemplateQuestionSimilarityService;
|
|
|
|
|
|
|
|
|
|
private final RedisVectorStore redisVectorStore;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void refreshQaKnowledge() {
|
|
|
|
|
TimeInterval timer = DateUtil.timer();
|
|
|
|
|
List<QaKnowledgeDTO> queryQaKnowledge = askTemplateQuestionLibraryService.queryQaKnowledge();
|
|
|
|
|
qaKnowledgeManageClient.refreshQuestionList(queryQaKnowledge);
|
|
|
|
|
log.info("QaKnowledgeManageServiceImpl : refreshQaKnowledge耗时:{} s" , timer.intervalSecond());
|
|
|
|
|
// 修改为手动刷新向量库
|
|
|
|
|
List<AskTemplateQuestionLibrary> list = askTemplateQuestionLibraryService.list();
|
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (AskTemplateQuestionLibrary askTemplateQuestionLibrary : list) {
|
|
|
|
|
String description = askTemplateQuestionLibrary.getStandardQuestion();
|
|
|
|
|
redisVectorStore.add(List.of(new Document(description,
|
|
|
|
|
Map.of("type", "1",
|
|
|
|
|
"libraryQuestionId", askTemplateQuestionLibrary.getId(),
|
|
|
|
|
"matchQuestionId", askTemplateQuestionLibrary.getId(),
|
|
|
|
|
"dictId", String.valueOf(askTemplateQuestionLibrary.getDictId())))));
|
|
|
|
|
List<AskTemplateQuestionSimilarity> similarityList = askTemplateQuestionSimilarityService.lambdaQuery().eq(AskTemplateQuestionSimilarity::getLibraryId, askTemplateQuestionLibrary.getId()).list();
|
|
|
|
|
for (AskTemplateQuestionSimilarity askTemplateQuestionSimilarity : similarityList) {
|
|
|
|
|
redisVectorStore.add(List.of(new Document(askTemplateQuestionSimilarity.getSimilarityQuestion(),
|
|
|
|
|
Map.of("type", "2",
|
|
|
|
|
"libraryQuestionId", askTemplateQuestionSimilarity.getLibraryId(),
|
|
|
|
|
"matchQuestionId", askTemplateQuestionSimilarity.getId(),
|
|
|
|
|
"dictId", String.valueOf(askTemplateQuestionLibrary.getDictId())))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|