mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-15 22:46:49 +00:00
(improvement) optimize schema data change monitoring (#333)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -28,7 +28,7 @@ public class SchemaElement implements Serializable {
|
||||
|
||||
private String defaultAgg;
|
||||
|
||||
private int order;
|
||||
private double order;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
@@ -54,7 +54,11 @@ public class SemanticParseInfo {
|
||||
@Override
|
||||
public int compare(SchemaElement o1, SchemaElement o2) {
|
||||
if (o1.getOrder() != o2.getOrder()) {
|
||||
return o1.getOrder() - o2.getOrder();
|
||||
if (o1.getOrder() < o2.getOrder()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
int len1 = o1.getName().length();
|
||||
int len2 = o2.getName().length();
|
||||
|
||||
@@ -47,7 +47,9 @@ public class EmbeddingMapper extends BaseMapper {
|
||||
long modelId = Long.parseLong(modelIdStr);
|
||||
|
||||
schemaElement = getSchemaElement(modelId, schemaElement.getType(), elementId);
|
||||
|
||||
if (schemaElement == null) {
|
||||
continue;
|
||||
}
|
||||
SchemaElementMatch schemaElementMatch = SchemaElementMatch.builder()
|
||||
.element(schemaElement)
|
||||
.frequency(BaseWordBuilder.DEFAULT_FREQUENCY)
|
||||
|
||||
@@ -109,6 +109,7 @@ public abstract class RuleSemanticQuery implements SemanticQuery, Serializable {
|
||||
|
||||
for (SchemaElementMatch schemaMatch : parseInfo.getElementMatches()) {
|
||||
SchemaElement element = schemaMatch.getElement();
|
||||
element.setOrder(1 - schemaMatch.getSimilarity());
|
||||
switch (element.getType()) {
|
||||
case ID:
|
||||
SchemaElement entityElement = modelSchema.getElement(SchemaElementType.ENTITY, element.getId());
|
||||
|
||||
@@ -230,6 +230,9 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
BeanUtils.copyProperties(chatConfigResp, chatConfigRich);
|
||||
|
||||
ModelSchema modelSchema = semanticService.getModelSchema(modelId);
|
||||
if (modelSchema == null) {
|
||||
return chatConfigRich;
|
||||
}
|
||||
chatConfigRich.setBizName(modelSchema.getModel().getBizName());
|
||||
chatConfigRich.setModelName(modelSchema.getModel().getName());
|
||||
|
||||
|
||||
@@ -51,6 +51,9 @@ public class RecommendServiceImpl implements RecommendService {
|
||||
return new RecommendResp();
|
||||
}
|
||||
ModelSchema modelSchema = semanticService.getModelSchema(modelId);
|
||||
if (Objects.isNull(modelSchema)) {
|
||||
return new RecommendResp();
|
||||
}
|
||||
List<Long> drillDownDimensions = Lists.newArrayList();
|
||||
Set<SchemaElement> metricElements = modelSchema.getMetrics();
|
||||
if (recommendReq.getMetricId() != null && !CollectionUtils.isEmpty(metricElements)) {
|
||||
|
||||
@@ -5,21 +5,29 @@ import com.tencent.supersonic.common.pojo.DataEvent;
|
||||
import com.tencent.supersonic.common.pojo.enums.DictWordType;
|
||||
import com.tencent.supersonic.common.pojo.enums.EventType;
|
||||
import com.tencent.supersonic.knowledge.dictionary.DictWord;
|
||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||
import com.tencent.supersonic.knowledge.utils.HanlpHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DictUpdateListener implements ApplicationListener<DataEvent> {
|
||||
public class SchemaDictUpdateListener implements ApplicationListener<DataEvent> {
|
||||
|
||||
@Autowired
|
||||
private SchemaService schemaService;
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void onApplicationEvent(DataEvent dataEvent) {
|
||||
if (CollectionUtils.isEmpty(dataEvent.getDataItems())) {
|
||||
return;
|
||||
}
|
||||
schemaService.getCache().invalidateAll();
|
||||
dataEvent.getDataItems().forEach(dataItem -> {
|
||||
DictWord dictWord = new DictWord();
|
||||
dictWord.setWord(dataItem.getName());
|
||||
@@ -18,11 +18,11 @@ public class SchemaService {
|
||||
|
||||
|
||||
public static final String ALL_CACHE = "all";
|
||||
private static final Integer META_CACHE_TIME = 2;
|
||||
private static final Integer META_CACHE_TIME = 30;
|
||||
private SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||
|
||||
private LoadingCache<String, SemanticSchema> cache = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(META_CACHE_TIME, TimeUnit.MINUTES)
|
||||
.expireAfterWrite(META_CACHE_TIME, TimeUnit.SECONDS)
|
||||
.build(
|
||||
new CacheLoader<String, SemanticSchema>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user