(improvement)(chat) Fix the issue where the query gets stuck when two terms appear simultaneously. (#1581)

This commit is contained in:
lexluo09
2024-08-18 00:16:55 +08:00
committed by GitHub
parent 07e0ba24bc
commit 2801b27ade
2 changed files with 28 additions and 32 deletions

View File

@@ -95,43 +95,41 @@ public abstract class BaseMapper implements SchemaMapper {
private static void filterByQueryDataType(ChatQueryContext chatQueryContext, private static void filterByQueryDataType(ChatQueryContext chatQueryContext,
Predicate<SchemaElement> needRemovePredicate) { Predicate<SchemaElement> needRemovePredicate) {
chatQueryContext.getMapInfo().getDataSetElementMatches().values().stream().forEach( chatQueryContext.getMapInfo().getDataSetElementMatches().values().forEach(schemaElementMatches -> {
schemaElementMatches -> schemaElementMatches.removeIf( schemaElementMatches.removeIf(schemaElementMatch -> {
schemaElementMatch -> { SchemaElement element = schemaElementMatch.getElement();
SchemaElement element = schemaElementMatch.getElement(); SchemaElementType type = element.getType();
SchemaElementType type = element.getType();
if (SchemaElementType.ENTITY.equals(type) || SchemaElementType.DATASET.equals(type) boolean isEntityOrDatasetOrId = SchemaElementType.ENTITY.equals(type)
|| SchemaElementType.ID.equals(type)) { || SchemaElementType.DATASET.equals(type)
return false; || SchemaElementType.ID.equals(type);
}
return needRemovePredicate.test(element); return !isEntityOrDatasetOrId && needRemovePredicate.test(element);
} });
)); });
} }
public abstract void doMap(ChatQueryContext chatQueryContext); public abstract void doMap(ChatQueryContext chatQueryContext);
public void addToSchemaMap(SchemaMapInfo schemaMap, Long dataSetId, SchemaElementMatch newElementMatch) { public void addToSchemaMap(SchemaMapInfo schemaMap, Long dataSetId, SchemaElementMatch newElementMatch) {
Map<Long, List<SchemaElementMatch>> dataSetElementMatches = schemaMap.getDataSetElementMatches(); Map<Long, List<SchemaElementMatch>> dataSetElementMatches = schemaMap.getDataSetElementMatches();
List<SchemaElementMatch> schemaElementMatches = dataSetElementMatches.putIfAbsent(dataSetId, new ArrayList<>()); List<SchemaElementMatch> schemaElementMatches = dataSetElementMatches.computeIfAbsent(dataSetId,
if (schemaElementMatches == null) { k -> new ArrayList<>());
schemaElementMatches = dataSetElementMatches.get(dataSetId);
} AtomicBoolean shouldAddNew = new AtomicBoolean(true);
//remove duplication
AtomicBoolean needAddNew = new AtomicBoolean(true); schemaElementMatches.removeIf(existingElementMatch -> {
schemaElementMatches.removeIf( if (isEquals(existingElementMatch, newElementMatch)) {
existElementMatch -> { if (newElementMatch.getSimilarity() > existingElementMatch.getSimilarity()) {
if (isEquals(existElementMatch, newElementMatch)) { return true;
if (newElementMatch.getSimilarity() > existElementMatch.getSimilarity()) { } else {
return true; shouldAddNew.set(false);
} else {
needAddNew.set(false);
}
}
return false;
} }
); }
if (needAddNew.get()) { return false;
});
if (shouldAddNew.get()) {
schemaElementMatches.add(newElementMatch); schemaElementMatches.add(newElementMatch);
} }
} }

View File

@@ -47,8 +47,6 @@ public class ChatWorkflowEngine {
parseResult.setState(ParseResp.ParseState.FAILED); parseResult.setState(ParseResp.ParseState.FAILED);
parseResult.setErrorMsg("No semantic entities can be mapped against user question."); parseResult.setErrorMsg("No semantic entities can be mapped against user question.");
queryCtx.setChatWorkflowState(ChatWorkflowState.FINISHED); queryCtx.setChatWorkflowState(ChatWorkflowState.FINISHED);
} else if (queryCtx.getMapInfo().needContinueMap()) {
queryCtx.setChatWorkflowState(ChatWorkflowState.MAPPING);
} else { } else {
queryCtx.setChatWorkflowState(ChatWorkflowState.PARSING); queryCtx.setChatWorkflowState(ChatWorkflowState.PARSING);
} }