code wiki / _hdl_build / nx_book_search.nx

nx_book_search.nx

buildroot/runtime/_hdl_build/nx_book_search.nx

8369 B139 linesdepth 4pulls 5 transitivereach 0 importersview sourcekind tooltopic book
docsdependenciesstructsconstsfunctions

about

nx_book_search.nx -- SC20: sovereign RANKED search over the NAS book library (idx_book.wsl, 5761 books). REUSE not reinvent: composes the team's production BM25 ranker (nx_bm25: bm_idf_micro / bm_sat_milli / bm_token_count / bm_df) + nx_research_extract (re_count/re_has). The existing nx_library_search is wired for the researcher's [doc]-index corpus and caps at 256 docs; this drives the SAME BM25 math over the 5761-book library index. TWO fixes for scale + real-world data: (1) case-insensitive: the index paths are mixed-case, so we rank over a LOWERCASED copy of the index. (2) O(N*nq) not O(N^2): bm_best recomputes df per-doc (fine for 256 docs, not 5761); we PRECOMPUTE idf once per query term, then score each doc -> a true library-scale ranker. Self-gated by KATs over the REAL index (dragonlance/byers/tolkien/witcher must rank a doc that contains the term; "sanderson" has 0 matches -> must return NO result = negative control; dragonlance != byers = discrim). Standalone (no server/reader edit -> no collision with the ark-beat loop). license_tier: ORIGINAL

dependencies 4 imports · 0 importers

nx_research_extract.nx nx_itoa_lib.nx nx_bm25.nx nx_syscalls.nx nx_book_search.nx

imports: nx_research_extract.nxnx_itoa_lib.nxnx_bm25.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main bs_p sys_write sys_mmap bs_read sys_openat_rd sys_read sys_close sys_exit bs_lc bm_token_count bs_n nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap bs_best1 bm_idf_micro bm_ln_micro bm_df re_has re_find re_strlen re_count re_strlen ↻ bm_sat_milli sys_write ↻ re_has ↻ sys_openat_append bs_fp sys_write ↻ bs_fn nxi_fd ↻ sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real sys_close ↻

structs

none

consts

17const BS_MAGIC_2000000: i64 = 2000000
19const BS_IDX: *u8 = "knowledge/staging/media/idx_book.wsl"
20const BS_LOG: *u8 = "knowledge/status/book_search.log"
21const BS_CAPDOCS: i64 = 8192 // > 5761

functions

23func bs_p(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 1: main calls 1: sys_write
28func bs_n(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
29func bs_fp(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 1: main calls 1: sys_write
34func bs_fn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: main calls 1: nxi_fd
35func bs_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
called by 1: main
37func bs_read(path: *u8, buf: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
47func bs_best1(ptrs: *i64, lens: *i64, dls: *i64, ndocs: i64, avgdl: i64, term: *u8) -> i64
62func main() -> i64