nx_learn_rank.nx
buildroot/runtime/nx_learn_rank.nx
about
nx_learn_rank.nx -- the learnings-rail ranker, COMPOSED not rebuilt.
module: nishi-core.learn.rank
depends: fx.nx, syscalls.nx, nx_bm25.nx, nx_rrf.nx, nx_rank_fused.nx
capability: CORE_COMPUTE
WHY THIS EXISTS AND WHY IT IS SMALL: nishi-ops/learn/nx_rank.ps1 implements BM25 + RRF + a severity
blend in PowerShell -- judgement in shell, which the standing order forbids. The obvious remedy is
"write a ranking organ", and that is WRONG: measured 2026-08-16 (corpus_complete=1) the estate
already ships nx_bm25 (+_lib,+_gate), nx_rrf, nx_rank_fused (+test), nx_intlog (+gate) and
nx_bm25_naive as a brute-force oracle. A third BM25 would be the duplicate-ruler defect -- the very
one nx_rank.ps1's OWN header cites (nx_ppmi_lib's two silently-diverged copies of one routine) as
its reason for existing. So this file contains NO ranking mathematics. It is a DRIVER: read a
corpus, call the incumbents, apply the declared blend, print an order.
CONTRACT (pre-declared BEFORE the first run, so the result cannot rationalise the design):
the top-N ORDER emitted here must equal nx_rank.ps1's top-N order on the same fixture.
SCORES may differ -- Q16.16 fixed point here vs IEEE doubles there -- but ORDER is the contract.
INPUT corpus file, one doc per line: <rank>\t<slug>\t<text>
rank is the severity 1..star_max; a malformed line is SKIPPED AND COUNTED, never guessed.
OUTPUT one line per hit: <rank>\t<slug>\t<q16.16 score> then a DECLARED envelope line.
nx_learn_rank <corpus> <topN> <conf> <query words...>
exit: 0 ranked (possibly zero hits) | 2 usage | 4 corpus unreadable
license_tier: ORIGINAL No hw writes (Rule 26).
dependencies 1 imports · 0 importers
imports: nx_rank_fused.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 44 | const LR_DEF_BLEND_REL_NUM: i64 = 100 // blend_relevance 1.00, held as hundredths so the conf's |
| 45 | const LR_DEF_BLEND_SEV_NUM: i64 = 35 // blend_severity 0.35, decimal text parses without floats |
| 46 | const LR_DEF_STAR_MAX: i64 = 6 |
| 52 | const LR_DEF_STEM_PREFIX: i64 = 6 |
| 53 | const LR_HUNDRED: i64 = 100 |
| 54 | const LR_TAB: i64 = 9 |
| 55 | const LR_NL: i64 = 10 |
| 56 | const LR_MAXDOCS: i64 = 20000 |
| 57 | const LR_MAXTERMS: i64 = 64 |
functions
| 59 | func lr_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 60 | func lr_e(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(2, s, n); return 0 } called by 1: main |
| 61 | func lr_n(fd: i64, v: i64) -> i64 called by 1: main |
| 74 | func lr_byte(fd: i64, c: i64) -> i64 { let b: *u8 = sys_mmap(1); b[0] = c as u8; sys_write(fd, b, 1); return 0 } called by 1: main |
| 75 | func lr_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 80 | func lr_hundredths(s: *u8, n: i64) -> i64 called by 1: main |
| 103 | func lr_conf_get(buf: *u8, n: i64, key: *u8, out: *u8, outcap: i64) -> i64 |
| 153 | func lr_is_tok(c: i64) -> i64 called by 1: lr_stem_into |
| 165 | func lr_stem_into(dst: *u8, src: *u8, n: i64, plen: i64) -> i64 |
| 197 | func main(argc: i64, argv: *i64) -> i64 |