code wiki / (root) / nx_distrib_embed.nx

nx_distrib_embed.nx

buildroot/runtime/nx_distrib_embed.nx

5967 B110 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_distrib_embed.nx -- R3 rung 2 (R3b): a SOVEREIGN DISTRIBUTIONAL embedder = the Jina-Embeddings replacement, count-based (NOT a trained neural net, NO float, NO training loop): "you shall know a word by the company it keeps" (Firth 1957 / Turney-Pantel 2010). Word vector = its co-occurrence row over a corpus; doc vector = sum of its words' rows; similarity = integer cosine (isqrt). This is the SEMANTIC lever nx_vec_index needed. THE PROOF (what BM25 canNOT do): query 'cat' retrieves the DOG doc over the CAR doc even though NEITHER contains the word 'cat' -- pure semantic (shared context), zero lexical overlap. main() = KAT gate + neg-control. HONEST SCOPE: proves the METHOD on a controlled mini-corpus (docs pre-tokenized to word-IDs to isolate the embedder from string-tokenization). Scaling to the real 519-doc library (tokenizer + big matrix) = R3b-scale. license_tier: ORIGINAL expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_distrib_embed.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap dw sys_write add_doc chk dw ↻ dn sys_mmap ↻ sys_write ↻ cos2 vdot isqrt doc_vec dn ↻

structs

none

consts

11const K_MAGIC_4096: i64 = 4096

functions

13func dw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 2: chkmain calls 1: sys_write
14func dn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m; sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
called by 2: chkmain calls 2: sys_mmapsys_write
16func isqrt(n: i64) -> i64
called by 1: cos2
25func vdot(a: *i64, ao: i64, b: *i64, bo: i64, d: i64) -> i64
called by 1: cos2
32func cos2(a: *i64, ao: i64, b: *i64, bo: i64, d: i64) -> i64
called by 1: main calls 2: vdotisqrt
44func add_doc(M: *i64, V: i64, doc: *i64, len: i64) -> i64
called by 1: main
55func doc_vec(M: *i64, V: i64, doc: *i64, len: i64, out: *i64) -> i64
called by 1: main
62func chk(label: *u8, got: i64, exp: i64, tot: *i64) -> i64
called by 1: main calls 2: dwdn
68func main() -> i64