nx_research_synth_qwen.nx
buildroot/runtime/nx_research_synth_qwen.nx
about
nx_research_synth_qwen.nx -- S1 of the Tesla growth ladder: SOVEREIGN GROUNDED SYNTHESIS.
Given a question + N retrieved source passages, the pretrained sovereign Qwen (nsv_generate, in-process,
no HTTP, $0, integer-deterministic) generates a MULTI-SENTENCE answer that cites each claim [n] back to a
numbered source. The organ's RESONANT property (Tesla law #1) is not the generation -- it is the
DETERMINISTIC GROUNDING CHECK that runs at $0 with NO model: every content word of the answer must trace
to a cited source, and every citation must be in range. A hallucinated claim (word absent from all sources)
or a fabricated citation ([5] when 2 sources exist) is caught mechanically. This is the anti-hallucination
discipline FARS lacked (its own audit: 5.7% hallucinated citations, 7.4% fabricated results).
Composes: nx_nofloat_serve_core (nsv_init/nsv_generate). Model-call pattern mirrors nx_qwen_extract (proven).
The grounding functions (rsq_ground_report / rsq_parse_cites / rsq_is_refusal) need NO model -> the gate
proves the mechanism in miniature (law #3), and the generative path is marker-gated for NAS measurement.
NEXT (S2): each ungrounded claim -> nx_evidence_verify_gate for external confirm/discredit. license_tier: ORIGINAL
dependencies 3 imports · 3 importers
imports: nx_syscalls.nxnx_nofloat_serve_core.nxnx_text_sentences.nx
imported by: nx_research_report.nxnx_research_synth_qwen_gate.nxnx_research_verify_synth.nx
structs
| none |
consts
| 18 | const RSQ_MODEL: *u8 = "/home/elderwesto/nx_stage/nx_real_model.gguf" |
| 19 | const RSQ_SRCCAP: i64 = 600 // per-source byte cap inside the prompt |
| 20 | const RSQ_MAXPROMPT: i64 = 4000 // hard byte guard (<< NSV_MAXIN=16384 tok-scratch; ~1600 tok < NSV_MAXT=2048) |
| 21 | const RSQ_MAXNEW: i64 = 64 // synthesis needs a 2-4 sentence answer (extraction used 16) |
| 22 | const RSQ_MODE: i64 = 0 // 0 = i32 lossless (faithful default) |
| 23 | const RSQ_MINWORD: i64 = 5 // a content word is len>=5 (filters most function words) |
functions
| 34 | func rsq_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 35 | func rsq_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } |
| 36 | func rsq_is_alnum(c: i64) -> i64 |
| 42 | func rsq_cat(dst: *u8, off: i64, s: *u8, n: i64, cap: i64) -> i64 called by 1: rsq_build_prompt |
| 47 | func rsq_cats(dst: *u8, off: i64, s: *u8, cap: i64) -> i64 called by 1: rsq_build_prompt |
| 52 | func rsq_catd(dst: *u8, off: i64, d: i64, cap: i64) -> i64 called by 1: rsq_build_prompt |
| 59 | func rsq_ci_match_at(buf: *u8, pos: i64, blen: i64, word: *u8, wlen: i64) -> i64 |
| 68 | func rsq_ci_contains(buf: *u8, blen: i64, word: *u8, wlen: i64) -> i64 |
| 78 | func rsq_word_end(ans: *u8, i: i64, alen: i64) -> i64 |
| 88 | func rsq_eqword(ans: *u8, off: i64, wlen: i64, w: *u8) -> i64 |
| 99 | func rsq_is_stop(ans: *u8, off: i64, wlen: i64) -> i64 |
| 118 | func rsq_present_in_sources(ans: *u8, off: i64, wlen: i64, srcv: *i64, nsrc: i64) -> i64 |
| 129 | func rsq_ground_report(ans: *u8, alen: i64, srcv: *i64, nsrc: i64, out: *i64) -> i64 |
| 154 | func rsq_parse_cites(ans: *u8, alen: i64, cites: *i64, maxc: i64, srcrange: i64, out: *i64) -> i64 |
| 182 | func rsq_is_refusal(ans: *u8, alen: i64) -> i64 |
| 190 | func rsq_verdict(ans: *u8, alen: i64, srcv: *i64, nsrc: i64, htol: i64, out: *i64) -> i64 |
| 210 | func rsq_sentence_cite(ans: *u8, s: i64, e: i64, nsrc: i64, outp: *i64) -> i64 |
| 233 | func rsq_span_overlaps_src(ans: *u8, s: i64, e: i64, srcv: *i64, c: i64) -> i64 |
| 252 | func rsq_claim_verdict(ans: *u8, alen: i64, srcv: *i64, nsrc: i64, out: *i64) -> i64 called by 1: main calls 7: sys_mmaptxt_sentence_endrsq_is_alnumrsq_word_endrsq_is_stoprsq_sentence_cite+1 |
| 285 | func rsq_build_prompt(q: *u8, srcv: *i64, nsrc: i64, pr: *u8, cap: i64) -> i64 |
| 309 | func rsq_load() -> i64 |
| 337 | func rsq_ready() -> i64 { return g_rsq_ready } |
| 341 | func rsq_synth(q: *u8, srcv: *i64, nsrc: i64, ans: *u8) -> i64 |