Top level¶
Module-level helpers, re-exported from the compiled core.
ann_search
¶
Vector search for single-cell and computational biology, in Rust.
Every index is a scikit-learn style estimator: parameters go in the
constructor, data goes into fit, results come out of kneighbors.
>>> import numpy as np, ann_search as ann
>>> X = np.random.default_rng(0).standard_normal((5000, 50)).astype("float32")
>>> index = ann.HnswIndex(n_neighbors=15, metric="cosine").fit(X)
>>> distances, indices = index.kneighbors() # self-kNN, fast path
>>> distances, indices = index.kneighbors(X[:100]) # cross-set
kneighbors returns distances first, matching scikit-learn and FAISS. A query
that came back with fewer than k neighbours is padded with -1 indices
and infinite distances, and kneighbors_graph drops those slots.
Indices are immutable. There's no incremental add, so rebuild instead.
AnnSearchError
¶
Bases: Exception
Base class for every error raised by the Rust core.
IndexIoError
¶
Bases: AnnSearchError
An index bundle is missing, truncated, or of the wrong kind or dtype.
gpu_available
builtin
¶
Whether the GPU indices can be used here.
Returns¶
True only when this build has the gpu feature and wgpu resolves an
adapter. Safe to call on any machine.
Note¶
Acquiring a client panics rather than erroring when no adapter is found, so
the probe catches it. That is sound here because the release profile is
pinned to panic = "unwind", which pyo3 requires anyway. The panic hook is
silenced for the duration, otherwise merely asking the question prints a
backtrace to stderr.
num_threads
builtin
¶
Number of threads currently available for index builds and queries.
Returns¶
The configured pool's size, or rayon's global pool size when no override is in place.
set_num_threads
builtin
¶
Set the number of threads used for index builds and queries.
Rayon worker threads do not survive fork, so a multiprocessing child
using the default fork start method on Linux will hang if it touches the
pool. Use the spawn start method there.
Params¶
n- Thread count.0clears the override and returns to rayon's global pool, which honoursRAYON_NUM_THREADS.
Returns¶
Nothing, or a RuntimeError if the pool could not be built.