Skip to content

feat(search): on-demand cosine rerank path behind flag (Phase 2) - #74

Merged
ManSio merged 4 commits into
feat/e26-chunk-formatfrom
feat/ondemand-rerank
Oct 10, 2026
Merged

ManSio merged 4 commits into
feat/e26-chunk-formatfrom
feat/ondemand-rerank

Conversation

@ManSio

@ManSio ManSio commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

What

Phase 2 of the approved stack migration (E25): score the top-N fused candidates with LIVE embeddings at request time instead of stored vectors + BGE reranker.

  • src/core/search/ondemand_rerank.py — pure numpy module: cosine_sims, rerank_by_cosine (stable sort, ties keep fused order), split_embed_inputs (prefers text_full, counts text-less).
  • src/config/settings.py — MSCODEBASE_ONDEMAND_RERANK (+ ..._TOP_N, default 10), same field(default_factory=...) pattern as late_enrichment so reload_config() re-reads env.
  • src/core/search/engine.py — hook in hybrid_search_async: flag ON -> _apply_ondemand_reranker_async INSTEAD of the BGE reranker (not before it — BGE stays the flag-off path). Any error returns the fused pool unchanged, same contract as the BGE fallback. Tail beyond top-N is appended in original order, total never exceeds limit.
  • experiments/search_quality/flagon_check.py — wiring proof artifact (same measuring code as the Phase 0 driver).

Default OFF

Production path is byte-identical without the flag: the branch is entered only when self._ondemand_rerank is true AND the fused pool is non-empty.

Tests

tests/test_ondemand_rerank.py 6/6 — exact math on fake vectors (cosine = 1 / 0 / sqrt(0.5), zero-query safety, stable ties, inputs not mutated, text_full preference), plus flag-default-off wiring assertions. Adjacent suites 36/36, ruff clean.

Live check (flag ON, real embedder)

  • quality: hit@1 3/10, hit@5 4/10 — equal to the Phase 0 baseline, no regression.
  • _last_rerank_timing = {'mode': 'ondemand_cosine', 'ms': 1041, 'skipped_no_text': 0}.
  • fast unchanged (hit@1 0/10, hit@5 6/10 as before).

Clean state

git clone --branch feat/ondemand-rerank + bash scripts/verify_clean_state.sh --no-clone at b8e544af:
Passed: 2049 / Failed: 0 — CLEAN STATE VERIFICATION: PASSED, revision gate VALID, 3/3 negative controls PROVEN.

CI caveat (honest)

The CI workflow triggers only on pull_request: branches: [main] (and push: main). This PR is stacked on #73, so no GitHub CI run is produced — the clean-state run above is the equivalent evidence. The only check reported on the PR is Code scanning AI findings, which failed on an external cause: You have exceeded your monthly quota (HTTP 402) from the Advanced Security action, not on repo code.
Re-targeting this PR to main after #73 merges will produce a normal CI run.

Notes

Phase 2 of the approved stack migration (E25). New pure ondemand_rerank.py (cosine, stable ties, skips text-less); MSCODEBASE_ONDEMAND_RERANK (+TOP_N) config mirroring late_enrichment; hybrid hook reranks top-N fused pool with live embeddings INSTEAD of BGE only when flagged. Default OFF: prod path byte-identical. Tests: test_ondemand_rerank.py 6/6 exact math on fake vectors; adjacent 36/36. Live proof with flag: quality h1 3/10 h5 4/10 = baseline, rerank_timing.mode=ondemand_cosine in 1041ms; fast untouched.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: faafb688-dd39-4d8c-91dd-cd28ea158a27

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Phase 3 as a measurement, not a deletion. Flag skips the whole dense stage (query embedding + LanceDB vector search); default OFF so the prod path is byte-identical.

EXP-28: frozen 33-case panel (sha256 f31e594e, union of three pre-existing frozen sets, frozen before the run), 2 runs per arm, same session and index.
A dense ON: hit1 11/33, hit5 15/33, 0 errors, mean 3359/3534ms.
B dense OFF: hit1 12/33, hit5 16/33, 0 errors, mean 3163/2492ms.
Per case 2 better / 1 worse / 30 same; speedup mean-of-means 18% but per-run spread 5.8-29.5%.
Verdict: H1/H2/H6 refuted as expected, H4 confirmed (0 errors), H3 PARTIAL, H5 untested (no symbol/NL labelling in the panel). Harness proven by a _vector_search_async call counter 1 -> 0 with the embedder alive.

Key finding: of 52 table-API call sites in 13 src files only 5 are vector search; bm25.py:93 builds BM25 from table.to_pandas(), so LanceDB is the chunk primary store, not a vector index. Dense removal NOT recommended; the flag stays as an operational kill-switch.

KNOWN_ISSUES untouched (foreign session edits it) - proposals in experiments/e28_denseoff/PENDING_LEDGER.md. Tests: 3 flag tests + adjacent suites 29/29, ruff clean.
MSCodeBase Agent and others added 2 commits October 10, 2026 18:11
…up claim

EXP-28 left H5 untested: no symbol-vs-NL labelling, and it could not be added after the run (freeze-before-look). This experiment freezes the labelling rule first (snake_case | CamelCase | pathy | single token -> symbolic 15 / NL 18, sha256 7639ba1b), then runs both arms twice.

A dense ON : NL 3/18 (16.7%), symbolic 8/15 (53.3%), 0 errors, mean 2559/2555ms
B dense OFF: NL 5/18 (27.8%), symbolic 7/15 (46.7%), 0 errors, mean 2375/2354ms
NL 2 better / 0 worse; symbolic 0 better / 1 worse (TR-P2). Speedup stable at 7.2% / 7.9%.

Verdicts: H1 CONFIRMED (symbolic loses exactly 1 of 15, within the declared tolerance), H2 REFUTED as expected (NL is better), H3 REFUTED as expected (7.5%, below 15%), H4 CONFIRMED (0 errors), H5 CONFIRMED against expectation (two NL cases improved).

CORRECTED: EXP-28 published an 18.0% speedup; two runs here show 7.2% and 7.9%. The old number was inflated by one noisy run (21% spread vs 0.2% here). Logged as a new entry with the supersede reference, not a silent edit.

Harness incident: the first run from the worktree printed hit1=0/33 with rc=0 and 167ms - a silent zero on an empty index (index is per-project-path). Guard added: all-empty exits 2, and the project root is an explicit manifest parameter. That run is not counted.

Phase 3 decision unchanged: no observed harm from dense, no proven gain (1-2 of 33 cases is noise), LanceDB stays as chunk primary store, the flag stays a kill-switch.
feat(search): MSCODEBASE_DENSE_OFF kill-switch + EXP-28 dense-off A/B
@ManSio
ManSio merged commit 11c71c0 into feat/e26-chunk-format Oct 10, 2026
1 of 2 checks passed
ManSio added a commit that referenced this pull request Oct 10, 2026
The workflow listened only to pull_request -> main, so a stacked PR (base = feature branch) produced no CI run at all. That is exactly what happened to phases 2 and 3 of the migration: PR #74 and #75 were merged with a local clean-state run as the only evidence, and their status stayed unverifiable on GitHub.

pull_request now also targets feat/**, exp/**, fix/**, chore/**. push stays main-only so one revision is never built twice. Job list unchanged (test, clean-state, manifest-parity, transport-equiv-e2e, docker-build); workflow yaml parses.

Co-authored-by: MSCodeBase Agent <mscodebase@intelligence.local>
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