(improvement)(chat) solved query recall add embedding url check (#217)

Co-authored-by: jolunoluo
This commit is contained in:
LXW
2023-10-13 19:53:22 +08:00
committed by GitHub
parent 40705181a0
commit a0b4fb33c1
4 changed files with 20 additions and 0 deletions

View File

@@ -203,6 +203,9 @@ public class ChatServiceImpl implements ChatService {
public List<SolvedQueryRecallResp> getSolvedQuery(String queryText, Integer agentId) { public List<SolvedQueryRecallResp> getSolvedQuery(String queryText, Integer agentId) {
//1. recall solved query by queryText //1. recall solved query by queryText
List<SolvedQueryRecallResp> solvedQueryRecallResps = solvedQueryManager.recallSolvedQuery(queryText, agentId); List<SolvedQueryRecallResp> solvedQueryRecallResps = solvedQueryManager.recallSolvedQuery(queryText, agentId);
if (CollectionUtils.isEmpty(solvedQueryRecallResps)) {
return Lists.newArrayList();
}
List<Long> queryIds = solvedQueryRecallResps.stream() List<Long> queryIds = solvedQueryRecallResps.stream()
.map(SolvedQueryRecallResp::getQueryId).collect(Collectors.toList()); .map(SolvedQueryRecallResp::getQueryId).collect(Collectors.toList());
PageQueryInfoReq pageQueryInfoReq = new PageQueryInfoReq(); PageQueryInfoReq pageQueryInfoReq = new PageQueryInfoReq();

View File

@@ -10,6 +10,7 @@ import com.tencent.supersonic.chat.parser.plugin.embedding.EmbeddingResp;
import com.tencent.supersonic.chat.parser.plugin.embedding.RecallRetrieval; import com.tencent.supersonic.chat.parser.plugin.embedding.RecallRetrieval;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
@@ -39,6 +40,9 @@ public class SolvedQueryManager {
} }
public void saveSolvedQuery(SolvedQueryReq solvedQueryReq) { public void saveSolvedQuery(SolvedQueryReq solvedQueryReq) {
if (StringUtils.isBlank(embeddingConfig.getUrl())) {
return;
}
String queryText = solvedQueryReq.getQueryText(); String queryText = solvedQueryReq.getQueryText();
try { try {
String uniqueId = generateUniqueId(solvedQueryReq.getQueryId(), solvedQueryReq.getParseId()); String uniqueId = generateUniqueId(solvedQueryReq.getQueryId(), solvedQueryReq.getParseId());
@@ -57,6 +61,9 @@ public class SolvedQueryManager {
} }
public List<SolvedQueryRecallResp> recallSolvedQuery(String queryText, Integer agentId) { public List<SolvedQueryRecallResp> recallSolvedQuery(String queryText, Integer agentId) {
if (StringUtils.isBlank(embeddingConfig.getUrl())) {
return Lists.newArrayList();
}
List<SolvedQueryRecallResp> solvedQueryRecallResps = Lists.newArrayList(); List<SolvedQueryRecallResp> solvedQueryRecallResps = Lists.newArrayList();
try { try {
String url = embeddingConfig.getUrl() + embeddingConfig.getSolvedQueryRecallPath() + "?n_results=" String url = embeddingConfig.getUrl() + embeddingConfig.getSolvedQueryRecallPath() + "?n_results="

View File

@@ -1,5 +1,6 @@
package com.tencent.supersonic.semantic.model.infrastructure.repository; package com.tencent.supersonic.semantic.model.infrastructure.repository;
import com.clickhouse.client.internal.apache.commons.compress.utils.Lists;
import com.tencent.supersonic.semantic.model.domain.dataobject.DimensionDO; import com.tencent.supersonic.semantic.model.domain.dataobject.DimensionDO;
import com.tencent.supersonic.semantic.model.domain.dataobject.DimensionDOExample; import com.tencent.supersonic.semantic.model.domain.dataobject.DimensionDOExample;
import com.tencent.supersonic.semantic.model.domain.repository.DimensionRepository; import com.tencent.supersonic.semantic.model.domain.repository.DimensionRepository;
@@ -7,6 +8,7 @@ import com.tencent.supersonic.semantic.model.domain.pojo.DimensionFilter;
import com.tencent.supersonic.semantic.model.infrastructure.mapper.DimensionDOCustomMapper; import com.tencent.supersonic.semantic.model.infrastructure.mapper.DimensionDOCustomMapper;
import com.tencent.supersonic.semantic.model.infrastructure.mapper.DimensionDOMapper; import com.tencent.supersonic.semantic.model.infrastructure.mapper.DimensionDOMapper;
import java.util.List; import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -56,6 +58,9 @@ public class DimensionRepositoryImpl implements DimensionRepository {
@Override @Override
public List<DimensionDO> getDimensionListOfmodelIds(List<Long> modelIds) { public List<DimensionDO> getDimensionListOfmodelIds(List<Long> modelIds) {
if (CollectionUtils.isEmpty(modelIds)) {
return Lists.newArrayList();
}
DimensionDOExample dimensionDOExample = new DimensionDOExample(); DimensionDOExample dimensionDOExample = new DimensionDOExample();
dimensionDOExample.createCriteria().andModelIdIn(modelIds); dimensionDOExample.createCriteria().andModelIdIn(modelIds);
return dimensionDOMapper.selectByExampleWithBLOBs(dimensionDOExample); return dimensionDOMapper.selectByExampleWithBLOBs(dimensionDOExample);

View File

@@ -1,6 +1,7 @@
package com.tencent.supersonic.semantic.model.infrastructure.repository; package com.tencent.supersonic.semantic.model.infrastructure.repository;
import com.clickhouse.client.internal.apache.commons.compress.utils.Lists;
import com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO; import com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO;
import com.tencent.supersonic.semantic.model.domain.dataobject.MetricDOExample; import com.tencent.supersonic.semantic.model.domain.dataobject.MetricDOExample;
import com.tencent.supersonic.semantic.model.domain.pojo.MetricFilter; import com.tencent.supersonic.semantic.model.domain.pojo.MetricFilter;
@@ -8,6 +9,7 @@ import com.tencent.supersonic.semantic.model.domain.repository.MetricRepository;
import com.tencent.supersonic.semantic.model.infrastructure.mapper.MetricDOCustomMapper; import com.tencent.supersonic.semantic.model.infrastructure.mapper.MetricDOCustomMapper;
import com.tencent.supersonic.semantic.model.infrastructure.mapper.MetricDOMapper; import com.tencent.supersonic.semantic.model.infrastructure.mapper.MetricDOMapper;
import java.util.List; import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -50,6 +52,9 @@ public class MetricRepositoryImpl implements MetricRepository {
@Override @Override
public List<MetricDO> getMetricList(List<Long> modelIds) { public List<MetricDO> getMetricList(List<Long> modelIds) {
if (CollectionUtils.isEmpty(modelIds)) {
return Lists.newArrayList();
}
MetricDOExample metricDOExample = new MetricDOExample(); MetricDOExample metricDOExample = new MetricDOExample();
metricDOExample.createCriteria().andModelIdIn(modelIds); metricDOExample.createCriteria().andModelIdIn(modelIds);
return metricDOMapper.selectByExampleWithBLOBs(metricDOExample); return metricDOMapper.selectByExampleWithBLOBs(metricDOExample);