code wiki / _hdl_build / nx_ltr_lib.nx
nx_ltr_lib.nx
buildroot/runtime/_hdl_build/nx_ltr_lib.nx
about
nx_ltr_lib.nx -- LEARNING-TO-RANK reranker as a library so a gate drives it in-process on a
synthetic fixture (search rung R0, 2026-09-14). COORDINATE ASCENT (Metzler-Croft) that directly
maximises training-fold nDCG@10 one weight at a time by step-halving line search, INITIALISED at
the BM25-only solution so it can never rank worse than BM25 on the folds it trains on; evaluated by
K-FOLD CROSS-VALIDATION so no query's own label ever trains the weights that score it (the
contamination-free path when only a test split exists). Integer/fixed-point end to end: features are
min-max normalised to LTR_SCALE per query, weights are i64, ranking is an integer dot product, so
the result is bit-reproducible. The harness (nx_beir_eval) stores per-candidate features + gold +
idcg during its BM25 pass and calls ltr_cv over the SAME candidate pool, so the learned arm is the
same controlled comparison as the semppmi and rrf arms. license_tier: ORIGINAL
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_beir_eval.nxnx_ltr_lib_gate.nx
structs
| none |
consts
| 14 | const LTR_NFEAT: i64 = 10 // bm25 ppmi_maxsim cover covidf sumtf doclen dense_maxsim_centered dense_maxsim minwin bigram |
| 15 | const LTR_SCALE: i64 = 1000 // per-query per-feature min-max target range (0..LTR_SCALE) |
| 16 | const LTR_FOLDS: i64 = 5 // 5-fold cross-validation |
| 17 | const LTR_TOPK: i64 = 10 // nDCG@10 |
| 18 | const LTR_CA_INIT: i64 = 1024 // initial bm25 (feature 0) weight -- ranking starts AS bm25 |
| 19 | const LTR_CA_STEP0: i64 = 1024 // line-search first step, halved to 0; comparable to the init so a feature can reach bm25 scale |
| 20 | const LTR_CA_PASSES: i64 = 12 // coordinate sweeps; ends early when a whole sweep improves nothing |
functions
| 23 | func ltr_disc(r: i64) -> i64 |
| 42 | func ltr_norm(feat: *i64, fn: *i64, nq: i64, ncand: *i64, maxcand: i64) -> i64 called by 1: ltr_cv |
| 71 | func ltr_dot(w: *i64, fn: *i64, base: i64) -> i64 called by 1: ltr_ndcg_sel |
| 81 | func ltr_ndcg_sel(w: *i64, fn: *i64, gold: *i64, fold: *i64, nq: i64, ncand: *i64, maxcand: i64, idcg: *i64, holdout: i64, sel: i64, cnt_out: *i64) -> i64 |
| 124 | func ltr_train_ca(fn: *i64, gold: *i64, fold: *i64, nq: i64, ncand: *i64, maxcand: i64, idcg: *i64, holdout: i64, w_out: *i64) -> i64 |
| 164 | func ltr_cv(feat: *i64, gold: *i64, fold: *i64, nq: i64, ncand: *i64, maxcand: i64, idcg: *i64, cnt_out: *i64) -> i64 |
| 192 | func ltr_ndcg_single(feat: *i64, gold: *i64, nq: i64, ncand: *i64, maxcand: i64, idcg: *i64, featk: i64, cnt_out: *i64) -> i64 |