code wiki / _hdl_build / nx_sitededup_lib.nx
nx_sitededup_lib.nx
buildroot/runtime/_hdl_build/nx_sitededup_lib.nx
about
nx_sitededup_lib.nx -- THE ONE COPY OF THE NEAR-DUPLICATE COLLAPSE DECISION.
module: nishi-core.search.sitededup
capability: CORE_COMPUTE (pure; reads a conf, touches no store, writes no file)
license_tier: ORIGINAL No hw writes (Rule 26).
WHY A LIB AND NOT A FUNCTION INSIDE THE ACTUATOR: the actuator suppresses rows in a LIVE
production shard and the gate proves the decision is correct. If each held its own copy of
the rule they could disagree, and the one that ships is the one nobody proved. There is
exactly one clusterer here, and both import it -- disagreement is impossible by construction.
COMPOSES nx_simhash (Charikar STOC 2002 fingerprint, Manku WWW 2007 threshold). It does NOT
contain a second fingerprinting ruler and must never grow one. The TEXT handed to that
fingerprint is normalised by nx_textnorm_lib, which is likewise a single shared copy: the
clusterer never sees raw bytes and never decides what normalisation means.
---- THE TRANSITIVITY HAZARD, HANDLED RATHER THAN ASSUMED -------------------------------
Near-duplication is NOT transitive: a~b and b~c does not give a~c. So a connected component
of the near-dup graph can be a CHAIN whose endpoints are genuinely different documents, and
collapsing it onto one survivor would suppress a document that is not a near-duplicate of
anything left searchable -- i.e. it would DELETE INFORMATION, which is the one outcome this
organ exists to avoid.
The fix is not to hope chains are rare. sdd_mark_chained MEASURES every component's diameter
(its widest internal pair) and any component wider than the threshold is marked UNSAFE and
left ENTIRELY ALONE -- every member stays searchable. The organ abstains on exactly the cases
it cannot justify, and reports how many. Abstain, never acquit; and here, abstain rather than
destroy.
The survivor of a safe component is therefore always within `k` bits of EVERY doc it replaces,
which is the property that makes suppression defensible at all.
DETERMINISM: union-by-lowest-cid means a component's root is its globally minimum cid no
matter what order the unions happen in. Two runs over the same shard pick the same survivor,
so the pass is idempotent and re-runnable -- it can never flip-flop and eat the corpus.
dependencies 3 imports · 2 importers
imports: nx_syscalls.nxnx_simhash.nxnx_lineconf_lib.nx
imported by: nx_sitededup.nxnx_sitededup_gate.nx
structs
| none |
consts
| 39 | const SDD_HIST: i64 = 17 |
| 40 | const SDD_BITS: i64 = 64 |
functions
| 52 | func sdd_confpath() -> *u8 { return "knowledge/sitededup.conf" as *u8 } |
| 53 | func sdd_confpath_up() -> *u8 { return "../knowledge/sitededup.conf" as *u8 } |
| 57 | func sdd_conf_int(key: *u8) -> i64 called by 3: sdd_conf_ksdd_conf_maxdocssdd_conf_showrows calls 3: lcf_int_ofsdd_confpathsdd_confpath_up |
| 64 | func sdd_conf_which() -> i64 |
| 69 | func sdd_conf_k() -> i64 { return sdd_conf_int("hamming_max" as *u8) } |
| 70 | func sdd_conf_maxdocs() -> i64 { return sdd_conf_int("max_docs" as *u8) } |
| 71 | func sdd_conf_showrows() -> i64 { return sdd_conf_int("show_rows" as *u8) } |
| 72 | func sdd_conf_missing(v: i64) -> i64 { if v == LCF_MISS { return 1 } return 0 } |
| 83 | func sdd_set_add(tab: *i64, mask: i64, cid: i64) -> i64 |
| 96 | func sdd_find(parent: *i64, x0: i64) -> i64 |
| 101 | func sdd_union(parent: *i64, cids: *i64, a: i64, b: i64) -> i64 |
| 118 | func sdd_cluster(cids: *i64, fps: *i64, n: i64, k: i64, parent: *i64, hist: *i64, eparent: *i64) -> i64 |
| 145 | func sdd_mark_chained(fps: *i64, n: i64, k: i64, parent: *i64, unsafe_of: *i64) -> i64 |
| 190 | func sdd_is_suppressed(i: i64, parent: *i64, unsafe_of: *i64, eparent: *i64) -> i64 |
| 202 | func sdd_survivor_of(i: i64, parent: *i64, unsafe_of: *i64, eparent: *i64) -> i64 |
| 210 | func sdd_permil(part: i64, whole: i64) -> i64 |
| 219 | func sdd_clear_search_bit(flags: i64) -> i64 { return flags - (flags & 1) } |
| 220 | func sdd_search_allowed(flags: i64) -> i64 { if (flags & 1) == 1 { return 1 } return 0 } |