Logspace recency reranking

From wenmin-wu/ds-skills · View interactive version

Logspace recency reranking is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Rerank session candidates using log-spaced recency weights multiplied by interaction-type multipliers

How to use this skill

Skill file

Logspace Recency Reranking

Overview

When reranking items from a user's session history, assign weights that grow logarithmically from oldest to newest event. Multiply by interaction-type multipliers (orders > carts > clicks) so recent high-intent actions dominate. Accumulate weighted scores per item via Counter and return top-K.

Quick Start

import numpy as np
from collections import Counter

def rerank_by_recency(aids, types, type_multipliers={0:1, 1:6, 2:3},
                      top_k=20):
    """Rerank candidates with logspace recency + type weights.
    
    Args:
        aids: list of item IDs in chronological order
        types: list of interaction types (0=click, 1=cart, 2=order)
        type_multipliers: weight per interaction type
        top_k: number of items to return
    """
    weights = np.logspace(0.1, 1, len(aids), base=2, endpoint=True) - 1
    scores = Counter()
    for aid, w, t in zip(aids, weights, types):
        scores[aid] += w * type_multipliers[t]
    return [aid for aid, _ in scores.most_common(top_k)]

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.