nx_rank_fused_test.nx source
↩ module page · 56 lines · 2380 B
1// nx_rank_fused_test.nx -- KAT for the additive tier+BM25+RRF ranker.
2// Native sovereign lane; exit 0 = pass, N = assertion N failed.
3//
4// The thesis, proven end-to-end on a controlled 5-doc corpus, query "diora":
5// A(0): high tier (IMDb primary) + relevant content -> best in BOTH
6// B(1): high tier (IMDb primary) + NO relevant content -> authority only
7// C(2): low tier (unknown blog) + STRONG relevant content
8// D(3): platform, no content; E(4): unknown, no content
9// Expected: A ranks #1 (best in both); and C (low-tier but relevant) ranks
10// ABOVE B (high-tier but irrelevant) -- content beats domain prejudice.
11
12import "fx.nx"
13import "nx_str.nx"
14import "nx_rank_fused.nx"
15
16func main() -> i64 {
17 let n: i64 = 5
18 let urls: **u8 = sys_mmap(n * 8) as **u8
19 let tits: **u8 = sys_mmap(n * 8) as **u8
20 let texts: **u8 = sys_mmap(n * 8) as **u8
21 let tlen: *i64 = sys_mmap(n * 8) as *i64
22
23 urls[0] = "https://www.imdb.com/name/nm1401531/"; tits[0] = "Diora Baird"; texts[0] = "diora baird american actress"
24 urls[1] = "https://www.imdb.com/title/tt0796366/"; tits[1] = "Star Trek"; texts[1] = "lattice quantum gauge boson hadron"
25 urls[2] = "https://someblog.xyz/diora"; tits[2] = "fan page"; texts[2] = "diora diora diora baird fan tribute"
26 urls[3] = "https://www.youtube.com/watch?v=x"; tits[3] = "cooking"; texts[3] = "cooking recipe kitchen food"
27 urls[4] = "https://another.xyz/space"; tits[4] = "space"; texts[4] = "astronomy galaxy nebula star"
28 var i: i64 = 0
29 while i < n { tlen[i] = nx_str_len(texts[i]); i = i + 1 }
30
31 let qd: **u8 = sys_mmap(8) as **u8
32 let qdl: *i64 = sys_mmap(8) as *i64
33 qd[0] = "diora"; qdl[0] = nx_str_len(qd[0])
34
35 let order: *i64 = sys_mmap(n * 8) as *i64
36 nx_rank_fused(urls, tits, texts, tlen, n, qd, qdl, 1, order)
37
38 // A (best in both signals) ranks #1
39 if order[0] != 0 { return 1 }
40
41 // C (low-tier + relevant) ranks ABOVE B (high-tier + irrelevant):
42 // content relevance beats domain authority -- the anti-prejudice thesis.
43 var posB: i64 = 0 - 1
44 var posC: i64 = 0 - 1
45 var z: i64 = 0
46 while z < n {
47 if order[z] == 1 { posB = z }
48 if order[z] == 2 { posC = z }
49 z = z + 1
50 }
51 if posB < 0 { return 2 }
52 if posC < 0 { return 3 }
53 if posC >= posB { return 4 }
54
55 return 0
56}