Jelajahi Sumber

refactor: UserProfileDkElements topN 5→30 (匹配上游每元素 50 vid 设计)

上游 e.sql alg_recsys_recall_elements_ros 每个元素倒排 cap 50 vid,
30 elements × 50 vid = 1500 vid 跟其他召回单路同量级 (YearShareCate1/2
~1500), 粗排压力对齐, 无需 strategy 内做 limit/subList 截断.

附带命名对齐: scoreStrs → scores, 跟 elements 命名风格统一
(参考 YearShareCate2 用 actVidSeq/actTypeSeq, 不加 Str 后缀的项目惯例).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
yangxiaohui 3 hari lalu
induk
melakukan
3e26cc73bd

+ 7 - 5
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/UserProfileDkElementsRecallStrategy.java

@@ -27,10 +27,12 @@ import java.util.stream.Collectors;
  *   数据源: param.userNetworkSeqFeature 里的 s_z_y_s (元素列表) + zt_gyf (归一分列表)
  *           上游 alg_user_network_seq_feature 已新增, 来自 user_element_profile_hot
  *           top_elements = UNION ALL(positive_ranked, negative_ranked), 所以归一分可能为负
- *   逻辑: (element, score) pair 按 score DESC 取前 topN 正向元素 -> 查 elements_ros_recall 倒排
+ *
+ *   逻辑: (element, score) pair 按 score DESC 取前 topN=30 正向元素 -> 一次 multiGet
+ *         elements_ros_recall:{kw} 倒排 -> 同 vid 取 max score -> 排序 -> filter
  *   只取正向 (score > 0), 避免召回用户厌恶元素
  *
- *   跟 YearShareDkElementsRecallStrategy 共用 Redis 倒排 key, 仅用户兴趣源不同
+ *   跟 YearShareDkElementsRecallStrategy 共用 Redis 倒排 key, 仅用户兴趣源 + 取法不同
  */
 @Slf4j
 @Component
@@ -45,7 +47,7 @@ public class UserProfileDkElementsRecallStrategy implements RecallStrategy {
 
     private final String CLASS_NAME = this.getClass().getSimpleName();
 
-    public static final int topN = 5;
+    public static final int topN = 30;
     public static final String PUSH_FROM = "recall_user_profile_dk_elements";
     public static final String redisKeyPrefix = "elements_ros_recall";
 
@@ -99,14 +101,14 @@ public class UserProfileDkElementsRecallStrategy implements RecallStrategy {
     }
 
     /** 组对 + 过滤负向 + 按归一分降序 + 取前 topN 个 element */
-    private List<String> pickTopPositiveElements(List<String> elements, List<String> scoreStrs) {
+    private List<String> pickTopPositiveElements(List<String> elements, List<String> scores) {
         List<Pair<String, Double>> pairs = new ArrayList<>();
         for (int i = 0; i < elements.size(); i++) {
             String element = elements.get(i);
             if (StringUtils.isBlank(element)) {
                 continue;
             }
-            double score = NumberUtils.toDouble(scoreStrs.get(i), 0.0);
+            double score = NumberUtils.toDouble(scores.get(i), 0.0);
             if (score <= 0) {
                 continue;
             }