Skip to content

Hardened Allocators, Py 3.15, Go Handles - #825

Merged
ashvardanian merged 12 commits into
mainfrom
main-dev
Oct 25, 2026
Merged

ashvardanian merged 12 commits into
mainfrom
main-dev

Conversation

@ashvardanian

Copy link
Copy Markdown
Member

No description provided.

ashvardanian and others added 12 commits October 19, 2026 00:42
Use cgo handles for captured callbacks and heap-backed user data.

Closes #799

Co-authored-by: Penghao Jiang <[email protected]>
Build Python 3.15 and 3.15t wheels with a 3.11 minimum, and smoke-test
installed wheels. Use the trusted-publishing policy owner's NuGet
username and fast-forward main-dev after releases.

Closes #798
Closes #767

Co-authored-by: Clémence Lesné <[email protected]>
Co-authored-by: Shaan Nobee <[email protected]>
Explain per-call workers and thread limits when running multiple
indexes concurrently.

Closes #747

Co-authored-by: Roland Faure <[email protected]>
`usearch_exact_search` built an executor from its `threads` argument
but never passed it to `exact_search_t`, so the C API always searched
on a single thread. Pass it through, and check in `test_find_vector`
that exact search returns the same closest vectors on one and four
threads.
`load` and `view` took the graph header's `entry_slot` and `max_level`
without checks. A correctly sized file with a corrupted header was
accepted, and the first search read past the stored nodes and crashed.

Both paths now reject a non-empty file when `entry_slot` is not below
the node count, or when `max_level` exceeds the entry node's level.
`view` resets before failing, as for the other size checks. The test of
truncated files now also corrupts each field and expects `load` and
`view` to fail cleanly.
`normalizeKeys` only range-checked keys passed inside an array. A single
`number` or any `bigint` went straight into `BigUint64Array.of(...)`,
which wraps modulo 2^64. As a result `index.add(-1, ...)` stored the
vector under 2^64 - 1, `index.add(2n ** 64n, ...)` stored it under 0, and
`index.remove(-1)` deleted whatever was stored under 2^64 - 1.

Check that every key, whether scalar or inside an array, is an integer
within [0, 2^64) and throw otherwise, like the array path already did for
negative numbers. Non-integer numbers now throw the same error instead of
a bare `RangeError` from `BigInt()`.
`normalizeVectors` summed `vec.length` over the rows of a nested array
without looking at what the rows are. A flat `number[]` has no `.length`
on its elements, so the total became NaN, `new Float32Array(NaN)` was
empty and `index.search([1, 0, 0], 2)` quietly returned an empty batch,
while `index.add(8n, [0, 0, 1])` failed with a misleading "length of keys
(1) must match the number of vectors (0)". Ragged input such as
`[[1, 0], [0, 0, 0, 1]]` was glued into two 3-dimensional vectors because
only the total size was checked.

Require every row to be an array or a typed array with exactly
`dimensions` elements. A flat array of numbers now throws the existing
"Vectors must be a TypedArray or an array of arrays." error.
The key-to-slot lookup and the free-slot ring allocated through
`std::allocator`, which throws inside their `noexcept` reserve paths, so
running out of memory terminated the process. Tombstones count toward the
load factor, so ordinary remove and add churn on a reserved index could
trigger that rehash.

Both now use `aligned_allocator_gt`, which returns `nullptr` like every
other buffer in `index_dense_gt`. When the rehash fails, `try_emplace`
still places the element in a free or deleted slot, `add` reports a failed
key mapping instead of ignoring it, and `load`, `view` and `compact`
report a failed reindex. A failed copy assignment of the lookup now leaves
an empty table instead of stale counts over a released buffer.
The server image installed `ucall` and `usearch` into Ubuntu's system
Python with `--break-system-packages`. It now creates a `venv`,
upgrades its pip to pick up a current certificate bundle, and installs both
packages there.
`Match.distance` is a distance for every built-in metric. The README.md
now gives the `cos`, `ip` and `l2sq` formulas, and where `ip` departs
from `cos`.

Closes #668

Co-authored-by: Aditya Menon <[email protected]>
Both native search entry points returned `py::tuple(5)` for a zero
`count`, a tuple of null slots that crashed the interpreter once the
wrapper unpacked it. They now raise `std::invalid_argument`, which
pybind11 turns into a `ValueError`. Negative counts already fail the
unsigned conversion in pybind11.
NumKong 7.8.4 fixed its SME kernels failing to compile with GCC 16 on
AArch64, and 7.8.6 stopped its macOS wheels importing `__sme_memset`,
which libSystem only provides from macOS 15. USearch still accepted
NumKong 7.5.0, so stale environments and lockfiles kept either bug.

Require 7.8.6 at runtime in `setup.py`, at build time in
`pyproject.toml`, and in `Cargo.toml` and `Package.swift`, and move the
`numkong` submodule, which the C, C++ and JavaScript builds compile
from, to v7.8.6.
@ashvardanian
ashvardanian merged commit 343dc7b into main Oct 25, 2026
10 of 11 checks passed
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 branch was successfully deployed

3 active deployments
github-pages — 343dc7bb Deployed Oct 25, 2026 by ashvardanian via Deploy GitHub Pages #292
pypi — 343dc7bb Deployed Oct 25, 2026 by ashvardanian via Publish Python #292
nuget — 343dc7bb Deployed Oct 25, 2026 by ashvardanian via Publish C# #292
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants