(improvement)(headless) Add semantic retrieval to term descriptions and extract relevant semantic information (#1468)

Co-authored-by: lxwcodemonkey
This commit is contained in:
LXW
2024-07-29 09:15:18 +08:00
committed by GitHub
parent ccd79e4830
commit 26f682cc45
7 changed files with 72 additions and 2 deletions

View File

@@ -35,6 +35,7 @@ import java.util.stream.Collectors;
public class ChatQueryContext {
private String queryText;
private String oriQueryText;
private Set<Long> dataSetIds;
private Map<Long, List<Long>> modelIdToDataSetIds;
private User user;

View File

@@ -0,0 +1,37 @@
package com.tencent.supersonic.headless.chat.mapper;
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
import com.tencent.supersonic.headless.chat.ChatQueryContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
/***
* A mapper that map the description of the term.
*/
@Slf4j
public class TermDescMapper extends BaseMapper {
@Override
public void doMap(ChatQueryContext chatQueryContext) {
List<SchemaElement> termDescriptionToMap = chatQueryContext.getMapInfo().getTermDescriptionToMap();
if (CollectionUtils.isEmpty(termDescriptionToMap)) {
if (StringUtils.isNotBlank(chatQueryContext.getOriQueryText())) {
chatQueryContext.setQueryText(chatQueryContext.getOriQueryText());
}
return;
}
if (StringUtils.isBlank(chatQueryContext.getOriQueryText())) {
chatQueryContext.setOriQueryText(chatQueryContext.getQueryText());
}
for (SchemaElement schemaElement : termDescriptionToMap) {
if (chatQueryContext.getQueryText().equals(schemaElement.getDescription())) {
schemaElement.setDescriptionMapped(true);
continue;
}
chatQueryContext.setQueryText(schemaElement.getDescription());
}
}
}