Skip to content

feat(retrieval): wire the cross-encoder reranker into kb.context#441

Open
nickmopen wants to merge 1 commit into
vouchdev:testfrom
nickmopen:fix/issue-429-reranker-wire-context
Open

feat(retrieval): wire the cross-encoder reranker into kb.context#441
nickmopen wants to merge 1 commit into
vouchdev:testfrom
nickmopen:fix/issue-429-reranker-wire-context

Conversation

@nickmopen

Copy link
Copy Markdown

What changed

Wires the existing cross-encoder reranker (embeddings/rerank.py, already used by vouch search --rerank) into the kb.context / kb.search hybrid retrieval path in context._retrieve, behind a new retrieval.rerank config block.

Why

vouch already fuses lexical + semantic hits by reciprocal-rank fusion (embeddings/fusion.py:rrf_fuse, wired into context._retrieve) and already ships a finished cross-encoder reranker, but the reranker was only reachable from one place — vouch search --rerank in cli.py. The context-pack path that actually feeds agents (build_context_pack_retrievekb.context) never reranked, and there was no config to turn it on. Fixes #429.

What might break

  • On-disk layout: none.
  • Behaviour change (intentional): none by default — retrieval.rerank.enabled defaults to false, so kb.context / kb.search ordering is byte-identical to today until a kb opts in. When enabled, only the ordering of hybrid-backend hits changes (never membership — archived/superseded claims stay excluded as before); if the optional reranker extra (sentence-transformers) isn't installed, it silently degrades to the unreranked fused order rather than raising.

VEP

Not a surface change — no new kb.* method, no object-model or on-disk-layout change, no audit-log-shape change. kb.context / kb.search gain an internal, opt-in reordering stage.

Tests

  • make check (lint + mypy + pytest) — clean on the touched files. Full local suite: 1012/1020 passed (excluding tests/embeddings); the 8 pre-existing failures and 2 excluded modules (test_http_server.py, test_http_server_mcp.py, which bind real sockets) are Windows-local environment artifacts unrelated to this change — identical failure set before and after this diff.
  • New tests in tests/test_retrieval_backend.py, following that file's existing monkeypatch pattern so they run under the base CI install without the sentence-transformers extra: test_rerank_disabled_by_default_ordering_unchanged (asserts the reranker is never even constructed when off), test_rerank_enabled_reorders_by_cross_encoder_score (on/off parity plus reordering via a stub reranker), test_rerank_missing_extra_degrades_to_fused_order (ImportError degrades cleanly).
  • CHANGELOG.md updated under ## [Unreleased].

Fixes #429

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 57 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1b5fc2b9-816e-4d89-afd7-06646caaeddf

📥 Commits

Reviewing files that changed from the base of the PR and between 661b59c and 7ab4f5a.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/vouch/context.py
  • tests/test_retrieval_backend.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions github-actions Bot added docs documentation, specs, examples, and repo guidance retrieval context, search, synthesis, and evaluation tests tests and fixtures size: S 50-199 changed non-doc lines labels Jul 8, 2026
vouch already fuses lexical + semantic hits by reciprocal-rank fusion
and already ships a cross-encoder reranker, but the reranker was only
reachable from `vouch search --rerank`. the context-pack path that
actually feeds agents (build_context_pack -> _retrieve -> kb.context)
never reranked, and there was no config to turn it on.

add retrieval.rerank.enabled (default false) and retrieval.rerank.top_k
(default: the query's context limit) in config.yaml. when enabled,
fused hybrid hits are reordered by embeddings.rerank.rerank before
scoping filters run, mirroring the existing --rerank cli path.
degrades to the fused order if the reranker extra isn't installed.
off by default, so existing rankings are unaffected.

Fixes vouchdev#429
@nickmopen
nickmopen force-pushed the fix/issue-429-reranker-wire-context branch from a20cca0 to 7ab4f5a Compare July 8, 2026 13:59
@plind-junior
plind-junior enabled auto-merge July 16, 2026 03:40
@plind-junior

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs documentation, specs, examples, and repo guidance retrieval context, search, synthesis, and evaluation size: S 50-199 changed non-doc lines tests tests and fixtures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants