Skip to content

Top-k k is a fixed constant (TOPK_K = 32); make it a per-query variable #184

Closed

Description

@zzylol

Problem

Top-k's k is the constant TOPK_K = 32 throughout:

  • sketch-bench grades every top-k row at precision@32;
  • the study measures top-k curves at 32 only;
  • rqe-optimizer prices every top-k RAQE at k = 32: heap m·32, 32 output entries, and the theory bound for the top 32.

A PromQL topk(k, …) carries its own k. A query with k > 32 is planned optimistically: lower precision and a bigger heap than priced. One with k < 32 is planned pessimistically.

Design

  • sketch-bench: a topk_k= config param on the heap top-k variants (default 32). The heap defaults to k, and a heap below k is refused. The answer is the heaviest k, and the comparator grades precision@k at it.
  • Study: top-k curves run at each k in --topk-ks (default 10, 32, 100). k ≠ 32 is keyed in the config string (topk_k=k), so k = 32 keeps its old keys.
  • rqe-optimizer:
    • Raqe.topk_k: Option<u64>, default 32;
    • heap = m·k, and eligibility requires heap ≥ (L/x)·k;
    • accuracy reads the curve at k, else at the next larger measured k; past every measured k, only the theory bound at k;
    • output cost is k entries.
  • ASAPQuery: passing the literal k into Raqe.topk_k goes into the existing ASAPQuery #804 after this lands.

The AutoSketch vs. ASAP evaluation (all top-k k = 32) is unaffected.

🤖 Generated with Claude Code

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions