Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions module/user_group_hot_recall_featurestore_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package module

import (
"fmt"
"math/rand"
"sort"
"strings"

"github.com/alibaba/pairec/v2/context"
Expand Down Expand Up @@ -78,14 +78,6 @@ func (d *UserGroupHotRecallFeatureStoreDao) ListItemsByUser(user *User, context
return
}

if len(itemIds) > d.recallCount {
rand.Shuffle(len(itemIds)/2, func(i, j int) {
itemIds[i], itemIds[j] = itemIds[j], itemIds[i]
})

itemIds = itemIds[:d.recallCount]
}

for _, id := range itemIds {
strs := strings.Split(id, ":")
if len(strs) == 1 {
Expand Down Expand Up @@ -117,6 +109,12 @@ func (d *UserGroupHotRecallFeatureStoreDao) ListItemsByUser(user *User, context
}
}

sort.Sort(sort.Reverse(ItemScoreSlice(ret)))

if d.recallCount > 0 && len(ret) > d.recallCount {
return ret[:d.recallCount]
}

return
}

Expand Down
16 changes: 7 additions & 9 deletions module/user_group_hot_recall_hologres_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package module
import (
"database/sql"
"fmt"
"math/rand"
"sort"
"strings"
"sync"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

潜在Bug

  • 随机数种子缺失: 移除了math/rand包导入,但没有看到重新引入rand.Seed()的地方。如果代码中其他地方还使用了rand包,可能会导致随机数序列每次都相同,影响推荐结果的多样性。

建议

  • 如果需要随机功能,请确保在程序启动时调用rand.Seed(time.Now().UnixNano())来设置随机种子。

Expand Down Expand Up @@ -99,14 +99,6 @@ func (d *UserGroupHotRecallHologresDao) ListItemsByUser(user *User, context *con
return
}

if len(itemIds) > d.recallCount {
rand.Shuffle(len(itemIds)/2, func(i, j int) {
itemIds[i], itemIds[j] = itemIds[j], itemIds[i]
})

itemIds = itemIds[:d.recallCount]
}

for _, id := range itemIds {
strs := strings.Split(id, ":")
if len(strs) == 1 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

功能变更分析

  • 推荐算法逻辑改变: 删除了原有的随机打乱前一半元素并截取recallCount个项目的逻辑,这改变了推荐结果的生成方式。

潜在问题

  • 推荐多样性降低: 原来的随机打乱逻辑是为了增加推荐多样性,现在删除后可能导致每次返回的结果完全一致,用户体验下降。
  • 算法意图不明确: 需要确认是否真的要移除随机化逻辑,如果是业务需求变更,需要确保相关方已知悉此变化。

Expand Down Expand Up @@ -138,6 +130,12 @@ func (d *UserGroupHotRecallHologresDao) ListItemsByUser(user *User, context *con
}
}

sort.Sort(sort.Reverse(ItemScoreSlice(ret)))

if d.recallCount > 0 && len(ret) > d.recallCount {
return ret[:d.recallCount]
}

return
}

Expand Down