|
|
@@ -42,7 +42,7 @@ import static com.tzld.videoVector.common.constant.VectorConstants.DEFAULT_CONFI
|
|
|
public class VideoSearchServiceImpl implements VideoSearchService {
|
|
|
|
|
|
private static final ExecutorService MATCH_EXECUTOR = new ThreadPoolExecutor(
|
|
|
- 10, 10, 60L, TimeUnit.SECONDS,
|
|
|
+ 16, 16, 60L, TimeUnit.SECONDS,
|
|
|
new LinkedBlockingQueue<>(32),
|
|
|
new ThreadPoolExecutor.CallerRunsPolicy());
|
|
|
|
|
|
@@ -681,7 +681,7 @@ public class VideoSearchServiceImpl implements VideoSearchService {
|
|
|
|
|
|
CompletableFuture<List<VideoMatchResult>> future = CompletableFuture.supplyAsync(() -> {
|
|
|
try {
|
|
|
- log.info("配置 {} 开始搜索 Top-{},向量维度: {}", cfgCode, candidateSize, queryVector.size());
|
|
|
+// log.info("配置 {} 开始搜索 Top-{},向量维度: {}", cfgCode, candidateSize, queryVector.size());
|
|
|
List<VideoMatch> matches = vectorStoreService.searchTopN(cfgCode, queryVector, candidateSize);
|
|
|
|
|
|
if (matches == null || matches.isEmpty()) {
|
|
|
@@ -709,7 +709,7 @@ public class VideoSearchServiceImpl implements VideoSearchService {
|
|
|
configResult.add(new VideoMatchResult(cfgCode, match.getVideoId(), match.getScore(), match.getText()));
|
|
|
}
|
|
|
|
|
|
- log.info("配置 {} 搜索完成,返回 {} 条结果", cfgCode, configResult.size());
|
|
|
+// log.info("配置 {} 搜索完成,返回 {} 条结果", cfgCode, configResult.size());
|
|
|
return configResult;
|
|
|
} catch (Exception e) {
|
|
|
log.error("配置 {} 搜索失败: {}", cfgCode, e.getMessage(), e);
|
|
|
@@ -731,7 +731,7 @@ public class VideoSearchServiceImpl implements VideoSearchService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- log.info("匹配完成,configCode: {},共返回 {} 条结果", param.getConfigCode(), result.size());
|
|
|
+// log.info("匹配完成,configCode: {},共返回 {} 条结果", param.getConfigCode(), result.size());
|
|
|
|
|
|
if (withDetail) {
|
|
|
// 从 Redis 获取视频基础信息并填充到结果中
|
|
|
@@ -780,27 +780,28 @@ public class VideoSearchServiceImpl implements VideoSearchService {
|
|
|
return param.getQueryVector();
|
|
|
}
|
|
|
|
|
|
- // 2. channelContentId 历史向量(查不到时降级到 queryText)
|
|
|
+ // 2. 优先检查内存缓存(同一 embeddingModel 的配置共享向量,避免重复 DB 查询)
|
|
|
+ String embeddingModel = config.getEmbeddingModel();
|
|
|
+ String cacheKey = embeddingModel != null ? embeddingModel : "__default__";
|
|
|
+ if (embeddingCache.containsKey(cacheKey)) {
|
|
|
+ return embeddingCache.get(cacheKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. channelContentId 历史向量(查不到时降级到 queryText)
|
|
|
if (StringUtils.hasText(param.getChannelContentId())) {
|
|
|
List<Float> cached = getVectorByChannelContentId(param.getChannelContentId(), config.getConfigCode());
|
|
|
if (cached != null && !cached.isEmpty()) {
|
|
|
log.info("配置 {} 命中 channelContentId 历史向量,channelContentId={}",
|
|
|
config.getConfigCode(), param.getChannelContentId());
|
|
|
+ embeddingCache.put(cacheKey, cached);
|
|
|
return cached;
|
|
|
}
|
|
|
log.info("配置 {} channelContentId={} 未命中历史向量,降级到 queryText",
|
|
|
config.getConfigCode(), param.getChannelContentId());
|
|
|
}
|
|
|
|
|
|
- // 3. queryText 向量化:按 embeddingModel 缓存
|
|
|
+ // 4. queryText 向量化
|
|
|
if (StringUtils.hasText(param.getQueryText())) {
|
|
|
- String embeddingModel = config.getEmbeddingModel();
|
|
|
- String cacheKey = embeddingModel != null ? embeddingModel : "__default__";
|
|
|
-
|
|
|
- if (embeddingCache.containsKey(cacheKey)) {
|
|
|
- return embeddingCache.get(cacheKey);
|
|
|
- }
|
|
|
-
|
|
|
// 先查 text_hash 缓存
|
|
|
String textHash = Md5Util.encoderByMd5(param.getQueryText());
|
|
|
if (StringUtils.hasText(textHash)) {
|