Skip to content

Migrate from SimSIMD to NumKong - #128293

Draft
thevar1able wants to merge 4 commits into
masterfrom
migrate-to-numkong
Draft

thevar1able wants to merge 4 commits into
masterfrom
migrate-to-numkong

Conversation

@thevar1able

@thevar1able thevar1able commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

SimSIMD was renamed to NumKong upstream, and usearch v2.25+ depends on NumKong instead of SimSIMD. This PR migrates both.

  • contrib/SimSIMD (ClickHouse fork at v6.5.15) is replaced by upstream NumKong v7.8.6, unpatched. Our fork's patches are covered upstream: MSan unpoisoning of dispatch results, unistd.h for ARM capability detection, and the data race on lazy dispatch initialization (the dispatch table is now filled by a load-time constructor).
  • usearch is bumped from v2.24.0 to v2.26.6. The ClickHouse patches are carried on the ClickHouse/v2.26.6 branch of the fork (Carry the ClickHouse patches from v2.24.0 onto v2.26.6 usearch#15), plus a fix to count the new striped locks in memory_usage, which the vector similarity index cache uses as the entry weight (Account for the striped locks in index_gt::memory_usage usearch#16). usearch no longer uses FP16, so contrib/FP16 is removed.
  • contrib/NumKong-cmake builds the dynamic-dispatch library. It enables the instruction sets explicitly: without that, NumKong compiles only the baseline ISA. SVE stays disabled, as before, because MemorySanitizer cannot instrument it. AMX, SME, AVX10.2 and NEON FP8 are also disabled (matrix-only kernels, or not supported by the minimum Clang). Genoa (AVX-512 BF16) is disabled because its bf16 L2 kernel computes a² + b² − 2ab in f32 and cancels catastrophically; bf16 uses the Haswell kernels instead, which subtract first.
  • distanceTransposed is ported to the nk_* API. NumKong kernels write the result in a type that depends on the input (f64 for Float32/Float64, f32 for BFloat16 and the Int8 L2/cosine, i32 for the Int8 dot product), so it is converted to Float64. As a result, the last digits of some BFloat16 and Int8 distances may differ.
  • USE_SIMSIMD / ch_contrib::simsimd are renamed to USE_NUMKONG / ch_contrib::numkong.

Related: ClickHouse/usearch#15
Related: ClickHouse/usearch#16

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Replace SimSIMD with NumKong 7.8.6 and update usearch to 2.26.6.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/128293]

thevar1able and others added 2 commits October 30, 2026 22:51
`SimSIMD` was renamed to `NumKong` upstream. Replace `contrib/SimSIMD` (the
ClickHouse fork at v6.5.15) with upstream `NumKong` v7.8.6, unpatched: the
fork's patches (MSan unpoisoning, `unistd.h` for ARM capability detection,
data race on lazy dispatch initialization) are covered upstream, where the
dispatch table is filled by a load-time constructor.

Bump `usearch` to v2.26.6, which uses `NumKong` instead of `SimSIMD` and no
longer needs `FP16`, so `contrib/FP16` is removed. The ClickHouse patches are
carried in ClickHouse/usearch#15.

`NumKong` with dynamic dispatch compiles kernels only for the instruction sets
enabled explicitly, so `contrib/NumKong-cmake` lists them. SVE stays disabled
because MemorySanitizer cannot instrument it.

Port `distanceTransposed` to the `nk_*` API. `NumKong` kernels write the result
in a type that depends on the input type (`f64`, `f32` or `i32`), so it is
converted to `Float64`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a7c456b]

Summary: ❌

job_name test_name status info comment
Build (amd_msan) FAIL
Relocation headroom FAIL cidb
Build (amd_release) FAIL
Build ClickHouse FAIL cidb
Build (arm_release) FAIL
Build ClickHouse FAIL cidb
python3 ./ci/jobs/scripts/job_hooks/build_profile_hook.py FAIL
Build (amd_musl) FAIL
Build ClickHouse FAIL cidb
Docker server image DROPPED
Docker keeper image DROPPED
Install packages (amd_release, deb) DROPPED
Install packages (amd_release, rpm) DROPPED
Install packages (amd_release, tgz) DROPPED
Install packages (arm_release, deb) DROPPED

