code wiki / _hdl_build / nx_click.nx
nx_click.nx source
↩ module page · 25 lines · 1319 B
1// nx_click.nx -- R-UX-4 of the onsite-search S-class ladder: SOVEREIGN query-analytics / click-loop (LIBRARY).
2// Learning-to-rank "uses click-through data" (cited srch_ltr.raw): record which result users actually click for a
3// query, aggregate into a click-through-rate signal, and feed it as a ranking FEATURE (popular-for-this-query
4// docs rise). CONTENT-NEUTRAL by construction -- counts only, no query text stored, no PII, no profiling
5// [[feedback-content-neutral-no-filter-search]]. Integer milli-CTR (no-float).
6//
7// exports: vr_click_record, vr_click_raw, vr_click_ctr. license_tier: ORIGINAL
8import "nx_syscalls.nx"
9
10// record one impression of (q,d); clicked=1 if the user clicked it. clk/imp are flat [Q*Dn] count matrices.
11func vr_click_record(clk: *i64, imp: *i64, Dn: i64, q: i64, d: i64, clicked: i64) -> i64 {
12 imp[q*Dn+d] = imp[q*Dn+d] + 1
13 if clicked == 1 { clk[q*Dn+d] = clk[q*Dn+d] + 1 }
14 return 0
15}
16
17// raw click count feature for (q,d)
18func vr_click_raw(clk: *i64, Dn: i64, q: i64, d: i64) -> i64 { return clk[q*Dn+d] }
19
20// milli-CTR = clicks*1000/impressions (the normalized ranking feature); 0 if never shown
21func vr_click_ctr(clk: *i64, imp: *i64, Dn: i64, q: i64, d: i64) -> i64 {
22 let im: i64 = imp[q*Dn+d]
23 if im == 0 { return 0 }
24 return clk[q*Dn+d] * 1000 / im
25}