Repository navigation
fix(engine): rank tied kNN neighbours by seq_no then _id on every executor (#3017) - #3030
Merged
Merged
Conversation
…cutor (#3017) Motivation. #3017: across three rc.101 server processes on the same index, only 106 of 160 hybrid (RRF) rankings and 157 of 160 kNN rankings were identical (review corpus: 5,000 records, bge-small 384-dim vectors, duplicate records kept). The hybrid recipe promises the same page after a restart. Root cause. Not a hash seed in fusion: `fuse_finish` already orders a tied fused score by `score DESC, seq_no ASC, _id ASC` (#940). The tie order enters one level down, in the kNN leg. `rank_knn_pool` is a stable sort on score alone, so equal scores keep the order the executor collected them in. On the HNSW path that is the graph's traversal order, and the graph's layers come from `thread_rng` (xerj-vector hnsw.rs `random_level`): the graph the indexing process built, the graph a restarted process serves, and the graph a second node builds from the same documents visit tied neighbours in different orders. RRF scores each leg by POSITION, so a reordered tie in the kNN leg changes fused scores, not just the order of equal ones. Repro (synthetic corpus: 5,000 docs, 2,500 distinct 384-dim vectors, so every vector is shared by two docs; 160 queries; kNN k=100, num_candidates=5000, size=100; hybrid = match + knn, RRF k=60): main, indexing process vs restart: 234 of 320 rankings identical (kNN 116/160, hybrid 118/160) main, two restarts of the same dir: 320 of 320 (the loaded graph is the same one) main, indexing process vs second node: 0 of 320 this branch, all three pairs: 320 of 320 Change (engine/crates/xerj-engine/src/index.rs). New `order_knn_pool_page_order` sorts a hydrated kNN pool by the one score-ranked page order `score DESC, seq_no ASC, _id ASC` (same key as `sort_hits_page_order` and `fuse_finish`; seq_no resolved once per candidate; NaN sorts last so the comparator is total). `knn_result_from_scored` (HNSW, sq8-codes and multi-field kNN) uses it before the k cap; the exact scan applies it to its page after the cap, since its pool is the whole corpus. Test. engine/crates/xerj-server/tests/hybrid_tie_order_across_processes.rs spawns the real binary three times: A indexes 1,600 docs (800 distinct 16-dim vectors, each on two docs) and answers 12 kNN + 12 hybrid queries, B restarts on A's data dir, C indexes the same docs into a fresh dir. All 24 rankings must match across A/B/C, and tied docs must be in arrival order. Without the index.rs change: FAILED, "indexing process vs restart: 8 of 24 rankings differ". With it: ok. Docs. docs/recipes/hybrid-search.md and its landing page say the kNN leg now uses the same tie order. ES-YAML conformance (release build of this branch, private port 19960, throwaway data dir): 1448 passed, 0 failed, 10 skipped of 1458. Residual. HNSW is approximate: when the beam does not reach every tied candidate (num_candidates well below the corpus), which tied neighbours make the pool can still depend on the graph. The ordering of what the pool holds is now fixed.
…_id (#3017) Build + Test on PR #3030 failed two oracle tests, index::exact_scan_hydration_tests::{exact_scan,scalar8_scan}_is_bit_identical_to_the_clone_everything_scan: the oracle (`legacy_scan`) left tied scores in collection order (memtable, then segments), and the exact scan now orders its capped page by `score DESC, seq_no ASC, _id ASC`. The failing pairs were exactly that: d10, d13, d11, d14 (oracle) vs d10, d11, d13, d14 (scan), all with the same score bits. The oracle keeps its own cap in collection order (which tied candidates survive the cap is unchanged) and then sorts the capped page with its own copy of the page-order comparator, so it still shares no ranking code with the scan it checks. Local: cargo test --release -p xerj-engine --no-fail-fast: all 99 test binaries ok.
todie
pushed a commit
to unsigned-gg/xerj
that referenced
this pull request
Nov 7, 2026
…52.52 Motivation. The "Use-case harnesses" job failed on PR xerj-org#3030 (an engine change that does not touch functions/) with FAIL no lat/long from request.cf in .github/scripts/functions-get-test.mjs. Root cause. The test fakes `request.cf.latitude = '52.52'` and asserts the stored install record does not contain the substring '52.52'. The record carries `ts: now.toISOString()` (functions/get.js:142), so the assertion fails whenever the test runs at hh:mm:52.52x: the job log shows the failure at 02:21:52.52. A time-dependent flake, not a privacy leak. Change. Use distinctive coordinates (52.5200871 / 13.4049540) that no ISO timestamp can contain, and also assert the stored row has no `latitude` or `longitude` key. Test. node .github/scripts/functions-get-test.mjs: FUNCTIONS TEST PASSED.
YYW0228
pushed a commit
to YYW0228/xerj
that referenced
this pull request
Nov 7, 2026
The public half of the v1.0.0-rc.102 cut. The release tag goes on this PR's merge commit, so the notes and the tree they describe are one commit. - CHANGELOG.md: [Unreleased] cut over to [1.0.0-rc.102] - 2026-11-06. Every PR merged since v1.0.0-rc.101 is cited (xerj-org#2969 xerj-org#2982 xerj-org#2983 xerj-org#2984 xerj-org#2985 xerj-org#2988 xerj-org#3023 xerj-org#3028 xerj-org#3029 xerj-org#3030) or exempted with its reason (site, blog and donation pages: xerj-org#2971 xerj-org#2972 xerj-org#2976 xerj-org#2978 xerj-org#2980 xerj-org#2990 xerj-org#3032; CI test-only: xerj-org#3031). The release-notes gate passes locally against origin/main 34a2f24. - The XERJ Query-1 numbers in the summary trace to the R8 evaluation (private harness, runs/r8_2026-11-06/R8_RESULT.md): Score v2 on the four development families, 1,600 items, seed 47 90.29 -> 94.69 (+4.40, 95% interval +3.32 to +5.64), seeds 11/29 +3.95/+4.17; stated as in-sample because R8 was chosen on those items; wrong answers 9 -> 10 of 1,600 (s47), 12 -> 15 (s11); held-out fresh_v1 Net 0.3333 -> 0.3481. The 1,600/1,600 engine-vs-Python parity was re-run on the merged rc.102 build tree. - Upgrade notes say plainly that the rc.101 promise to land the storage and ingest lanes on public main before rc.102 was not kept, and that the rc.102 bundle needs an rc.102 binary. - Fixed lists the rc.101 aarch64 Linux assets built with a 4 KiB jemalloc page (checked in the rc.101 build tree: "checking LG_PAGE... 12" for both aarch64 targets), which xerj-org#1663 had fixed in release.yml; rc.102's native aarch64 builds set JEMALLOC_SYS_WITH_LG_PAGE=16. - ROADMAP.md: review line names v1.0.0-rc.102 (the docs_capability_lists check); the open-defects shortlist re-verified live: xerj-org#1122 and xerj-org#1170 open. - engine/Cargo.toml workspace version 1.0.0-rc.102, Cargo.lock restamped (19 workspace packages, no dependency moved). - Landing footer stamps V1.0.0-RC.101 -> V1.0.0-RC.102 (59 pages) and the nav's fallback latest-tag label; landing-constants-guard passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3017.
Root cause. Hybrid fusion already breaks fused-score ties by
score, seq_no, _id(#940). The tie order came from the kNN leg:rank_knn_poolis a stable sort on score only, so equal scores kept the executor's collection order. On the HNSW path that is graph traversal order, and HNSW layers come fromthread_rng. The indexing process, a restarted process and a second node therefore return tied neighbours in different orders. RRF scores by position, so the fused scores changed too.Change.
order_knn_pool_page_order(xerj-engine/src/index.rs) ranks every kNN pool byscore DESC, seq_no ASC, _id ASC, the same key assort_hits_page_orderandfuse_finish. It runs before the k cap inknn_result_from_scored(HNSW, sq8 codes, multi-field) and on the page after the cap in the exact scan.Repro. Synthetic corpus: 5,000 docs, 2,500 distinct 384-dim vectors (two docs per vector), 160 queries, kNN k=100 / num_candidates=5000 / size=100, hybrid = match + knn RRF.
Test. New
xerj-server/tests/hybrid_tie_order_across_processes.rsspawns the real binary three times: A indexes and queries, B restarts on A's dir, C indexes into a fresh dir. 12 kNN + 12 hybrid rankings must match across all three, and ties must be in arrival order. Without the engine change it fails withindexing process vs restart: 8 of 24 rankings differ. With it, the test passes.ES-YAML. Release build of this branch, private port, throwaway data dir: 1448 passed, 0 failed, 10 skipped.
Residual. HNSW is approximate. If the beam does not reach every tied candidate (num_candidates far below corpus size), which tied neighbours enter the pool can still depend on the graph. Their order no longer does.
🤖 Generated with Claude Code