8000 fix(xccode): hybrid keeps lexical-only indices in the BM25 leg (#1146) by Vinz2168 · Pull Request #1177 · xerj-org/xerj · GitHub
[go: up one dir, main page]

Skip to content

fix(xccode): hybrid keeps lexical-only indices in the BM25 leg (#1146) - #1177

Merged
xerj-org merged 1 commit into
xerj-org:mainfrom
Vinz2168:fix/1146-hybrid-bm25-leg
Oct 6, 2026
Merged

xerj-org merged 1 commit into
xerj-org:mainfrom
Vinz2168:fix/1146-hybrid-bm25-leg

Conversation

@Vinz2168
@Vinz2168 Vinz2168 commented Oct 6, 2026
Copy link
Copy Markdown
Collaborator

Fixes #1146.

What this changes, and why

On a corpus where only some indices map body as semantic_text, xerj code --mode hybrid sent the single fused hybrid request only to the capable set. It has to, because a semantic leg on a plain-text field is a deliberate 400 (#530) that fails the whole wildcard. Nothing sent the BM25 leg to the other indices, so every lexical-only index dropped out of both legs, while the note still said "BM25 over N index(es)". Result: 1 hit under hybrid where --mode bm25 returned 20.

The lexical-only indices now get the same native hybrid with only its BM25 leg (hybrid_bm25_leg_body). The engine fuses per index (fuse_rrf, 1/(k+rank)) and merges a multi-index search by _score (cross-index re-sort in es_compat.rs). That means both responses carry RRF scores on the same scale, and merge_by_score just repeats that cross-index step on the client: score descending, stable, _index on ties, hits.total summed. The client does no fusion arithmetic of its own, which keeps the module's "no client-side fusion" contract. The note now names the indices: lexical-only (BM25 leg only, merged by score): <indices>.

The body builders now share bm25_leg / with_lang / hybrid_request, so --lang still rides in filter on every leg (#1148). When every index is capable, or none is, nothing changes.

Evidence

The new test hybrid_keeps_lexical_only_indices_in_the_bm25_leg failed before the fix and passes after:

before: assertion `left == right` failed  left: 2  right: 3   (requests sent)
after:  cargo test -p xerj-common  ->  189 passed; 0 failed  /  3 passed; 0 failed

Live, with the issue's repro on a clean --data-dir, using the rc.83 release build of this branch:

"xc-tinya-…-docs":     body="semantic_text"
"xc-tinya-…-src-docs": body="text"
before (the old request, replayed with curl against -docs only): 1 hit
bm25   -k 20: 20
hybrid -k 20: 20      # 19 from -src-docs + 1 from -docs, hits.total 31
@mode hybrid RRF(k=60) — BM25 over 2 index(es), vector over 1 of 2; lexical-only (BM25 leg only, merged by score): xc-tinya-…-src-docs
single-leg hybrid on -src-docs: scores 0.01639 0.01613 0.01587 (= 1/61, 1/62, 1/63)

Checks

  • cargo fmt --all (--check clean); cargo clippy -p xerj-common --lib --tests -- -D warnings clean
  • Scoped release build: cargo build --release -j 32 -p xerj-ser 8000 ver
  • cargo test -p xerj-common passes
  • ES-YAML conformance: N/A. No engine code changed; this is the xerj code client path in xerj-common only.
  • YAML case: N/A (no new ES-compatible behaviour)
  • Docs: CHANGELOG [Unreleased] entry. No other doc quotes the old note.
  • CONTRIBUTION_REVIEW audit: one file of logic. Failure atomicity: if the extra lexical request fails, the query exits 2 with search failed, the same as every other BM25 transport failure in this function.
  • Operational audit: N/A (no operational document or recipe changed)

Not run: the ES-YAML gate (see above). cargo test -p xerj-mcp has one pre-existing failure on macOS, loopback_url_with_no_auth_picks_up_the_local_admin_key, a /var vs /private/var path comparison that does not touch xccode.

Provenance

  • Written by: AI agent (Claude Code, Claude Opus 5.5), run by @Vinz2168 who has reviewed it
  • Verified: the test failing before and passing after; the crate test suite; fmt and clippy; the live repro numbers above, from commands run on this machine.
  • Assumed: that a tie across indices at an identical RRF score is ordered by _index ascending, the same as the engine's own cross-index order. The engine's sort is stable over its index-resolution order, which I did not trace. A same-request comparison where both orders differ would falsify this. It only affects tie order, never which hits make the page. Also not measured: any latency cost of the second request on large corpora.

🤖 Generated with Claude Code

…org#1146)

Motivation. On a corpus where only some indices map `body` as
semantic_text, `xerj code --mode hybrid` returned 1 hit where
`--mode bm25` returned 20, while its note claimed "BM25 over 2
index(es)". Every lexical-only index was dropped from BOTH legs. Not a
synthetic case: a `corpus index` of psf/requests yields one such index.

Root cause. `run_code_query` sends the fused native `hybrid` request to
the comma-joined capable set when capable < total
(xccode/mod.rs, the `target` choice), because a `semantic` leg on a
plain-text field is a deliberate 400 (xerj-org#530, engine index.rs
`run_semantic`) that fails the whole wildcard request. Nothing sent the
BM25 leg to the remaining indices.

Fix. The lexical-only indices get the same native `hybrid` with its BM25
leg alone (`hybrid_bm25_leg_body`). The engine fuses per index
(`fuse_rrf`, 1/(k+rank)) and merges a multi-index search by `_score`
(es_compat.rs cross-index re-sort), so both responses carry RRF scores
on one scale; `merge_by_score` repeats that cross-index step client-side
(score desc, stable, `_index` on ties, `hits.total` summed). No new
fusion arithmetic lives in the client. The note now names the indices:
"lexical-only (BM25 leg only, merged by score): <indices>". The body
builders share `bm25_leg` / `with_lang` / `hybrid_request`, so `--lang`
still rides in `filter` on every leg (xerj-org#1148).

Evidence (verified):
- New test `hybrid_keeps_lexical_only_indices_in_the_bm25_leg` failed
  before the fix (2 requests, expected 3) and passes after;
  `cargo test -p xerj-common`: 189 + 3 passed, 0 failed.
- Issue repro on a clean --data-dir, rc.83 release build of this branch
  (30 short .py files -> `-src-docs` body=text, corpus.json -> `-docs`
  body=semantic_text):
    before (the old request, replayed with curl): 1 hit
    bm25   -k 20: 20 hits
    hybrid -k 20: 20 hits (19 src-docs + 1 docs), total 31
  Single-leg hybrid on the lexical index scores 0.01639, 0.01613,
  0.01587 = 1/61, 1/62, 1/63 — the same scale as the fused request.
  `--lang python` on the hybrid path still answers.

Not verified / out of scope: ES-YAML gate not run (no engine code
changed — xerj-common client path only). `cargo test -p xerj-mcp` has
one failure, `loopback_url_with_no_auth_picks_up_the_local_admin_key`,
a macOS /var vs /private/var path comparison unrelated to xccode.

Written by an AI agent (Claude Code) for the account that opens the PR.
@cla-bot cla-bot Bot added the cla-signed label Oct 6, 2026
@xerj-org
xerj-org merged commit da148e8 into xerj-org:main Oct 6, 2026
22 checks passed
Ravandevil25 pushed a commit to Ravandevil25/xerj that referenced this pull request Oct 6, 2026
@xerj-org xerj-org mentioned this pull request Oct 6, 2026
neoneye pushed a commit to agent-memory-atlas-archive/xerj-org--xerj that referenced this pull request Oct 10, 2026
Fifth daily release cut. The window was dominated by the xerj-org#1109
security audit fixes and the config/telemetry honesty items, plus
the first code contribution from a third external contributor.

Window (v1.0.0-rc.85..main, PRs all cited in the CHANGELOG):
- Security: xerj-org#1109 closed by PR xerj-org#1194 (audit remediation,
  Security section added to the notes)
- Fixed: xerj-org#1158 (build-time half, PR xerj-org#1185, stays open on the
  issue), xerj-org#1189 + xerj-org#1190 (PR xerj-org#1193), xerj-org#1186 (PR xerj-org#1188),
  xerj-org#1146 (PR xerj-org#1177) and xerj-org#1092 (PR xerj-org#1184) - both Vincenzo
  Lombardo, xerj-org#1146 his first merged fix; _doc arrival order
  (xerj-org#1127, Saurav Kumar, his first code contribution)
- Field reports: xerj-org#1178 (Vinz2168), xerj-org#1187 (thomas-villani)
- Metrics chore 15b62f5 cited as a Community line (direct
  commit, [skip ci], rc.85 precedent)

Roll mechanics:
- engine/Cargo.toml workspace version 1.0.0-rc.86; Cargo.lock
  regenerated (version-only diff verified: 0 non-version lines)
- CHANGELOG: fresh [Unreleased], rc.86 section, new Community
  section
- ROADMAP: Last-reviewed pass for the cut (docs_capability_lists
  gate requires it), rc.86 paragraph in Next release, Open
  defects shortlist rolled to the eleven live trackers
- landing footers: V1.0.0-RC.85 -> V1.0.0-RC.86 (91), lowercase
  variant (1); zero rc.85 patterns remain
- release-notes-gate.sh run locally before this commit: PASS on
  freshness, issue-state (11 open-defect checks, 6 Fixed checks
  incl. the xerj-org#1158 stays-open marker) and coverage (9 window PRs)

In flight past the cut: phase-B bulk coalescing for xerj-org#1147
(PR xerj-org#1195, sticky-failure fix + 8-in-flight wire concurrency,
rustsec 10.1s->9.7s / pysec 17.4s->16.9s vs rc.85 on the
loopback A/B), merges into the rc.87 window.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: xerj code --mode hybrid drops lexical-only indices from the BM25 leg too, while the note says "BM25 over N index(es)"

2 participants

0