code wiki / _hdl_build / nx_semantic_retrieval.nx
nx_semantic_retrieval.nx
buildroot/runtime/_hdl_build/nx_semantic_retrieval.nx
about
nx_semantic_retrieval.nx -- SPEC A built bits-up: match a query BEYOND exact terms via co-occurrence.
Terms that appear together across the corpus are related; so a document can be relevant to a query
even when it never contains the query word, as long as it contains terms that CO-OCCUR with it. This
is the rung where retrieval can exceed BM25 (which scores 0 when the exact term is absent).
Built on Layer-8 integer ALU ops only (the spec's primitives): COUNT (term presence), IMUL+IADD
(vector dot product), ISQRT (cosine magnitude) -- no floats, no learned embeddings.
Honest boundary: co-occurrence over a small corpus is a weak proxy for true semantics; learned
embeddings (the EMBED_TRAIN primitive the Researcher flagged) are the LLM rung, not faked here.
license_tier: ORIGINAL Pairs with nx_research_extract (re_has/re_count) + nx_bm25 (exact baseline).
dependencies 2 imports · 1 importers
imports: nx_research_extract.nxnx_syscalls.nx
imported by: nx_semantic_retrieval_test.nx
structs
| none |
consts
| none |
functions
| 15 | func sr_isqrt(x: i64) -> i64 |
| 26 | func sr_doc(ptrs: *i64, k: i64) -> *u8 { return ptrs[k] as *u8 } |
| 29 | func sr_cooc(ptrs: *i64, lens: *i64, N: i64, a: *u8, b: *u8) -> i64 |
| 36 | func sr_build_qvec(ptrs: *i64, lens: *i64, N: i64, qterm: *u8, vocab: *i64, V: i64, qvec: *i64) -> i64 |
| 43 | func sr_score(ptrs: *i64, lens: *i64, k: i64, qvec: *i64, vocab: *i64, V: i64) -> i64 |
| 50 | func sr_exact(ptrs: *i64, lens: *i64, k: i64, qterm: *u8) -> i64 { return re_count(sr_doc(ptrs, k), lens[k], qterm) } |
| 52 | func sr_best(ptrs: *i64, lens: *i64, N: i64, qvec: *i64, vocab: *i64, V: i64) -> i64 |
| 59 | func sr_cosine_milli(ptrs: *i64, lens: *i64, k: i64, qvec: *i64, vocab: *i64, V: i64) -> i64 |