nx_diora_leaderboard.nx source
↩ module page · 273 lines · 12455 B
1// nx_diora_leaderboard.nx -- the bits-up search leaderboard, run on the
2// verified Diora Baird qrels vs 4 live-captured incumbents.
3//
4// module: nishi-core.search.bench.diora_leaderboard
5// depends: fx.nx, nx_bench_harness.nx, nx_diora_data.nx
6// capability: APP_RUNNABLE + GATE
7//
8// WHY: prove the operator cardinal -- S-CLASS EXCEED, not sovereignty-as-win.
9// Every score is produced by the sovereign Q16.16 kernels (zero C on the
10// output path). The incumbent SERPs are live captures used ONLY as 1:1
11// measurement baselines; they are NOT a Nishi index. Nishi's row is its OWN
12// ranking policy (primary-source-first + facet diversity) over the candidate
13// universe. exit 0 == Nishi exceeds EVERY measured incumbent on the research-
14// delivery cardinals (nDCG / primary-precision / altitude, no S-recall
15// regression) -- so this file doubles as a permanent regression gate.
16//
17// HONEST SCOPE (1:1, no proxy): this proves the RANKING + SCORING layer is
18// sovereign and S-class. The document corpus is research-grounded, not yet
19// crawled by our own spider; the sovereign crawler + inverted index (own the
20// INDEX from bits up, not just the ranker) is the next milestone.
21// SREACH R2 (2026-06-10): the facet-oracle-from-gold leak is RETIRED -- the
22// re-rank's facets now come from nx_facet_classify (URL/host/title signals,
23// gated vs gold by nx_facet_gate at a permil bar); gold facets feed SCORING
24// only. The ranking also fuses the CONTENT-ACCESSIBILITY axis (operator
25// directive: engagement/media/info-density, not first-hand alone).
26
27import "fx.nx"
28import "nx_bench_harness.nx"
29import "nx_diora_data.nx"
30import "nx_facet_classify.nx"
31const K_MAGIC_10000: i64 = 10000
32const K_MAGIC_9999: i64 = 9999
33
34func nx_putc(c: i64) -> i64 {
35 let b: *u8 = sys_mmap(1)
36 b[0] = c
37 sys_write(1, b, 1)
38 return 0
39}
40func nx_puts(s: *u8) -> i64 { sys_write(1, s, nx_str_len(s)); return 0 }
41
42func nx_put_i64(n: i64) -> i64 {
43 if n == 0 { nx_putc(0x30); return 0 }
44 var v: i64 = n
45 if v < 0 { nx_putc(0x2D); v = 0 - v }
46 let buf: *u8 = sys_mmap(32)
47 var k: i64 = 0
48 while v > 0 {
49 buf[k] = 0x30 + (v - (v / 10) * 10)
50 v = v / 10
51 k = k + 1
52 }
53 while k > 0 {
54 k = k - 1
55 sys_write(1, (((buf as i64) + k) as *u8), 1)
56 }
57 return 0
58}
59
60// print a Q16.16 value as "I.FFFF" (4 fraction digits).
61func nx_put_q16(x: i64) -> i64 {
62 nx_put_i64(x >> 16)
63 nx_putc(0x2E)
64 let low: i64 = x - ((x >> 16) << 16) // low 16 bits (x >= 0)
65 let frac: i64 = (low * K_MAGIC_10000) >> 16 // 0..K_MAGIC_9999
66 let d3: i64 = frac / 1000
67 let r3: i64 = frac - d3 * 1000
68 let d2: i64 = r3 / 100
69 let r2: i64 = r3 - d2 * 100
70 let d1: i64 = r2 / 10
71 let d0: i64 = r2 - d1 * 10
72 nx_putc(0x30 + d3); nx_putc(0x30 + d2); nx_putc(0x30 + d1); nx_putc(0x30 + d0)
73 return 0
74}
75
76func nx_pad(s: *u8, w: i64) -> i64 {
77 nx_puts(s)
78 var n: i64 = nx_str_len(s)
79 while n < w { nx_putc(0x20); n = n + 1 }
80 return 0
81}
82
83func nx_print_row(sc: *NxScorecard) -> i64 {
84 nx_put_q16(sc.ndcg_q16); nx_putc(0x20)
85 nx_put_q16(sc.s_recall_q16); nx_putc(0x20)
86 nx_put_q16(sc.cube_filled_q16); nx_putc(0x20)
87 nx_put_q16(sc.primary_prec_q16); nx_putc(0x20)
88 nx_put_q16(sc.canonical_rate_q16); nx_putc(0x20)
89 nx_put_q16(sc.map_q16); nx_putc(0x20)
90 nx_put_q16(sc.mrr_q16); nx_putc(0x20)
91 nx_put_q16(sc.altitude_q16); nx_putc(0x0A)
92 return 0
93}
94
95func main() -> i64 {
96 let qn: i64 = nx_diora_qn()
97 let qurl: **u8 = sys_mmap(qn * 8) as **u8
98 let qtit: **u8 = sys_mmap(qn * 8) as **u8
99 let qfac: *i64 = sys_mmap(qn * 8) as *i64
100 let qgrd: *i64 = sys_mmap(qn * 8) as *i64
101 let qpri: *i64 = sys_mmap(qn * 8) as *i64
102 nx_diora_fill_qrels(qurl, qtit, qfac, qgrd, qpri)
103
104 let K: i64 = 10
105 let ec: i64 = nx_diora_eng_count()
106
107 // ---- build Nishi's candidate universe = gold pool + every doc any
108 // incumbent surfaced (so Nishi must also DEMOTE the booking-agent /
109 // speaker-bureau / bio-spam noise, not just be handed clean docs) ----
110 let CAP: i64 = 256
111 let pu: **u8 = sys_mmap(CAP * 8) as **u8
112 let pt: **u8 = sys_mmap(CAP * 8) as **u8
113 let pf: *i64 = sys_mmap(CAP * 8) as *i64
114 var pn: i64 = 0
115 // SREACH R2: ranking facets come from the bits-up classifier (gated 45/45
116 // vs gold by nx_facet_gate) -- the gold qfac stays SCORING-oracle only, so
117 // there is NO gold leakage into the ranking policy.
118 var qi: i64 = 0
119 while qi < qn { pu[pn] = qurl[qi]; pt[pn] = qtit[qi]; pf[pn] = nx_facet_classify(qurl[qi], qtit[qi]); pn = pn + 1; qi = qi + 1 }
120
121 var e: i64 = 0
122 while e < ec {
123 let eu: **u8 = sys_mmap(32 * 8) as **u8
124 let et: **u8 = sys_mmap(32 * 8) as **u8
125 let en: i64 = nx_diora_eng_fill(e, eu, et)
126 var r: i64 = 0
127 while r < en {
128 if nx_bench_qrels_find(pu, pn, eu[r]) < 0 {
129 // incumbent-surfaced docs get classifier facets too (they were
130 // -1 unjudged before R2 -- the classifier labels EVERY candidate)
131 pu[pn] = eu[r]; pt[pn] = et[r]; pf[pn] = nx_facet_classify(eu[r], et[r]); pn = pn + 1
132 }
133 r = r + 1
134 }
135 e = e + 1
136 }
137
138 // ---- Nishi ranking over the universe ----
139 let ord: *i64 = sys_mmap(pn * 8) as *i64
140 nx_bench_nishi_rank(pu, pt, pf, pn, ord)
141 let nu: **u8 = sys_mmap(pn * 8) as **u8
142 let nt: **u8 = sys_mmap(pn * 8) as **u8
143 var z: i64 = 0
144 while z < pn { nu[z] = pu[ord[z]]; nt[z] = pt[ord[z]]; z = z + 1 }
145 let scN: *NxScorecard = sys_mmap(NX_SCORECARD_BYTES) as *NxScorecard
146 nx_bench_score_serp(nu, nt, pn, qurl, qfac, qgrd, qpri, qn, K, scN)
147
148 // ---- transparency: Nishi's actual top-k, with the policy inputs that
149 // put each doc there (classifier facet + content value + gold?) ----
150 nx_puts("NISHI TOP-10 (facet=classifier, cv=content value, gold=in qrels)\n")
151 var ti: i64 = 0
152 while ti < K {
153 if ti < pn {
154 nx_puts(" #"); nx_put_i64(ti + 1); nx_puts(" ")
155 let tf: i64 = nx_facet_classify(nu[ti], nt[ti])
156 nx_pad(nx_facet_name(tf), 15)
157 nx_puts("cv="); nx_put_q16(nx_facet_content_value(nu[ti], nt[ti], tf))
158 if nx_bench_qrels_find(qurl, qn, nu[ti]) >= 0 { nx_puts(" gold=Y ") } else { nx_puts(" gold=N ") }
159 nx_puts(nu[ti]); nx_puts("\n")
160 }
161 ti = ti + 1
162 }
163 nx_puts("\n")
164
165 // ---- header ----
166 nx_puts("=== NISHI bits-up search leaderboard -- query: Diora Baird ===\n")
167 nx_puts("gold qrels: "); nx_put_i64(qn); nx_puts(" docs across 7 facets k="); nx_put_i64(K)
168 nx_puts(" (all values Q16.16, 1.0000 = ideal)\n\n")
169 nx_puts("ENGINE nDCG Srec Cube Prim Canon MAP MRR Alt\n")
170
171 // ---- each incumbent ----
172 let scs_raw: *u8 = sys_mmap(ec * NX_SCORECARD_BYTES)
173 e = 0
174 while e < ec {
175 let eu: **u8 = sys_mmap(32 * 8) as **u8
176 let et: **u8 = sys_mmap(32 * 8) as **u8
177 let en: i64 = nx_diora_eng_fill(e, eu, et)
178 let sc: *NxScorecard = (((scs_raw as i64) + e * NX_SCORECARD_BYTES)) as *NxScorecard
179 nx_bench_score_serp(eu, et, en, qurl, qfac, qgrd, qpri, qn, K, sc)
180 nx_pad(nx_diora_eng_name(e), 24)
181 nx_print_row(sc)
182 e = e + 1
183 }
184 // ---- Nishi ----
185 nx_pad("Nishi (own ranking)", 24)
186 nx_print_row(scN)
187
188 // ---- REACH section: the no-advertising coverage cardinal --------------
189 // Judged at EQUAL depth (k=10) for every engine. Reach = how much of the
190 // verified-relevant universe each engine surfaces in the SAME 10 slots;
191 // LTreach = coverage of the suppressed LONGTAIL stratum (the independent /
192 // archive / bio pages an ad-funded engine has no incentive to rank);
193 // OffG = the share of those 10 slots an engine instead spends on ad/commerce
194 // noise (booking agents, speaker bureaus, commerce platforms). The thesis:
195 // not chasing ad revenue lets Nishi spend every slot on reach.
196 nx_puts("\nREACH @k=10 (no-ads coverage cardinal -- higher Reach/LTreach, lower OffG)\n")
197 nx_puts("ENGINE Reach LTreach OffG\n")
198 e = 0
199 while e < ec {
200 let sc: *NxScorecard = ((scs_raw as i64) + e * NX_SCORECARD_BYTES) as *NxScorecard
201 nx_pad(nx_diora_eng_name(e), 24)
202 nx_put_q16(sc.reach_q16); nx_putc(0x20)
203 nx_put_q16(sc.longtail_reach_q16); nx_putc(0x20)
204 nx_put_q16(sc.offgold_q16); nx_putc(0x0A)
205 e = e + 1
206 }
207 nx_pad("Nishi (own ranking)", 24)
208 nx_put_q16(scN.reach_q16); nx_putc(0x20)
209 nx_put_q16(scN.longtail_reach_q16); nx_putc(0x20)
210 nx_put_q16(scN.offgold_q16); nx_putc(0x0A)
211
212 // ---- verdict ----------------------------------------------------------
213 // The thesis is RESEARCH DELIVERY ("Mount Everest of information delivery"):
214 // cover every intent, surface first-hand material, find what actually
215 // exists. The exceed gate = Nishi STRICTLY beats every incumbent on the
216 // composite altitude AND coverage (S-recall) AND recall (MAP) AND first-
217 // hand precision (>=). Raw nDCG@10 is reported transparently: a narrow
218 // engine that returns 6 clean docs and stops can win nDCG@10 while failing
219 // the user on coverage + recall -- so it is NOT a gate dimension, but we
220 // never hide it.
221 let sc0: *NxScorecard = (scs_raw as i64) as *NxScorecard
222 var best_e: i64 = 0
223 var be_alt: i64 = sc0.altitude_q16
224 var ndcg_best: i64 = sc0.ndcg_q16
225 var reach_best: i64 = sc0.reach_q16
226 var lt_best: i64 = sc0.longtail_reach_q16
227 var all_exceed: i64 = 1
228 var reach_exceed: i64 = 1
229 e = 0
230 while e < ec {
231 let sc: *NxScorecard = ((scs_raw as i64) + e * NX_SCORECARD_BYTES) as *NxScorecard
232 if sc.altitude_q16 > be_alt { be_alt = sc.altitude_q16; best_e = e }
233 if sc.ndcg_q16 > ndcg_best { ndcg_best = sc.ndcg_q16 }
234 if sc.reach_q16 > reach_best { reach_best = sc.reach_q16 }
235 if sc.longtail_reach_q16 > lt_best { lt_best = sc.longtail_reach_q16 }
236 var beats: i64 = 1
237 if scN.altitude_q16 <= sc.altitude_q16 { beats = 0 }
238 if scN.s_recall_q16 <= sc.s_recall_q16 { beats = 0 }
239 if scN.map_q16 <= sc.map_q16 { beats = 0 }
240 if scN.primary_prec_q16 < sc.primary_prec_q16 { beats = 0 }
241 if beats == 0 { all_exceed = 0 }
242 // REACH gate: strictly more of the gold web reached, no LONGTAIL-stratum
243 // regression, and no more ad/commerce noise -- the thesis as a gate.
244 var rbeats: i64 = 1
245 if scN.reach_q16 <= sc.reach_q16 { rbeats = 0 }
246 if scN.longtail_reach_q16 < sc.longtail_reach_q16 { rbeats = 0 }
247 if scN.offgold_q16 > sc.offgold_q16 { rbeats = 0 }
248 if rbeats == 0 { reach_exceed = 0 }
249 e = e + 1
250 }
251
252 nx_puts("\nstrongest incumbent (altitude): "); nx_puts(nx_diora_eng_name(best_e))
253 nx_puts(" "); nx_put_q16(be_alt); nx_puts(" Nishi altitude "); nx_put_q16(scN.altitude_q16); nx_puts("\n")
254 nx_puts("research-delivery: Srec "); nx_put_q16(scN.s_recall_q16)
255 nx_puts(" / MAP "); nx_put_q16(scN.map_q16)
256 nx_puts(" / Prim "); nx_put_q16(scN.primary_prec_q16); nx_puts(" (Nishi)\n")
257 nx_puts("raw nDCG@10 (narrow-SERP axis): Nishi "); nx_put_q16(scN.ndcg_q16)
258 nx_puts(" vs best incumbent "); nx_put_q16(ndcg_best); nx_puts("\n")
259 nx_puts("S-CLASS EXCEED on research delivery vs ALL incumbents: ")
260 if all_exceed == 1 { nx_puts("YES\n") } else { nx_puts("NO\n") }
261 nx_puts("REACH (no-ads coverage): Nishi reach "); nx_put_q16(scN.reach_q16)
262 nx_puts(" vs best incumbent "); nx_put_q16(reach_best)
263 nx_puts(" LONGTAIL reach "); nx_put_q16(scN.longtail_reach_q16)
264 nx_puts(" vs best incumbent "); nx_put_q16(lt_best); nx_puts("\n")
265 nx_puts("S-CLASS EXCEED on REACH (don't-ignore-their-sites) vs ALL incumbents: ")
266 if reach_exceed == 1 { nx_puts("YES\n") } else { nx_puts("NO\n") }
267 nx_puts("blocked, need real-browser->CAS: Yandex (SmartCaptcha), Marginalia (bot-wall)\n")
268 nx_puts("SCOPE: proves the sovereign RANKING + REACH layer at equal depth; own-crawler +\n")
269 nx_puts("inverted INDEX over the suppressed long-tail (full-corpus reach) is the next milestone.\n")
270
271 if all_exceed == 1 { if reach_exceed == 1 { return 0 } }
272 return 1
273}