Skip to content

feat(search): bounded top-1 tie-break hardening for operator retrieval (#304 slice A) - #316

Merged
hurttlocker merged 1 commit into
mainfrom
feat/304-top1-ranking-harden
Mar 11, 2026
Merged

hurttlocker merged 1 commit into
mainfrom
feat/304-top1-ranking-harden

Conversation

@hurttlocker

Copy link
Copy Markdown
Owner

What this does

Implements #304 slice A as a bounded ranking hardening pass for operator-style retrieval.

Focus: improve top-1 tie-break behavior for long operator prompts after #303 query shaping.

Problem / Context

After #303, long operator prompts are cleaner at retrieval input, but near-tie top candidates can still rank in the wrong order for operator intent.

Issue: #304

How it works

Bounded operator top-1 tie-break

Added a narrow, deterministic post-retrieval tie-break stage in search.Engine.Search:

  • only runs when query shaping was applied (#303 signal)
  • only considers near-top candidates (within 3% of top score, top 5 max)
  • computes tie-break signal from query-token overlap with:
    • SourceSection (highest weight)
    • SourceFile
    • Content (lowest weight)
  • applies small bounded boost (max +8%) to break near ties toward operator-relevant section/file matches

Explainability (operator trust)

When --explain is enabled, tie-break appends reason text:

  • operator top-1 tie-break <boost>x (signal=<...>)

This keeps top-1 movement auditable for Hawk/Q.

Files changed

  • internal/search/search.go
  • internal/search/operator_tiebreak_test.go (new)

Testing done

Exact commands run:

  1. go test ./internal/search -run 'OperatorTop1TieBreak|QueryShape|SearchExplain' -count=1
  2. go test ./...

Screenshots / before-after

Terminal/JSON behavior change (operator explain mode):

  • top results can now include tie-break rationale in explain.why
  • no CLI flag changes required

Breaking changes / risks

Breaking changes: None.

Concise risk note for Hawk:

  • Primary risk is over-boosting atypical long prompts (false-positive tie-break influence).
  • Mitigations: strict activation gate (must be shaped), narrow candidate window, small bounded boost, deterministic tests.

Explicit out-of-scope

Merge notes

@hurttlocker
hurttlocker merged commit 8c7a9b9 into main Mar 11, 2026
4 checks passed
@hurttlocker
hurttlocker deleted the feat/304-top1-ranking-harden branch March 21, 2026 01:27
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