Bladeren bron

优化视频内容搜索逻辑,支持向量搜索和关键词搜索降级
- 调整向量搜索接口相似度阈值,从0.7提升至0.8

wangyunpeng 13 uur geleden
bovenliggende
commit
bb1da81e46

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/component/ManagerApiService.java

@@ -186,7 +186,7 @@ public class ManagerApiService {
             param.put("queryText", queryText);
             param.put("configCode", "ALL");
             param.put("topN", topN);
-            param.put("simMin", 0.7);
+            param.put("simMin", 0.8);
             String post = httpPoolClient.post(url, param.toJSONString());
             JSONObject res = JSONObject.parseObject(post);
             if (res != null && "0".equals(res.getString("code"))) {

+ 3 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/contentplatform/VideoContentItemVO.java

@@ -87,6 +87,9 @@ public class VideoContentItemVO {
     @ApiModelProperty(value = "实验id")
     private String experimentId;
 
+    @ApiModelProperty(value = "搜索来源 vector-向量搜索 manager-管理后台搜索")
+    private String searchSource;
+
     @ApiModelProperty(value = "三级渠道")
     private String channelLevel3;
 }

+ 20 - 9
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformPlanServiceImpl.java

@@ -676,19 +676,27 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
         // 调用向量搜索接口,topN 取 pageSize 的合理上限
         int topN = Math.min(pageSize, 50);
         JSONObject data = managerApiService.recallVideoWithScore(param.getTitle(), topN);
-        if (data == null) {
-            result.setTotalSize(0);
-            result.setObjs(new ArrayList<>());
-            return result;
+
+        boolean vectorEmpty = (data == null);
+        if (!vectorEmpty) {
+            JSONArray items = data.getJSONArray("items");
+            vectorEmpty = (items == null || items.isEmpty());
         }
 
-        JSONArray items = data.getJSONArray("items");
-        if (items == null || items.isEmpty()) {
-            result.setTotalSize(0);
-            result.setObjs(new ArrayList<>());
-            return result;
+        // 向量搜索为空,降级走关键词搜索
+        if (vectorEmpty) {
+            Page<VideoContentItemVO> fallbackResult = getVideoContentListByTitle(param);
+            // 标识来源为关键词搜索
+            if (fallbackResult.getObjs() != null) {
+                for (VideoContentItemVO vo : fallbackResult.getObjs()) {
+                    vo.setSearchSource("manager");
+                    vo.setExperimentId("manager_search");
+                }
+            }
+            return fallbackResult;
         }
 
+        JSONArray items = data.getJSONArray("items");
         int total = data.getIntValue("total");
         int effectiveTotalSize = Math.min(total, videoTitleSearchMaxCount);
         result.setTotalSize(effectiveTotalSize);
@@ -746,6 +754,9 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
             VideoContentItemVO vo = new VideoContentItemVO();
             vo.setVideoId(videoId);
             vo.setScore(item.getDouble("score"));
+            // 标识来源为向量搜索
+            vo.setSearchSource("vector");
+            vo.setExperimentId("vector_search");
             // 优先从视频详情中获取标题、封面、视频地址
             VideoDetail detail = videoDetailMap.get(videoId);
             if (detail != null) {