Skip to content

KS78: Recency tie-breaker for score equality (#13)#24

Closed
Liorrr wants to merge 2 commits intomasterfrom
fix/ks78-recency-test
Closed

KS78: Recency tie-breaker for score equality (#13)#24
Liorrr wants to merge 2 commits intomasterfrom
fix/ks78-recency-test

Conversation

@Liorrr
Copy link
Copy Markdown
Contributor

@Liorrr Liorrr commented Apr 10, 2026

Summary

  • Adds microsecond-precision recency epsilon to break score ties in favor of newer memories
  • recency_epsilon = created_at.timestamp_micros() * 1e-18 — negligible impact on normal scoring
  • Applied after all boosts/caps but before final sort
  • Fixed test to properly distinguish Google-only vs Meta memory matches

Changes

  • crates/shrimpk-memory/src/echo.rs: +14/-2 lines (recency epsilon + test fix only)

Test plan

  • cargo test -p shrimpk-memory — all non-ignored tests pass
  • cargo clippy -p shrimpk-memory -- -D warnings — clean
  • cargo check --workspace — clean

Closes #13

🤖 Generated with Claude Code

- Remove merged supersession-demotion changes (hebbian_boosts type change,
  demotion→superseded_count rename, multiplicative demotion) that belong
  on a separate branch
- Keep only the recency tie-breaker epsilon (step 7c7) and google_result
  test fix from PR #13

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 10, 2026

Greptile Summary

This PR adds a microsecond-precision recency epsilon (step 7c7) to the EchoEngine scoring pipeline to break score ties in favor of newer memories (KS78 / issue #13). It also fixes a test bug where the "Google-only" memory was being incorrectly matched because the Meta memory's content also contains the word "Google".

Key changes:

  • A negligible epsilon timestamp_micros * 1e-18 is added to each result's final_score after all boosts and the inflation cap, so that among equal-scoring memories the newer one surfaces first.
  • The test recency_boost_newer_memory_ranks_higher is fixed: the predicate for the "Google-only" result now correctly excludes entries that also contain "Meta".
  • The epsilon magnitude for current timestamps is ~0.00174 (absolute), but the difference between any two entries created within the same year is at most ~3 × 10⁻⁵ — genuinely negligible relative to any meaningful similarity gap.

Confidence Score: 5/5

Safe to merge — no panics, no memory-safety issues, epsilon math is correct, and the test fix is accurate.

The epsilon formula is mathematically sound: the i64→f64 cast is lossless at current timestamp magnitudes (~1.744e15 μs, ULP ≈ 0.25 μs), and the maximum epsilon difference between any two memories created within the same year is ~3×10⁻⁵ — genuinely negligible relative to meaningful similarity gaps. The only concern is a minor documentation gap at the cap site (P2), not a behavioral bug.

No files require special attention; the single P2 is a comment-only suggestion at crates/shrimpk-memory/src/echo.rs line 1620.

Important Files Changed

Filename Overview
crates/shrimpk-memory/src/echo.rs Adds 9-line recency epsilon loop (step 7c7) after the inflation cap, plus a one-line test predicate fix; math is sound, no panics, minor cap-bypass worth noting.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["7c2: Temporal query boost"] --> B["7c3: Topic-label boost"]
    B --> C["7c4: Preference-update multiplier"]
    C --> D["7c5: Career/intro adjustment"]
    D --> E["7c6: Inflation cap\n(final_score ≤ similarity + 0.50)"]
    E --> F["7c7 NEW: Recency epsilon\n(+= timestamp_micros × 1e-18)"]
    F --> G["7d: Re-sort by final_score DESC"]
    G --> H["7d2: Subject-diversity cap"]
    H --> I["7e: Optional reranker"]
Loading

Reviews (1): Last reviewed commit: "fix: revert accidental hebbian_boosts ch..." | Re-trigger Greptile

- Add comment at step 7c6 (inflation cap) noting that step 7c7's
  recency epsilon intentionally follows after and may exceed the
  cap by up to ~3e-5, which only breaks ties.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Liorrr has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@Liorrr
Copy link
Copy Markdown
Contributor Author

Liorrr commented Apr 10, 2026

Closing: branch contaminated with config changes from other worktrees. Recreating as clean PR.

@Liorrr Liorrr closed this Apr 10, 2026
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.

recency_boost_newer_memory_ranks_higher test panic — tie-break at equal scores

1 participant