Skip to content

fix(optimizer): recall-SLA-aware topk bind — CMS-heap when recall is loose (~60× cheaper) - #371

Merged
zzylol merged 1 commit into
mainfrom
fix/topk-bind-recall-aware
Jun 12, 2026
Merged

zzylol merged 1 commit into
mainfrom
fix/topk-bind-recall-aware

Conversation

@zzylol

@zzylol zzylol commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

The Fig-12 harness found the optimizer hard-binds topk → CountSketch (~250 KB wire state) where a CMS-with-heap (~4 KB) answers approximate heavy-hitter queries fine under a loose recall SLA — ~60× more expensive than necessary (the harness P95 cost-gap tail).

Fix (sketch_algebra/rules/bind_cms_topk.rs): BindCountSketchOnTopK is now recall-tier-aware — Loose → {CMS-heap, CountSketch}, Tight → {CountSketch} — with a cost-min tie-break over the SLA-meeting set (the same min-cost-s.t.-SLA the oracle uses). Loose-recall topk → CMS-heap; exact/tight → CountSketch (unbiased). bind_workload_typed routes pinned picks via the new apply_with_tier.

Cost: loose-recall topk drops 250,200 → 4,200 B/flush (~59.6×), from the optimizer's own wire.rs table.

Recall source: no per-query recall field today (AccuracyTarget is a frequency budget) → tier inferred conservatively (Exact→Tight, else Loose=cheap). Follow-up: thread a real recall@k/signed target. Servability confirmed end-to-end (Cms{with_heap} → FrequencyTopk).

Tests: 3 new (loose→CMS-heap, tight→CountSketch, cost-min pick) + fixed the old hard-bind test. cargo build/test -p control_plane green except one pre-existing unrelated failure (invalid_sketch_type_override_falls_back_to_default, verified on main via git stash).

🤖 Generated with Claude Code

The Fig-12 harness flagged a P95 cost-gap tail: BindCountSketchOnTopK
hard-bound every non-exact top-k to CountSketch (~250 KB wire state)
when a Count-Min-with-heap (~4 KB) answers approximate heavy-hitter
queries fine under a loose recall SLA — ~66x more expensive than
necessary.

Make the top-k binding recall-tier-aware and cost-aware:
  * Loose recall (recall@k >= ~0.9, no signed/exact-rank need; the
    common case) -> CMS-with-heap (cheap, one-sided over-estimate).
  * Tight recall (exact rank / signed / two-sided) -> CountSketch-
    with-heap (unbiased median-of-rows).

The tie-break among families that meet the SLA uses the existing
optimizer::cost::wire cost table — the same "min cost s.t. SLA" the
oracle uses; for a loose SLA both clear the bar so the cheaper CMS-heap
wins. The CMS-with-heap emit path is already servable end-to-end
(stage_config promotes with_heap to CountMinSketchWithHeap;
asap_tier_analysis maps it to FrequencyTopk(CmsWithHeap)).

No per-query recall field exists yet, so the tier is inferred from the
accuracy target (Exact -> Tight, else Loose); threading a real per-query
recall@k target is the follow-up. bind_workload_typed keeps its pinned-
family routing via the new apply_with_tier entry point (CountSketch pick
-> Tight, CMS-on-topk pick -> Loose), so contract-row mappings are
unchanged. The redundant bind_cms_with_heap_on_topk helper is removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit cd88682 into main Jun 12, 2026
@zzylol
zzylol deleted the fix/topk-bind-recall-aware branch June 12, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant