code wiki / (root) / nx_imgsearch_engine.nx

nx_imgsearch_engine.nx

buildroot/runtime/nx_imgsearch_engine.nx

22067 B476 linesdepth 8pulls 17 transitivereach 3 importersview sourcekind librarytopic imgsearch
docsdependenciesstructsconstsfunctions

about

nx_imgsearch_engine.nx -- THE MULTI-TIER REVERSE-IMAGE QUERY ENGINE. Replaces the shipped single-tier client (nx_image_search) on two counts, both of them load-bearing: 1. IT SCALES. The shipped client ranks by scanning every fingerprint and then SELECTION-SORTING the whole corpus -- O(N^2). At 1,000 images that is a million comparisons; at the 10^6 an indie image index reaches it is 10^12 and the query never returns. Here every tier extracts its top-K through a BOUNDED MAX-HEAP of size K: O(N log K) time and O(K) space, with N touched exactly once. Going from 10^3 to 10^6 images multiplies the work by 10^3, not 10^6. 2. IT FUSES. One descriptor cannot cover the modification space (nx_imgbench proves it class by class), so the engine runs every registered tier and combines their ranked lists with RECIPROCAL RANK FUSION -- score = sum over tiers of weight / (K_RRF + rank). RRF is the fusion the S-Class IR literature settles on precisely because it needs no score calibration between rankers: a Hamming distance over 64 bits and an L1 distance over 80 dimensions are never comparable as magnitudes, but their RANKS always are. Same integer discipline as the text engine -- no floats anywhere. The engine holds only base-class tier pointers. Adding local-feature or semantic matching is a new nx_imgtier subtype plus one add_tier call; this file does not change. That is the design contract. genealogy_id: cormack_2009_reciprocal_rank_fusion + williams_1975_bounded_heap_selection license_tier: ORIGINAL

dependencies 2 imports · 3 importers

nx_imgsearch_tier.nx nx_phash_index.nx nx_imgsearch_engine.nx nx_imgbench.nx nx_imgsearch.nx nx_imgsearch_engine_gate.nx

imports: nx_imgsearch_tier.nxnx_phash_index.nx

imported by: nx_imgbench.nxnx_imgsearch.nxnx_imgsearch_engine_gate.nx

structs

38struct nx_bkaccel
47struct nx_imgengine

consts

25const NX_MAGIC_1000000: i64 = 1000000
27const NX_IE_MAXTIERS: i64 = 8
28const NX_IE_MAXK: i64 = 64
29const NX_IE_RRF_K: i64 = 60 // Cormack/Clarke/Buettcher 2009 -- damps the top-rank monopoly
45const NX_BKACCEL_BYTES: i64 = 40
58const NX_IMGENGINE_BYTES: i64 = 64

functions

60func nx_imgengine_count(e: *nx_imgengine) -> i64 { return e.count }
called by 1: main
61func nx_imgengine_cap(e: *nx_imgengine) -> i64 { return e.cap }
62func nx_imgengine_ntiers(e: *nx_imgengine) -> i64 { return e.ntiers }
called by 2: s_emit_tiersmain
63func nx_imgengine_last_visited(e: *nx_imgengine) -> i64 { return e.last_visited }
called by 1: main
64func nx_imgengine_tier(e: *nx_imgengine, i: i64) -> *nx_imgtier
69func nx_imgengine_new(cap: i64) -> *nx_imgengine
85func ie_accel(e: *nx_imgengine, ti: i64) -> *nx_bkaccel
92func ie_tier_is_hash(t: *nx_imgtier) -> i64
103func nx_imgengine_add_tier(e: *nx_imgengine, t: *nx_imgtier) -> i64
128func ie_desc_at(e: *nx_imgengine, ti: i64, i: i64) -> *i64
138func nx_imgengine_add_image(e: *nx_imgengine, gray: *u8, rgb: *u8, w: i64, h: i64, payload: i64) -> i64
161func ie_swap(hd: *i64, hp: *i64, a: i64, b: i64) -> i64
166func ie_heap_up(hd: *i64, hp: *i64, start: i64) -> i64
called by 1: ie_heap_offer calls 1: ie_swap
177func ie_heap_down(hd: *i64, hp: *i64, n: i64, start: i64) -> i64
called by 2: ie_heap_offerie_heap_drain calls 1: ie_swap
191func ie_heap_offer(hd: *i64, hp: *i64, nbox: *i64, k: i64, key: i64, item: i64) -> i64
207func ie_heap_drain(hd: *i64, hp: *i64, n_in: i64, out_key: *i64, out_item: *i64) -> i64
229func ie_tier_topk_bk(e: *nx_imgengine, ti: i64, qdesc: *i64, k: i64,
276func nx_imgengine_tier_topk(e: *nx_imgengine, ti: i64, qdesc: *i64, k: i64,
309func nx_imgengine_query_class(e: *nx_imgengine, gray: *u8, rgb: *u8, w: i64, h: i64, topk: i64,
424func nx_imgengine_query(e: *nx_imgengine, gray: *u8, rgb: *u8, w: i64, h: i64, topk: i64,
438func nx_imgengine_best_match_r(e: *nx_imgengine, gray: *u8, rgb: *u8, w: i64, h: i64,
472func nx_imgengine_best_match(e: *nx_imgengine, gray: *u8, rgb: *u8, w: i64, h: i64,