|
|
@@ -13,9 +13,11 @@ import com.tzld.videoVector.model.po.pgVector.ChannelDemandMatchResultExample;
|
|
|
import com.tzld.videoVector.model.vo.RecallVideoScoreVO;
|
|
|
import com.tzld.videoVector.service.VideoSearchService;
|
|
|
import com.tzld.videoVector.util.OdpsUtil;
|
|
|
+import com.tzld.videoVector.util.RedisUtils;
|
|
|
import com.tzld.videoVector.util.VectorUtils;
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
@@ -55,6 +57,19 @@ public class ChannelDemandMatchJob {
|
|
|
@Resource
|
|
|
private VideoSearchService videoSearchService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private RedisUtils redisUtils;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 召回结果Redis缓存前缀
|
|
|
+ */
|
|
|
+ private static final String RECALL_CACHE_PREFIX = "channel_demand:recall:";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 召回结果缓存过期时间(秒),默认2小时
|
|
|
+ */
|
|
|
+ private static final long RECALL_CACHE_EXPIRE = 2 * 60 * 60;
|
|
|
+
|
|
|
/**
|
|
|
* 需求匹配并发线程数(单个渠道内部的需求匹配)
|
|
|
*/
|
|
|
@@ -353,7 +368,7 @@ public class ChannelDemandMatchJob {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 执行单次召回并构建结果行
|
|
|
+ * 执行单次召回并构建结果行(支持Redis缓存,相同参数复用匹配结果)
|
|
|
*/
|
|
|
private List<ChannelDemandMatchResult> doRecall(ChannelDemandMatchResult demand, String queryText, String configCode, int topN) {
|
|
|
List<ChannelDemandMatchResult> batchRows = new ArrayList<>();
|
|
|
@@ -363,7 +378,7 @@ public class ChannelDemandMatchJob {
|
|
|
param.setConfigCode(configCode);
|
|
|
param.setTopN(topN);
|
|
|
|
|
|
- RecallVideoScoreVO scoreVO = videoSearchService.recallWithScore(param);
|
|
|
+ RecallVideoScoreVO scoreVO = getRecallResultWithCache(param);
|
|
|
if (scoreVO == null || CollectionUtils.isEmpty(scoreVO.getItems())) {
|
|
|
return batchRows;
|
|
|
}
|
|
|
@@ -390,6 +405,33 @@ public class ChannelDemandMatchJob {
|
|
|
return batchRows;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 带Redis缓存的召回:相同queryText+configCode+topN直接复用缓存结果
|
|
|
+ */
|
|
|
+ private RecallVideoScoreVO getRecallResultWithCache(RecallVideoScoreParam param) {
|
|
|
+ String cacheKey = RECALL_CACHE_PREFIX + Md5Util.encoderByMd5(
|
|
|
+ param.getQueryText() + "|" + param.getConfigCode() + "|" + param.getTopN());
|
|
|
+ try {
|
|
|
+ String cached = redisUtils.get(cacheKey);
|
|
|
+ if (cached != null) {
|
|
|
+ return JSON.parseObject(cached, RecallVideoScoreVO.class);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("读取召回缓存失败, key={}: {}", cacheKey, e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ RecallVideoScoreVO scoreVO = videoSearchService.recallWithScore(param);
|
|
|
+
|
|
|
+ if (scoreVO != null && !CollectionUtils.isEmpty(scoreVO.getItems())) {
|
|
|
+ try {
|
|
|
+ redisUtils.set(cacheKey, JSON.toJSONString(scoreVO), RECALL_CACHE_EXPIRE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("写入召回缓存失败, key={}: {}", cacheKey, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return scoreVO;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 生成确定性实验ID
|
|
|
* 格式: 渠道_线上动作_需求策略_特征点类型_视频ID_configCode_短哈希
|