AI Review

Summary

Replaces SimSIMD with NumKong, upgrades usearch, and adapts the transposed-distance dispatch. The earlier BF16 cancellation and striped-lock accounting findings are fixed. One new resource regression remains in vector-index thread reservation.

Findings

⚠️ Majors

  • contrib/usearch:1: The new index_dense_gt::make reserves the host's hardware thread count, while ClickHouse's unchanged constructor omits initial limits. Reservations now retain the maximum count, so subsequent quota-aware build/load limits cannot reduce it. On a 192-thread host with a two-CPU quota, loaded granules retain 192 slots instead of four, allocating 8,388,736 striped-lock bytes instead of 131,200 at default connectivity. Pass explicit, small nonzero initial limits to make; unreserved alone still selects hardware defaults during loading. A standalone probe confirms that reserving one thread retains one slot before the upgrade and two after it on a two-thread host; explicit construction limits restore one.
Tests
  • ⚠️ Verify index building and loading when configured CPU/thread limits are below the host count. Both paths must retain the intended reservation after construction and deserialization.
Final Verdict

Status: ⚠️ Request changes. Adapt vector-index construction to preserve ClickHouse's configured thread limits and verify both build and load reservations.

@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR. labels Oct 30, 2026
Comment thread contrib/NumKong-cmake/CMakeLists.txt Resolved
Comment thread contrib/usearch Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. label Oct 30, 2026
The Genoa (AVX-512 BF16) `bf16` squared Euclidean distance computes
`a^2 + b^2 - 2ab` in `f32`, which cancels catastrophically for close vectors
(`[32768, 1]` and `[32768, 2]` give 0 instead of 1) and overflows to NaN for
identical vectors with huge components. Without it, `bf16` falls back to the
Haswell kernels, which subtract before squaring, as `SimSIMD` did.

Also fix the clang-tidy errors in `distanceTransposed`:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128293&sha=837a64c18aebe7ecfbb49f78bbdc822890e8a223&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29

#128293

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`striped_locks_gt`, new in `usearch` v2.26, was not included in
`index_gt::memory_usage`, which the vector similarity index cache uses as the
entry weight: about 4 MiB per index on a 64-core server.

ClickHouse/usearch#16

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread contrib/usearch
@@ -1 +1 @@
Subproject commit 6bd13d4c69a1baef1f668e652c3ca26028970f12
Subproject commit 78b5cbf5df91ff2aa7a07f5b732996acd8a00f8d

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve ClickHouse's thread limits when constructing indexes

The new index_dense_gt::make reserves hardware_concurrency() threads by default, but USearchIndexWithSerialization still calls make(metric, config) without initial limits at src/Storages/MergeTree/MergeTreeIndexVectorSimilarity.cpp:130. Both reservation layers now retain the maximum thread count, so the later builder reservation using max_build_vector_similarity_index_thread_pool_size and loader reservation using 2 * getNumberOfCPUCoresToUse cannot reduce it.

On a 192-thread host with a two-CPU container quota, loaded indexes therefore retain 192 thread slots instead of four. With the default connectivity, their striped locks alone consume 8,388,736 bytes per granule instead of 131,200, reducing the number of small parts fitting in the cache and increasing index-loading allocations. A standalone probe on this two-thread host confirms the change: after reserving one thread, the old revision retains one slot and the new revision retains two; supplying the initial limit to make restores one.

Please adapt the caller to pass explicit, small nonzero initial thread limits through the new fourth argument, allowing the existing build/load reservations to grow them. Using unreserved alone does not cover loading: load_from_stream replaces zero thread counts with hardware defaults. Verify both build and load paths with the configured CPU/thread count below the host count.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant