[improvement][chat]Remove deprecated SatisfactoryChecker.

This commit is contained in:
jerryjzhang
2024-10-30 10:36:19 +08:00
parent 4102082f2a
commit 9644fc4207
2 changed files with 1 additions and 59 deletions

View File

@@ -23,7 +23,7 @@ import java.util.Objects;
import java.util.Set;
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
public class QueryTypeParser implements SemanticParser {

View File

@@ -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;
}
}