Skip to content

Support universal Top-K query engine #369

Closed

Description

@em3s

Background

Add a universal Top-K query engine to support precomputed ranking queries (e.g., trending lists, leaderboards, user preferences) as first-class operations.

Conceptually, topk acts as a ranking operator over Actionbase's aggregation engine (agg):

topk(agg(...))

Consequently, all aggregation logic (e.g., counts, sums, weighted multi-edge merging, time-decay) must reside within the agg layer. The topk engine is strictly responsible for performing flat O(K) ranking queries over these pre-aggregated states, ensuring a clean decoupling of write-time aggregation and read-time ranking.

Interface

topk(Target | [Filter], [Window])

The engine will support 4 query shapes:

Shape Signature Example
1 topk(Target) Most active users (All time)
2 topk(Target | Window) Trending items this week
3 topk(Target | Filter) Most purchased items by a user
4 topk(Target | Filter, Window) Recent category heavy users / User's recent purchases

Done When

  • Universal topk interface is supported, and "top purchased items per user within the last year (Shape 4)" works as the initial target.
  • Read latency remains bounded at O(K), independent of total interaction volume.
  • Comprehensive unit/integration tests and documentation are completed.

Notes

  • Decoupled Writes: Index updates for ranking must not block or bottleneck the primary write/mutation path.
  • Pre-aggregated State: Top-K lists are maintained via bucket pre-aggregation to avoid full-scan lookups.
  • Signature Degradation: Since Shape 4 is the superset query signature, implementing it with optional Filter and Window parameters naturally satisfies Shapes 1, 2, and 3 as omitted parameter fallbacks.

Activity

  1. added this to the v0.7.0 - topk milestone on Jun 1, 2026
  2. changed the title [-]Implement universal Top-K query engine[/-] [+]Support universal Top-K query engine[/+] on Jun 1, 2026
  3. em3s commented on Sep 1, 2026

    @em3s
    ContributorAuthor

    Partially resolved by #500. I'll pick up the rest later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions