mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
[improvement][chat]Remove deprecated SatisfactoryChecker.
This commit is contained in:
@@ -23,7 +23,7 @@ import java.util.Objects;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/** QueryTypeParser resolves query type as either METRIC or TAG, or ID. */
|
/** QueryTypeParser resolves query type as either AGGREGATE or DETAIL or ID. */
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class QueryTypeParser implements SemanticParser {
|
public class QueryTypeParser implements SemanticParser {
|
||||||
|
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
package com.tencent.supersonic.headless.chat.parser;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
|
||||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
|
||||||
import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
|
||||||
import com.tencent.supersonic.headless.chat.query.SemanticQuery;
|
|
||||||
import com.tencent.supersonic.headless.chat.query.llm.s2sql.LLMSqlQuery;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import static com.tencent.supersonic.headless.chat.parser.ParserConfig.PARSER_TEXT_LENGTH_THRESHOLD;
|
|
||||||
import static com.tencent.supersonic.headless.chat.parser.ParserConfig.PARSER_TEXT_LENGTH_THRESHOLD_LONG;
|
|
||||||
import static com.tencent.supersonic.headless.chat.parser.ParserConfig.PARSER_TEXT_LENGTH_THRESHOLD_SHORT;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This checker can be used by semantic parsers to check if query intent has already been satisfied
|
|
||||||
* by current candidate queries. If so, current parser could be skipped.
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Deprecated
|
|
||||||
public class SatisfactionChecker {
|
|
||||||
|
|
||||||
// check all the parse info in candidate
|
|
||||||
public static boolean isSkip(ChatQueryContext chatQueryContext) {
|
|
||||||
for (SemanticQuery query : chatQueryContext.getCandidateQueries()) {
|
|
||||||
if (query.getQueryMode().equals(LLMSqlQuery.QUERY_MODE)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (checkThreshold(chatQueryContext.getRequest().getQueryText(),
|
|
||||||
query.getParseInfo())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean checkThreshold(String queryText, SemanticParseInfo semanticParseInfo) {
|
|
||||||
int queryTextLength = queryText.replaceAll(" ", "").length();
|
|
||||||
double degree = semanticParseInfo.getScore() / queryTextLength;
|
|
||||||
ParserConfig parserConfig = ContextUtils.getBean(ParserConfig.class);
|
|
||||||
int textLengthThreshold =
|
|
||||||
Integer.valueOf(parserConfig.getParameterValue(PARSER_TEXT_LENGTH_THRESHOLD));
|
|
||||||
double longTextLengthThreshold =
|
|
||||||
Double.valueOf(parserConfig.getParameterValue(PARSER_TEXT_LENGTH_THRESHOLD_LONG));
|
|
||||||
double shortTextLengthThreshold =
|
|
||||||
Double.valueOf(parserConfig.getParameterValue(PARSER_TEXT_LENGTH_THRESHOLD_SHORT));
|
|
||||||
|
|
||||||
if (queryTextLength > textLengthThreshold) {
|
|
||||||
if (degree < longTextLengthThreshold) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (degree < shortTextLengthThreshold) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
log.info("queryMode:{}, degree:{}, parse info:{}", semanticParseInfo.getQueryMode(), degree,
|
|
||||||
semanticParseInfo);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user