Skip to content

fix: make importance/recency score boosts opt-in (boost-confound)#584

Merged
EtanHey merged 1 commit into
mainfrom
feat/boost-confound-optin
Jul 10, 2026
Merged

fix: make importance/recency score boosts opt-in (boost-confound)#584
EtanHey merged 1 commit into
mainfrom
feat/boost-confound-optin

Conversation

@EtanHey

@EtanHey EtanHey commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • add process-wide opt-ins for the existing importance multiplier and recency rerank/decay controls
  • keep explicit importance_rerank and recency_rerank kwargs working for existing callers
  • use effective opt-in values in the hybrid-search cache key
  • document the two-PR implementation plan

Context

PR #565 already made the explicit rerank kwargs default-off. This follow-up finishes the handoff contract by exposing strict call-time environment controls:

  • BRAINLAYER_SCORE_IMPORTANCE_BOOST
  • BRAINLAYER_SCORE_RECENCY_DECAY

Accepted enabled values are 1, true, yes, and on (case-insensitive). Unset or other values remain off.

Test plan

  • TDD red: both env-control tests failed before implementation
  • focused scoring/consumer suite: 91 passed
  • Ruff check + format: clean
  • pre-push Python 3.12 unit gate: 3450 passed, 9 skipped, 61 deselected, 1 xfailed
  • MCP registration: 3 passed
  • isolated eval/hook routing: 40 passed
  • Bun regression: 1 passed
  • FTS5 determinism shell regression: passed

Review note

The local CodeRabbit CLI was attempted before commit but returned the public OSS rate limit (15-minute reset), so PR-level bot review is requested below.


Note

Medium Risk
Changes relevance ranking when env flags are enabled and affects cache partitioning by rerank mode; defaults unchanged so production risk is low unless operators opt in.

Overview
Adds process-wide opt-ins for hybrid search post-RRF boosts that previously required explicit kwargs. At the start of hybrid_search, recency_rerank and importance_rerank are combined with BRAINLAYER_SCORE_RECENCY_DECAY and BRAINLAYER_SCORE_IMPORTANCE_BOOST via a new _env_flag_enabled helper (truthy values: 1, true, yes, on, case-insensitive). Explicit kwargs still work; unset env keeps default-off behavior from the prior kwargs-only contract.

Effective rerank flags continue to drive boost gates and the hybrid result cache key, so env-on vs env-off queries do not share cached rankings. Tests assert isolated importance and recency effects under each env flag and clear those variables in existing default/opt-in kwargs tests. A docs plan describes this PR as task 1 of a two-PR relevance stack (weighted RRF follows separately).

Reviewed by Cursor Bugbot for commit f53e512. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make importance and recency score boosts opt-in via environment variables in hybrid_search

  • Recency decay and importance boost in SearchMixin.hybrid_search previously applied based only on kwargs; they now also require the corresponding env vars (BRAINLAYER_SCORE_RECENCY_DECAY, BRAINLAYER_SCORE_IMPORTANCE_BOOST) to be set to a truthy value.
  • Adds a _env_flag_enabled helper in search_repo.py that parses boolean-like env vars ("1", "true", "yes", "on", case-insensitive).
  • Behavioral Change: boosts that previously fired when kwargs were set will no longer fire unless the env var is also enabled, making these features opt-in by default.
📊 Macroscope summarized f53e512. 2 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

@cursor

cursor Bot commented Jul 10, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_1dbcbe14-4e79-4b08-bce8-5cff205cda16)

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@EtanHey, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 30 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 05a03879-f5f8-43e0-ada4-3b306bf0a06f

📥 Commits

Reviewing files that changed from the base of the PR and between aa24d41 and f53e512.

📒 Files selected for processing (3)
  • docs/plans/2026-07-10-relevance-score-controls-weighted-rrf.md
  • src/brainlayer/search_repo.py
  • tests/test_hybrid_search.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/boost-confound-optin

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@EtanHey

EtanHey commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@cursor @BugBot review

@EtanHey

EtanHey commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your trial has ended. Reactivate Greptile to resume code reviews.

@cursor

cursor Bot commented Jul 10, 2026

Copy link
Copy Markdown

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium

recency_rerank: bool = False,
importance_rerank: bool = False,

When a caller explicitly passes recency_rerank=False or importance_rerank=False, the or override on lines 1771-1772 still enables the feature if the corresponding env var (BRAINLAYER_SCORE_RECENCY_DECAY or BRAINLAYER_SCORE_IMPORTANCE_BOOST) is set. This makes a per-call opt-out impossible and silently changes ranking and cache keys for those requests. Consider checking the env var only when the caller does not explicitly pass a value, e.g. default the parameter to None and apply _env_flag_enabled(...) only when it is None.

-        recency_rerank: bool = False,
-        importance_rerank: bool = False,
+        recency_rerank: Optional[bool] = None,
+        importance_rerank: Optional[bool] = None,
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @src/brainlayer/search_repo.py around lines 1757-1758:

When a caller explicitly passes `recency_rerank=False` or `importance_rerank=False`, the `or` override on lines 1771-1772 still enables the feature if the corresponding env var (`BRAINLAYER_SCORE_RECENCY_DECAY` or `BRAINLAYER_SCORE_IMPORTANCE_BOOST`) is set. This makes a per-call opt-out impossible and silently changes ranking and cache keys for those requests. Consider checking the env var only when the caller does not explicitly pass a value, e.g. default the parameter to `None` and apply `_env_flag_enabled(...)` only when it is `None`.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f53e512931

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Cache is module-level LRU (128 entries) with defensive copy-on-read.
"""

recency_rerank = recency_rerank or _env_flag_enabled("BRAINLAYER_SCORE_RECENCY_DECAY")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep decay env from enabling recency fallback

When BRAINLAYER_SCORE_RECENCY_DECAY=1 is set, this assigns recency_rerank=True, but that same flag also gates the recency-intent fallback query (if recency_rerank and recency_intent and not date_from) before scoring. In any process that enables the new score-decay control, queries containing terms like "latest" or "recent" can now inject up to 25 arbitrary recent chunks that have no lexical or vector match, instead of only applying the documented decay multiplier; this can surface unrelated memories and degrade retrieval correctness. Separate the env-controlled decay/boost gate from the candidate-supplement behavior, or only enable the fallback through the explicit rerank path.

Useful? React with 👍 / 👎.

@EtanHey EtanHey merged commit e5203f4 into main Jul 10, 2026
8 checks passed
@EtanHey

EtanHey commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

Follow-up: the score-only recency-decay isolation fix that missed the merged head is carried by recovery PR #588. Env-only decay no longer enables recent-candidate fallback.

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