mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
(improvment)(chat) remove low-scoring queries from recommended questions (#202)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.tencent.supersonic.chat.api.pojo.request;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PageQueryInfoReq {
|
||||
@@ -11,27 +12,5 @@ public class PageQueryInfoReq {
|
||||
|
||||
private String userName;
|
||||
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public int getCurrent() {
|
||||
return current;
|
||||
}
|
||||
|
||||
public void setCurrent(int current) {
|
||||
this.current = current;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
private List<Long> ids;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
|
||||
public interface ChatQueryRepository {
|
||||
|
||||
PageInfo<QueryResp> getChatQuery(PageQueryInfoReq pageQueryInfoCommend, long chatId);
|
||||
PageInfo<QueryResp> getChatQuery(PageQueryInfoReq pageQueryInfoCommend, Long chatId);
|
||||
|
||||
List<QueryResp> queryShowCase(PageQueryInfoReq pageQueryInfoCommend, int agentId);
|
||||
|
||||
|
||||
@@ -52,15 +52,21 @@ public class ChatQueryRepositoryImpl implements ChatQueryRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<QueryResp> getChatQuery(PageQueryInfoReq pageQueryInfoCommend, long chatId) {
|
||||
public PageInfo<QueryResp> getChatQuery(PageQueryInfoReq pageQueryInfoReq, Long chatId) {
|
||||
ChatQueryDOExample example = new ChatQueryDOExample();
|
||||
example.setOrderByClause("question_id desc");
|
||||
Criteria criteria = example.createCriteria();
|
||||
criteria.andChatIdEqualTo(chatId);
|
||||
criteria.andUserNameEqualTo(pageQueryInfoCommend.getUserName());
|
||||
|
||||
PageInfo<ChatQueryDO> pageInfo = PageHelper.startPage(pageQueryInfoCommend.getCurrent(),
|
||||
pageQueryInfoCommend.getPageSize())
|
||||
if (chatId != null) {
|
||||
criteria.andChatIdEqualTo(chatId);
|
||||
}
|
||||
if (StringUtils.isNotBlank(pageQueryInfoReq.getUserName())) {
|
||||
criteria.andUserNameEqualTo(pageQueryInfoReq.getUserName());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(pageQueryInfoReq.getIds())) {
|
||||
criteria.andQuestionIdIn(pageQueryInfoReq.getIds());
|
||||
}
|
||||
PageInfo<ChatQueryDO> pageInfo = PageHelper.startPage(pageQueryInfoReq.getCurrent(),
|
||||
pageQueryInfoReq.getPageSize())
|
||||
.doSelectPageInfo(() -> chatQueryDOMapper.selectByExampleWithBLOBs(example));
|
||||
|
||||
PageInfo<QueryResp> chatQueryVOPageInfo = PageUtils.pageInfo2PageInfoVo(pageInfo);
|
||||
|
||||
@@ -23,14 +23,17 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.tencent.supersonic.chat.service.ChatService;
|
||||
import com.tencent.supersonic.chat.utils.SolvedQueryManager;
|
||||
import com.tencent.supersonic.common.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@Service("ChatService")
|
||||
@Primary
|
||||
@@ -129,8 +132,8 @@ public class ChatServiceImpl implements ChatService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<QueryResp> queryInfo(PageQueryInfoReq pageQueryInfoCommend, long chatId) {
|
||||
return chatQueryRepository.getChatQuery(pageQueryInfoCommend, chatId);
|
||||
public PageInfo<QueryResp> queryInfo(PageQueryInfoReq pageQueryInfoReq, long chatId) {
|
||||
return chatQueryRepository.getChatQuery(pageQueryInfoReq, chatId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -198,7 +201,25 @@ public class ChatServiceImpl implements ChatService {
|
||||
|
||||
@Override
|
||||
public List<SolvedQueryRecallResp> getSolvedQuery(String queryText, Integer agentId) {
|
||||
return solvedQueryManager.recallSolvedQuery(queryText, agentId);
|
||||
//1. recall solved query by queryText
|
||||
List<SolvedQueryRecallResp> solvedQueryRecallResps = solvedQueryManager.recallSolvedQuery(queryText, agentId);
|
||||
List<Long> queryIds = solvedQueryRecallResps.stream().map(SolvedQueryRecallResp::getQueryId).collect(Collectors.toList());
|
||||
PageQueryInfoReq pageQueryInfoReq = new PageQueryInfoReq();
|
||||
pageQueryInfoReq.setIds(queryIds);
|
||||
pageQueryInfoReq.setPageSize(100);
|
||||
//2. remove low score query
|
||||
int lowScoreThreshold = 3;
|
||||
PageInfo<QueryResp> queryRespPageInfo = chatQueryRepository.getChatQuery(pageQueryInfoReq, null);
|
||||
List<QueryResp> queryResps = queryRespPageInfo.getList();
|
||||
if (CollectionUtils.isEmpty(queryResps)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
Set<Long> lowScoreQueryIds = queryResps.stream().filter(queryResp ->
|
||||
queryResp.getScore() != null && queryResp.getScore() <= lowScoreThreshold)
|
||||
.map(QueryResp::getQuestionId).collect(Collectors.toSet());
|
||||
return solvedQueryRecallResps.stream().filter(solvedQueryRecallResp ->
|
||||
!lowScoreQueryIds.contains(solvedQueryRecallResp.getQueryId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user