Repository navigation
Fix: replace identity hash with SplitMix64 for sequential integer keys - #773
Merged
ashvardanian merged 1 commit intoJul 10, 2026
Merged
ashvardanian merged 1 commit into
ashvardanian merged 1 commit into
Conversation
`std::hash` is the identity for integers on libstdc++ and libc++. Our open-addressing
tables mask that hash into a power-of-2 slot count and probe linearly until an empty
slot, so consecutive keys land in adjacent slots and coalesce into a single contiguous
run. Insertions and lookups both scan that run end to end, making the whole build
quadratic.
Measured on `flat_hash_multi_set_gt` at 200k keys, insert plus lookup, in millions of
keys per second:
key pattern identity splitmix64
dense ascending 0.01 19.90
2^40 + 4096k 0.31 16.10
9k+7 54.66 20.71
random u64 22.72 20.43
Note the collapse needs keys that are adjacent, not merely sequential: with an odd
stride every key already gets its own slot, and the identity hash wins there on cache
locality. Mixing costs ~20ns per key, which the graph traversal in `add` dwarfs.
Member
|
Thank you, @chakshu-dhannawat! Sorry it took a bit of time. I'm finalising new NumKong/StringZilla/ForkUnion releases to feed into USearch v3 🤗 |
ashvardanian
pushed a commit
that referenced
this pull request
Jul 10, 2026
### Minor - Add: Expose `stats()` in Rust SDK (#768) (3713af9) - Add: Rust compact binding (#771) (749d03b) ### Patch - Make: Modernize CI toolchains, pin cibuildwheel (017fad3) - Fix: Reclaim `slot_lookup_` tombstones under churn (#769) (c6d634c) - Fix: Mix integer key hashes with SplitMix64 (#773) (9fc3500) - Make: Build JavaScript Windows x64 prebuilds (#774) (7240652) - Make: Bundle NumKong runtime with C# native artifacts (9c0ed29)
titusz
pushed a commit
to iscc/usearch
that referenced
this pull request
Aug 3, 2026
`std::hash` is the identity for integers on libstdc++ and libc++. Our open-addressing tables mask that hash into a power-of-2 slot count and probe linearly until an empty slot, so consecutive keys land in adjacent slots and coalesce into a single contiguous run. Insertions and lookups both scan that run end to end, making the whole build quadratic. Closes unum-cloud#770. Co-Authored-By: Chakshu Dhannawat <[email protected]> Co-Authored-By: Ash Vardanian <[email protected]> (cherry picked from commit 9fc3500)
titusz
added a commit
to iscc/usearch
that referenced
this pull request
Aug 3, 2026
…() fixes Cherry-picks from upstream unum-cloud/usearch: - Mix integer key hashes with SplitMix64 (unum-cloud#773) - Bounded probe in equal_iterator_gt::operator++ - Preserve hash lookup capacity across thread reserves (unum-cloud#765) - Keep vectors_lookup_ capacity after clear() (unum-cloud#759) - Reclaim slot_lookup_ tombstones under churn (unum-cloud#769) Fork fixes: - Rebuild key lookups after compact(), preserve the nodes buffer capacity, and abort cleanly on progress cancellation (#9)
swasik
added a commit
to swasik/vector-store
that referenced
this pull request
Oct 13, 2026
…ulating in f32 usearch 2.25+ takes its distance kernels from NumKong instead of simsimd. Stock NumKong 7.8.5 costs 22% of the searches per second on Graviton4 and 44% of the index build time: every f32 kernel widens each lane to f64 before the multiply-add (ashvardanian/NumKong#392). With the opt-in f32 accumulation and a two-chain SVE kernel (ashvardanian/NumKong#393, pinned from a fork through [patch.crates-io] until NumKong ships it) the new usearch beats 2.22.0 by 2-5% on F32 and runs F16 and BF16 6-7x faster than today's release, whose simsimd probe falls back to serial kernels on Linux ARM (VECTOR-1027). The upgrade also ends search stalls during row deletions. usearch 2.22.0 finds keys through a table with an identity hash and linear probing, so Vector Store's dense, ascending keys form one long run, and remove() walks it from the key's slot to its end while Vector Store runs the remove with no search in flight. On a 136M-row index that is ~0.31 s per delete, and 2 deletes/s put half of the searches over 100 ms. With 2.26.4 (SplitMix64 key hash, unum-cloud/USearch#773) the same deletes leave search latency unchanged. numkong's aarch64 kernels need gcc >= 13 or clang. The release toolchain image is now derived from rust:<channel>-bookworm with clang 19 for arm64 (scripts/release-toolchain.Dockerfile, built on first use by run-with-release-toolchain), which keeps bookworm's glibc floor; amd64 keeps gcc 12, which builds the crates as they are. numkong's SME targets are off: clang's SME kernels need compiler-rt's __arm_get_current_vg, which the gcc link does not provide, and no machine we ship to has SME. The `-include unistd.h` entry that scylladb#633 put in .cargo/config.toml goes: it fixed the capability probe of usearch 2.22.0's simsimd, which numkong replaces, and numkong's probe includes the header itself. Refs: VECTOR-720 Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
swasik
added a commit
to swasik/vector-store
that referenced
this pull request
Oct 14, 2026
…ulating in f32 usearch 2.25+ takes its distance kernels from NumKong instead of simsimd. Stock NumKong 7.8.5 costs 22% of the searches per second on Graviton4 and 44% of the index build time: every f32 kernel widens each lane to f64 before the multiply-add (ashvardanian/NumKong#392). With the opt-in f32 accumulation and a two-chain SVE kernel (ashvardanian/NumKong#393, pinned from the scylladb/NumKong fork through [patch.crates-io] until NumKong ships it) the new usearch beats 2.22.0 by 2-5% on F32 and runs F16 and BF16 6-7x faster than today's release, whose simsimd probe falls back to serial kernels on Linux ARM (VECTOR-1027). The upgrade also ends search stalls during row deletions. usearch 2.22.0 finds keys through a table with an identity hash and linear probing, so Vector Store's dense, ascending keys form one long run, and remove() walks it from the key's slot to its end while Vector Store runs the remove with no search in flight. On a 136M-row index that is ~0.31 s per delete, and 2 deletes/s put half of the searches over 100 ms. With 2.26.4 (SplitMix64 key hash, unum-cloud/USearch#773) the same deletes leave search latency unchanged. numkong's aarch64 kernels need gcc >= 13 or clang. The release toolchain image is now derived from rust:<channel>-bookworm with clang 19 for arm64 (scripts/release-toolchain.Dockerfile, built on first use by run-with-release-toolchain), which keeps bookworm's glibc floor; amd64 keeps gcc 12, which builds the crates as they are. numkong's SME targets are off: clang's SME kernels need compiler-rt's __arm_get_current_vg, which the gcc link does not provide, and no machine we ship to has SME. The `-include unistd.h` entry that scylladb#633 put in .cargo/config.toml goes: it fixed the capability probe of usearch 2.22.0's simsimd, which numkong replaces, and numkong's probe includes the header itself. Refs: VECTOR-720 Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
ewienik
added a commit
to ewienik/vector-store
that referenced
this pull request
Oct 14, 2026
…ulating in f32 (scylladb#634) ## Motivation usearch 2.22.0 → 2.26.4 (VECTOR-720). From 2.25 usearch takes its distance kernels from [NumKong](https://github.com/ashvardanian/NumKong) instead of simsimd. Stock NumKong 7.8.5 costs 22% of the searches per second on Graviton4 and 44% of the index build time, because every f32 kernel widens each lane to f64 before the multiply-add (ashvardanian/NumKong#392). With f32 accumulation and the SVE kernel unrolled into two FMA chains (ashvardanian/NumKong#393) the new usearch beats 2.22.0 on F32 and runs F16/BF16 6–7× faster than today's release, which executes simsimd's serial kernels for every non-f32 quantization on Linux ARM (VECTOR-1027, scylladb#633). The upgrade also fixes search stalls during row deletions, reported from production (details on VECTOR-720). usearch 2.22.0's `index_dense` finds keys through a table with an identity hash and power-of-two linear probing, so Vector Store's dense, ascending keys form one long run of slots, and `remove()` walks that run from the key's slot to its end. Vector Store runs every remove exclusively (`mod operation` in `vs_index/usearch.rs`), so searches on the index wait for the scan: on a 136M-row index one delete costs ~0.31 s with the node at 2–3% CPU, and 2 deletes/s already put half of the searches over 100 ms. usearch 2.26 hashes the keys with SplitMix64 (unum-cloud/USearch#773, for unum-cloud/USearch#770), and the stall is gone (see "Deletes" below). This part does not depend on numkong. ## What it does - `usearch = "2.26.4"`; numkong pinned through `[patch.crates-io]` to the commit of ashvardanian/NumKong#393, the `f32-accumulate-angular-f32` branch of the `scylladb/NumKong` fork, which adds the opt-in `NK_ACCUMULATE_F32_IN_F64=0`. The fork lets us ship the faster kernels now instead of waiting for a NumKong release with the option; a NumKong release replaces the pin once one ships it. - `.cargo/config.toml` `[env]`: `CFLAGS_aarch64_unknown_linux_gnu=-DNK_ACCUMULATE_F32_IN_F64=0`, and numkong's SME targets off: no machine we ship to has SME, and clang's SME code needs compiler-rt's `__arm_get_current_vg`, which the gcc link does not provide. - Release toolchain: numkong's aarch64 kernels need gcc ≥ 13 or clang, `rust:<channel>-bookworm` has gcc 12, and a trixie image would produce binaries needing glibc 2.39 (the `ubi9-minimal` runtime image has 2.34). `scripts/release-toolchain.Dockerfile` derives the toolchain image from the bookworm one and installs clang 19 from apt.llvm.org for arm64 only; `run-with-release-toolchain` builds it on first use (cached afterwards). The amd64 build keeps gcc 12, which compiles usearch 2.26.4 and numkong as they are. CONTRIBUTING says so in one sentence. - `.cargo/config.toml` loses the `CXXFLAGS_aarch64_unknown_linux_gnu = "-include unistd.h"` entry from scylladb#633: it fixed the capability probe of usearch 2.22.0's simsimd, which numkong replaces, and numkong's probe includes the header itself. No Rust code changes: the usearch API we use is unchanged between 2.22.0 and 2.26.4. ## Measurements AWS `r8g.4xlarge` Vector Store (Graviton4, 16 threads), `i8g.2xlarge` Scylla, cohere-1m (768-d, cosine), M=16, ef=64, k=10, HTTP searches, ABBA repeats with a 150 s warm-up, CV ≤ 2.2%; the full report with the comparison ids is on VECTOR-720. | Build | F32 c64 QPS | F32 c128 QPS | F32 index build | F16 c64 QPS | BF16 c64 QPS | |---|---|---|---|---|---| | A: usearch 2.22.0, release toolchain (master 315f61d) | 22090 | 22257 | 86 s | 3.3k (serial kernel, index 696 s) | not measured (serial kernel, as F16) | | B: usearch 2.26.4, stock numkong 7.8.5 | 16427 | — | 123 s | — | — | | C: usearch 2.26.4 without numkong (usearch's own kernels) | 22204 | 22189 | 84 s | 7.5–8.4k (index 269 s) | 22187 [21023–23350] (index 78 s) | | D2: this PR's kernels (f32 accumulation, two SVE chains; gcc 14 build) | 23051 | 23145 | 81 s | 20.3–22.9k (D build, index 84 s) | 26068 [24488–27647] (D build, stock `nk_angular_bf16_*`, index 61 s; CQL 25424 at 93.2% recall) | | A + scylladb#633 (SVE detected, simsimd f16 accumulates in f16) | — | — | — | 28.2–28.5k at 92.5% recall | 23307 [22604–24010] (index 63 s; CQL 23981 at 93.7%) | CQL recall at c64: A 93.8%, C 93.4%, D 93.5% (F32); D 93.6% (F16). I8 (`'quantization': 'I8'`, HTTP c64): D 29.7–35.9k (index 46 s, CQL recall 85.9%), A + scylladb#633 28.6–33.6k (index 43 s, recall 86.1%): equal within the client's noise (every I8 run is latency-floored at 30k+ QPS). I8 recall is 86% on both builds against 93.5% for F32: the quantization, not the kernels. ### Deletes (136M rows) AWS: 3 × `i8g.2xlarge` Scylla 2026.2.6 (RF=3) and 2 × `r8g.8xlarge` Vector Store (32 threads). The table held 136M random 768-d rows in one global I8 cosine index, built by a full scan. 40 inserts/s and ~3 CQL searches/s ran in the background, and DELETEs by full primary key ran at fixed rates (`delete-ids`, scylladb/vector-store-bench#22). The two builds ran side by side, one per Vector Store node: release 1.11.0 (usearch 2.22.0) and 1.11.0 + usearch 2.26.4 with stock numkong 7.8.5 (build B above). That covers this PR as well, because the delete path does not touch numkong and I8 uses numkong's stock kernels here too. Latency is the server-side `request_latency_seconds`, over one 5-minute window per rate. | Deletes | 2.22.0 p50 / p99 | 2.22.0 searches > 100 ms | 2.26.4 p50 / p99 | |---|---|---|---| | none | 1.1 / 4.7 ms | 0% | 0.9 / 4.3 ms | | 1/s | 1.6 / 484 ms | 11% | 0.9 / 4.3 ms | | 2/s | 91 / 880 ms | 49% | 0.9 / 4.4 ms | | 5/s | 279 / 1270 ms | 80% | 0.9 / 4.3 ms | | 8/s | 305 / ~1000 ms | 81% | 0.9 / 4.6 ms | | 50/s for 60 s | 479 / 1420 ms | 86% | 0.9 / 4.5 ms | | 8/s of rows inserted after the build | 1.5 / 4.9 ms | 0% | 0.9 / 4.7 ms | - With 2.22.0 a node applies at most ~3.2 deletes/s at this size. Faster deletes queue, and the inserts queue behind them: the node needed 8.5 min to catch up after 2,400 deletes at 8/s and 15.5 min after 3,000 at 50/s, with p99 ~1 s throughout. Deleting rows inserted after the full-scan build costs nothing, because their keys sit at the end of the run. - The full-scan build of the 136M-row I8 index ran at 12.4k rows/s with 2.26.4 and 9.0k with 2.22.0 (3 h 03 min vs 4 h 09 min). Release 1.11.0 predates scylladb#633, so part of that gap may be its serial I8 kernels. ## How it was tested - `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -Dwarnings`, `cargo test --workspace` on the host (gcc 15); `cargo deny check sources` passes (`deny.toml` allows git sources from the scylladb organization; the only warning is the pre-existing axum-server-dual-protocol one). - After the rebase onto master `37913e4` (2026-10-13, scylladb#633 merged): `cargo fmt --all -- --check`, `cargo clippy --locked --all-targets` with `-Dwarnings`, `cargo test --locked -p vector-store --lib` (344 passed) and `cargo deny check sources` pass again on the host. - amd64: `TARGETARCH=amd64 ./scripts/run-with-release-toolchain cargo build --release --bin vector-store -p vector-store` builds the derived image and the binary (gcc 12). - arm64: a cross build of this tree with clang 19 (the same apt.llvm.org packages, from an x86 host) passed the benchmark skill's verify gate: aarch64, GLIBC ≤ 2.34, `--version` under qemu, SVE kernels present. The arm64 derived image itself was not built here (no arm64 binfmt on the build host), so the first CI run of `build-vector-store.yml` on arm64 is the test of that path. The clang-built arm64 binary from this tree, ABBA against today's release on the same cluster (`20261008T214941Z-ab-2923`, HTTP c64, 240 s settle after each switch): 20079 [19965–20193] vs 20285 [20238–20332] QPS (−1.0%, CV ≤ 0.8%), index build 86.5 s vs 88.0 s, CQL recall 93.4%. Parity, not the +4.6% of the gcc 14 build of the same source: clang's code for the two-chain SVE kernel costs per distance what simsimd's NEON kernel costs (68% of the profile in both), gcc 14's costs less. The upgrade meets "at least as good" with this toolchain; the missing 4.6% is listed below. ## Before this leaves draft - The arm64 kernel codegen: clang 19 gives parity with 2.22.0 where gcc 14 gave +4.6% (same source). Either a gcc ≥ 13 toolchain for the arm64 release, which means a runtime image with glibc ≥ 2.39 (ubi10) because bookworm stops at gcc 12, or a kernel shaped so that clang produces gcc's code. - x86_64 is not covered: numkong's `nk_angular_f32_haswell/skylake` widen to f64 as well (the fork patches NEON and SVE only), so amd64 may carry B's regression. Needs its own measurement and, if confirmed, the same option in those kernels. Fixes: VECTOR-720 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xet7
pushed a commit
to xet7/usearch
that referenced
this pull request
Nov 12, 2026
The 2.x line released v2.25.2 through v2.26.6 after 3.0 branched at v2.25.1, and its public main ends at 33d3ab6. Installs place headers under GNUInstallDirs' include directory (14f9807, unum-cloud#800), the README lists the integrations 2.x added (0fd2f32, unum-cloud#795), and CONTRIBUTING states the commit conventions in place of stale links (06ad060, unum-cloud#748). Its correctness fixes already hold on 3.0's code: - Keys move with their entries when `compact` permutes slots (0a4baa6, unum-cloud#795), and the insert-only key table never rehashes (1633e25, unum-cloud#822; 9d77be5, unum-cloud#759) - File loads bound every column slice from the header (9c25176, unum-cloud#824; 64d10d8, unum-cloud#776), and allocation sizes are checked (89da7c5, unum-cloud#763) - JavaScript keys are range-checked (b65a420, unum-cloud#812), Go filters ride `cgo.Handle`s (ad77fe7, unum-cloud#825), `splitmix64_t` survives `windows.h` (0f1c5f2, unum-cloud#806), and integer key hashes mix with SplitMix64 (9fc3500, unum-cloud#773) - C install targets and relocatable pkg-config (4160e47, 679e190, unum-cloud#800), the GIL released in long calls (d8be67d, unum-cloud#764), and graph cursors in C and Rust (55c43f7, unum-cloud#748) Thread-context reserves, tombstones, renames, `change_metric`, OpenMP metrics and hand-written BF16 casts are absent from 3.0, so their fixes have nothing to land on. The Rust `compact()` binding (749d03b, unum-cloud#771) waits for all bindings to wrap `usearch_dense_compact`. The README's performance lead now quotes the SIFT 100M rows at 99% recall on a B300 and on 192 Graviton5 cores beside FAISS HNSW, and the verification notes link ForkUnion's `main`. The sibling pins move to the libraries' own merges with their released lines, so this line builds against them. Co-Authored-By: Jonathan Ringer <[email protected]>
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.
Fixes #770.
What
std::hash<uint64_t>is the identity function on libstdc++ and libc++. With the power-of-2 open-addressing table and linear probing inflat_hash_multi_set_gt, ascending integer keys (database row ids, auto-increment entity ids) produce contiguous probe clusters. The issue reporter measured a 90x throughput collapse on 112M-vector indexes.include/usearch/index.hpp- Addhash_gtspecializations forstd::uint64_tandstd::int64_tthat apply the SplitMix64 bit-mixer finalizer. Overhead is about 2 ns per lookup. No API or on-disk format change.rust/lib.rs+rust/lib.cpp- Exposeenable_key_lookupsthrough the Rust cxx bridgeIndexOptions. Previously the field was unreachable from Rust, so all Rust callers (includingview()/load()) always paid the fullreindex_keys_()rebuild cost even for add/search-only workloads.Why SplitMix64
It is the standard bit-mixer for this exact problem (sequential integer keys into power-of-2 hash tables), used in Abseil's hash map and referenced by the issue author. Three multiplications and three XOR-shifts, constant time, no state.
Backward compatibility
enable_key_lookupsdefaults totrue, matching the previous behavior. Callers that never useget/remove/contains/renamecan now set it tofalseto skip the per-startupreindex_keys_()rebuild.