code wiki / (root) / nx_beir_arms_lib.nx

nx_beir_arms_lib.nx source

↩ module page · 64 lines · 4070 B

1// nx_beir_arms_lib.nx -- THE ONE CHOOSER of the arm the BRIGHT sweep writes into search.leaderboard (search R0f, 2026-09-16). 2// 3// WHY A LIB: be_bright used to choose between plain BM25 and the BM25Q RRF fusion only, so the cross-encoder arm's 4// twelve-split average was read by nobody and could never reach the row -- a whole day of rerank compute would have 5// left the placement at the lexical floor with nothing in the receipt saying so. The choice is a pure function of the 6// sweep's own averages so an in-process gate can hold every branch (nx_beir_arms_gate), and the harness composes it. 7// 8// THE RULES, each pre-declared on search.plan before the run that could benefit from it: 9// plain the floor; always eligible 10// fused the BM25Q RRF arm: eligible only when its own rule held in the SAME sweep (fusion beat plain on the long 11// subset AND every no-repeat query ranked identically), and its average is at least the plain average 12// prf RM3-style pseudo-relevance feedback (R0g): eligible only when EVERY split measured it and it EXCEEDS plain 13// and the best so far -- the non-reasoning expansion control the R0c rewriter must beat 14// crossenc the sovereign BERT cross-encoder rerank over a LICENSED data asset: eligible only when EVERY split measured 15// it (a partial average is not a placement) and it EXCEEDS plain BM25 (the R0 accept rule) and the best so far 16// cefusion RRF over the BM25 order and the cross-encoder order: same eligibility as crossenc; it displaces the pure 17// rerank only when STRICTLY higher, so a tie keeps the simpler arm 18// license_tier: ORIGINAL No hw writes (Rule 26). 19 20const BA_ARM_PLAIN: i64 = 0 21const BA_ARM_FUSED: i64 = 1 22const BA_ARM_CE: i64 = 2 23const BA_ARM_CEF: i64 = 3 24const BA_ARM_PRF: i64 = 4 25 26func be_lb_choose(avg: i64, fq_avg: i64, fusion_ok: i64, prf_n: i64, prf_avg: i64, ce_n: i64, ce_avg: i64, cef_avg: i64, nsplits: i64) -> i64 { 27 var arm: i64 = BA_ARM_PLAIN 28 var best: i64 = avg 29 if fusion_ok == 1 { if fq_avg >= avg { arm = BA_ARM_FUSED; best = fq_avg } } 30 if prf_n == nsplits { if nsplits > 0 { 31 if prf_avg > avg { if prf_avg > best { arm = BA_ARM_PRF; best = prf_avg } } 32 } } 33 if ce_n == nsplits { if nsplits > 0 { 34 if ce_avg > avg { if ce_avg > best { arm = BA_ARM_CE; best = ce_avg } } 35 if cef_avg > avg { if cef_avg > best { arm = BA_ARM_CEF; best = cef_avg } } 36 } } 37 return arm 38} 39 40func be_lb_arm_score(arm: i64, avg: i64, fq_avg: i64, prf_avg: i64, ce_avg: i64, cef_avg: i64) -> i64 { 41 if arm == BA_ARM_FUSED { return fq_avg } 42 if arm == BA_ARM_PRF { return prf_avg } 43 if arm == BA_ARM_CE { return ce_avg } 44 if arm == BA_ARM_CEF { return cef_avg } 45 return avg 46} 47 48func be_lb_arm_label(arm: i64) -> *u8 { 49 if arm == BA_ARM_FUSED { return "bm25q-rrf-fusion" as *u8 } 50 if arm == BA_ARM_PRF { return "bm25-rm3-prf" as *u8 } 51 if arm == BA_ARM_CE { return "crossenc-rerank" as *u8 } 52 if arm == BA_ARM_CEF { return "crossenc-rrf-fusion" as *u8 } 53 return "plain-bm25" as *u8 54} 55 56// the row's organisation text names the arm and, for the reranker arms, the licensed third-party weights the sovereign 57// encoder runs -- the data asset is declared on the row, never hidden behind the estate's name 58func be_lb_arm_org(arm: i64) -> *u8 { 59 if arm == BA_ARM_FUSED { return "Nishi (sovereign integer BM25 + BM25Q RRF fusion, nx_beir_eval be_bright)" as *u8 } 60 if arm == BA_ARM_PRF { return "Nishi (sovereign integer BM25 + RM3-style pseudo-relevance feedback, nx_beir_eval be_bright)" as *u8 } 61 if arm == BA_ARM_CE { return "Nishi (sovereign integer BM25 + sovereign BERT cross-encoder rerank over the licensed MiniLM-L6 MS MARCO weights, nx_beir_eval be_bright)" as *u8 } 62 if arm == BA_ARM_CEF { return "Nishi (sovereign integer BM25 + RRF fusion with the sovereign BERT cross-encoder over the licensed MiniLM-L6 MS MARCO weights, nx_beir_eval be_bright)" as *u8 } 63 return "Nishi (sovereign integer BM25, nx_beir_eval be_bright)" as *u8 64}