Repository navigation
refactor: remove duplicated logic in HNSW, QG, PiPNN, IVF and shared helpers - #190
Merged
Merged
Conversation
…ites The constructor computed the level-0 record sizes and offsets and load recomputed them to validate a file; both now use set_record_layout. Production writes of labels and cluster IDs go through set_external_label and a new set_raw_clusterid instead of raw pointer accessors. The default ef_search of 10 is a constant applied once in search_knn_sorted_direct rather than a member read by five ISA wrappers. Saved files are byte-identical.
QuantizedGraph sets its raw distance function in initialize(), which the constructor and load share. QGBuilder::write_row fetches rotated rows for the neighbors and the centroid through one lambda. PiPNN copies ID-selected rows with one helper and finishes merged small buckets with one lambda. IVF uses one constant for the removal f_add marker in remove and load.
mem_prefetch_l1 and mem_prefetch_l2 share one unrolled template over the prefetch hint. k-means computes double-precision squared norms and L2 distances with two helpers in the same index order. The v1 API reads and range-checks UnpackedU16 codes with one helper in read_codes and compute_checked; messages are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Remove duplicated logic in the index and clustering code. Results are unchanged, and there are no public API, Python API or saved-format changes. One commit per area:
set_record_layout);loadvalidates against the same derivation instead of recomputing it.set_external_labeland a newset_raw_clusterid. The two raw-pointer accessors used only for writes are removed.ef_searchof 10 is a constant applied once insearch_knn_sorted_direct, replacing a member read by five ISA wrappers.QuantizedGraphsetsraw_dist_func_ininitialize(), which the constructor andloadshare.QGBuilder::write_rowuses one lambda for its three ways of producing a rotated row: cached, rotated raw vector, or reconstructed codes.removeandload.mem_prefetch_l1andmem_prefetch_l2share one unrolled template.Left out on purpose:
search_batch: removing it would put single-query batches inside an OpenMP region.Testing
Linux x86-64 host: Xeon Gold 6418H, 2 sockets; GCC 14.3;
RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF.--no-tests=error):RABITQ_USE_OPENMP=OFF: 173 passed.check-format.sh, fullcheck-tidy.sh build-tidy(clang-tidy 23) andgit diff --checkpass.constructplus 5kadd) write byte-identical index files for L2/IP with 4 bits and L2 with 1 and 9 bits.Benchmarks
Single thread, pinned to one idle core and its NUMA node (
numactl --physcpubind=20 --membind=0). Baseline (main0734ec2) and candidate runs were alternated, 6–10 pairs per row. Removing an HNSW member shifts later field offsets, so object code cannot be compared directly; these runs check performance instead.Ratio is candidate/baseline (median).
exact_assign262144×128, k=1024exact_assign65536×960, k=1024rabitq_core_benchmark128 dims, 4 and 9 bits: all operationsEvery result is within this host's noise (single-pair ratios vary by about ±5–10%), and no speedup is claimed. Shared host: load average 3–11 during the runs; CPU frequency was not locked.
Not run locally: NEON, Windows and macOS builds.