code wiki / (root) / nx_queries_merge.nx

nx_queries_merge.nx source

↩ module page · 31 lines · 1995 B

1// nx_queries_merge.nx -- REWRITE ENSEMBLE AS TERM UNION (search R0l+, 2026-09-16): join K BEIR query files row by row 2// into ONE queries file whose text is the space-joined union of every file's text for that query id. 3// 4// WHY. Every reasoning rewrite of a query is one sample of the vocabulary the answer lives in; two rewrites of the same 5// query from different engines or seeds cover different terms. With the BM25Q query-term saturation already in 6// nx_beir_eval (S5), the union of K rewrites scores as one long query whose repeated terms saturate instead of piling 7// up, so a K-rewrite ensemble needs NO evaluator change: it is a queries file. This organ makes that file, and nothing 8// else (rank fusion of the K rankings is the next arm, and it lives in the evaluator when it comes). 9// 10// CONTRACT. Every input carries the same query ids in the same order (the rewrite driver preserves the split's order), 11// and the organ REFUSES BY NAME on the first row whose id differs or on a row-count mismatch -- a silently misaligned 12// merge would score one query's rewrite against another's judgments and look like a real number. The output is 13// truncate-written to <out>.tmp and renamed, so a killed run leaves no half file. 14// nx_queries_merge <out.tsv> <in1.tsv> <in2.tsv> [<in3.tsv> ...] 15// exit 0 MERGED / 2 usage / 3 REFUSED (mismatch named) / 4 io 16// license_tier: ORIGINAL No hw writes (Rule 26). 17import "nx_syscalls.nx" 18import "nx_queries_merge_lib.nx" 19 20func main(argc: i64, argv: *i64) -> i64 { 21 if argc < 4 { qm_puts("usage: nx_queries_merge <out.tsv> <in1.tsv> <in2.tsv> [<in3.tsv> ...]\n" as *u8); return QM_EXIT_USAGE } 22 let out: *u8 = argv[1] as *u8 23 let n_in: i64 = argc - 2 24 let ins: *i64 = sys_mmap(n_in * QM_I64) as *i64 25 var i: i64 = 0 26 while i < n_in { ins[i] = argv[2 + i]; i = i + 1 } 27 let st: *i64 = sys_mmap(QM_ST_SLOTS * QM_I64) as *i64 28 let rc: i64 = qm_merge(out, ins, n_in, st) 29 qm_report(out, n_in, st, rc) 30 return rc 31}