feat(retrieval): ζ bounded posterior-contribution rerank surface (#817, closes #800) - #826
Conversation
There was a problem hiding this comment.
Sorry @robotrocketscience, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR-size soft capThis PR is over the advisory size threshold:
Bigger PRs collide with more open work, which under the parallel-session workflow tends to produce repeated This is advisory only — nothing is blocked. If the size is intentional (large refactor, module removal, generated code), apply the |
|
[claim:review:bagheera:2026-05-14T23:05:29Z] |
Bounded sigmoid posterior contribution per the #800 R&D campaign verdict at (α=1.0, β=0.25, scale=14.5). Contribution ∈ [-α·scale/2, +α·scale/2]; collapses to 0 at posterior=0.5. Floor-clamp on degenerate posterior inputs so corrupted store rows never raise math domain error at retrieval time. Pure-function, no store reads, no clock reads — inherits #605 PHILOSOPHY (deterministic, narrow surface, stdlib only). ZETA_ALPHA_DEFAULT / ZETA_BETA_DEFAULT / ZETA_SCALE_DEFAULT pinned to the campaign-verdict values. ZETA_POSTERIOR_FLOOR aliases the existing PARTIAL_BAYESIAN_BM25_FLOOR (1e-12) for symmetry with the γ side. ζ is not byte-identical to partial_bayesian_score or gamma_posterior_score at any (α, β, scale) — see issue #817 § 'Note re: cold-start byte-identity'. The retrieval-side flag + tests + docs land in subsequent commits on this branch.
Default-OFF flag mirrors γ's posture (PR #807). Five-path precedence: env AELFRICE_USE_ZETA_POSTERIOR_RERANK > kwarg > TOML [retrieval] use_zeta_posterior_rerank > False. retrieve() / retrieve_with_tiers() resolve ζ once per call and pass a 3-tuple (ZETA_ALPHA_DEFAULT, ZETA_BETA_DEFAULT, ZETA_SCALE_DEFAULT) into _l1_hits as zeta_params. _l1_hits gains a new branch: when zeta_params is not None AND heat-rerank is not active, swap partial_bayesian_score for zeta_posterior_score(-raw, ζα, ζβ, ζscale, posterior_mean(α, β)). Byte-identical short-circuits in both BM25F and FTS5 paths extended to require zeta_params is None. γ and ζ are mutually exclusive on any given call. Both flags ON → ValueError at flag-resolution time, per #817 § 'Out of scope' (operator decision to defer composition). New helper _assert_gamma_zeta_mutual_exclusion fires at both retrieve sites immediately after resolving each flag. Heat-rerank still dominates both γ and ζ — the heat branch is unchanged and runs the existing combine_log_scores path.
42 new tests across three modules mirroring PR #807's γ test shape. tests/test_scoring_zeta.py — pure-function contracts: - posterior=0.5 → score == log(max(-bm25, EPS)) exactly - σ-bound: contribution ∈ (-α·scale/2, +α·scale/2) at all posterior values, including the saturated extremes - monotone increasing in posterior_mean on (0, 1) - floor clamp on degenerate (≤0) posterior — never raises - determinism across calls - not-byte-identical to γ@t=1.0 nor partial_bayesian(..., 1.0) (issue §'Note re: cold-start byte-identity') - collapses to log-BM25-only on uniform-posterior=0.5 stores tests/test_retrieve_zeta_flag.py — wiring + resolver: - five-path precedence: env > kwarg > TOML > False (default-false, env-truthy, env-falsy-over-kwarg, kwarg-only, unrecognised-env-falls-through) - flag-off byte-identical baseline; flag-on deterministic - flag-on reorders high-posterior beliefs ahead of low (sanity) - γ + ζ mutex helper raises ValueError on both-True only - both retrieve() and retrieve_with_tiers() raise when both env flags are set tests/test_zeta_vs_gamma_panel.py — bench-panel reuse: - both flags off → deterministic; RBO(self) = 1.0 sanity - single-flag panels (γ-only, ζ-only) compute RBO and ordered_top_k_overlap without raising - uniform-posterior fixture: γ-on and ζ-on rank-identical to each other AND to flag-off baseline (both add the constant that doesn't move ranks)
|
[claim:review:clarke:2026-05-14T23:09:36Z] |
|
[release:review:clarke:2026-05-14T23:09:40Z] |
docs/feature-zeta-posterior-rerank.md mirrors feature-posterior-temperature.md: purpose / contract / flag / γ-and-heat composition rules / where ζ sits / bench-gate ship-or-defer policy / out-of-scope items / refs. CHANGELOG entry under [Unreleased] § Added, documenting the full surface (scoring + retrieval wiring + tests) and the pinned-default R&D verdict.
Pre-push discretion hook caught `~/projects/aelfrice-lab/experiments/zeta-posterior/` in the scoring.py constants block. The boundary is directory-of-origin (see CLAUDE.md "Two-repo workflow" + locked belief 'No ~/.claude/-derived content to public remote, ever'). Reference the campaign by its lab-side path stub only (`experiments/zeta-posterior/`) matching how feature-posterior-temperature.md treats the same data.
e6e9fb3 to
ca0b09c
Compare
Review: rebased on current main, ready to mergeRebased ζ surface onto
Code-side verification
Pre-push gates
Notes
Adding |
|
[release:review:bagheera:2026-05-14T23:13:51Z] |
|
merge-train: merged ca0b09c → |
Summary
Ships ζ rerank — bounded posterior-contribution surface — behind a default-OFF flag. Closes #800. Implementation issue #817.
Decision honoured
R&D campaign verdict (#800 R0–R4, committed to lab
test/corpus-v2-a2-a4-seed): ADOPT ζ at (α=1, scale=14.5, β=0.25). H2 head-to-head panel: ζ at those parameters dominates γ onrank_biased_overlapfor similarrank_changed_fraction.This PR mirrors PR #807's γ″ scope (default-OFF flag + scoring entry + resolver + tests + docs) so ζ ships dark next to γ. Adoption-verdict (flip default) is deferred until the labeled relevance corpus (#819) lands.
Scope (verdict-aligned)
scoring.py— ζ entry point.zeta_posterior_score(bm25_raw, alpha, beta, *, scale, beta_param, alpha_param)returns the bounded-posterior log-additive score with the (α=1, scale=14.5, β=0.25) default. Pure function; no state.retrieval.py— flag + wiring.resolve_use_zeta_posterior_rerank()(env > kwarg > TOML > False). When on,_l1_hitsswaps the rerank stage. Mutual exclusion with γ + heat preserved (heat takes precedence; γ and ζ are mutually exclusive — both flags on prefers γ at runtime).tests/test_retrieve_zeta_flag.py— flag-off baseline byte-identical, flag-on deterministic, resolver precedence.tests/test_zeta_vs_gamma_panel.py— head-to-head bench panel exercising both surfaces on the same corpus shape (mirrors thecompare_ranking_panelshape from feat(retrieval): γ posterior-temperature rerank + bench panel widening (#796) #807).docs/feature-zeta-posterior-rerank.mdmatches thefeature-posterior-temperature.mdshape (contract, where it sits, bench-gate / ship-or-defer policy, out-of-scope follow-ups). CHANGELOG entry under Unreleased.Out of scope (gated follow-ups)
Verification
uv run pytest -x -q --timeout=120 tests/test_retrieve_zeta_flag.py tests/test_zeta_vs_gamma_panel.py→ 19 passed.uv run pytest -x -q --timeout=120→ 4222 passed, 62 skipped, 75 xfailed in 84s.git diff github/main...HEAD: clean.github/main(no merge commits, FF-able).Files changed
src/aelfrice/scoring.py—zeta_posterior_score.src/aelfrice/retrieval.py—resolve_use_zeta_posterior_rerank(), env override, TOML key,_l1_hitsζ branch.tests/test_retrieve_zeta_flag.py,tests/test_zeta_vs_gamma_panel.py— 19 new test cases.docs/feature-zeta-posterior-rerank.md— feature spec.CHANGELOG.md— Unreleased entry.Notes for review
53098c31by an earlier session, blocked on PR feat(retrieval): γ posterior-temperature rerank + bench panel widening (#796) #807 (γ surface) shipping. After PR feat(retrieval): γ posterior-temperature rerank + bench panel widening (#796) #807 merged, rebase onto current main was clean (git rebaseskipped 7 already-applied commits — γ + A4 bench gate is structurally vacuous — rebuilder uses verbatim token cost, ignoring compression flag #798 follow-ups).test(zeta): drop demotion_pressure kwarg from _mk_belief (#817)—Belief.__init__no longer acceptsdemotion_pressureafter refactor(feedback): remove unreachable CONTRADICTS-edge auto-demote path (per #605) #814 / refactor(feedback): remove unreachable contradict-edge auto-demote (#814) #820. Same fix shape PR feat(retrieval): γ posterior-temperature rerank + bench panel widening (#796) #807 needed.Closes #800.