Expand description
Rust bindings for scann-core, the TensorFlow- and Python-independent core of ScaNN.
Two types do the work:
ConfigBuilderturns high-level options into a ScaNN config, likescann.scann_ops_pybind.builder(...)in Python (it is the same builder ported to C++; seecore/scann_core/config_builder.h).ScannIndexis a built, searchable, mutable index.
use scann_core::{AhOptions, ConfigBuilder, DistanceMeasure, ReorderOptions,
SearchOptions, TreeOptions};
let dim = 128;
let dataset: Vec<f32> = vec![0.0; 10_000 * dim]; // row-major, n x dim
let index = ConfigBuilder::new(10, DistanceMeasure::DotProduct, dim)
.tree(TreeOptions::new(100, 10))
.score_ah(AhOptions::new(2).anisotropic_quantization_threshold(0.2))
.reorder(ReorderOptions::new(100))
.build_index(&dataset)?;
let neighbors = index.search(&dataset[..dim], SearchOptions::default())?;
println!("{:?}", neighbors.indices);Distances are reported the way the Python API reports them: dot product
as the (positive) inner product, squared L2 as the squared distance (also
through ConfigBuilder::l2_as_dot_product).
Structs§
- AhOptions
- Python:
ScannBuilder.score_ah(): asymmetric-hashing (product quantization) scoring. - Autopilot
Options - Options for
ConfigBuilder::autopilot_with(Python:autopilot()). - Config
Builder - Builds a ScaNN config from high-level options, like Python’s
scann_ops_pybind.builder(db, num_neighbors, distance_measure). - Health
Stats SingleMachineSearcherBase::HealthStats.- L2As
DotProduct Options - Python:
ScannBuilder.l2_as_dot_product(): squared L2 search through an inner-product index (the exact L2 -> MIPS reduction). The index stores each datapointxas[x, (center - |x|²) / (2 scale)]and searches[q, scale]by dot product; results are squared L2 distances, and upserts, rebalancing and saved indexes keepscaleandcenter. SeeConfigBuilder::l2_as_dot_product. - Neighbors
- Nearest neighbours of one query, best first.
- PcaOptions
- Python:
ScannBuilder.pca(). Set at most one ofreduction_dimandpca_significance_threshold; with neither, the threshold is 0.8. - Reorder
Options - Python:
ScannBuilder.reorder(): rescore the top candidates exactly (or with a finer quantization). - Scann
Index - A built ScaNN index (
research_scann::ScannInterface). - Search
Options - Per-query search overrides.
Noneuses the value from the config the index was built with (Python: passingNone). - Tree
Options - Python:
ScannBuilder.tree(). Defaults match Python’s. - Upper
Tree Options - Python:
ScannBuilder.upper_tree(): a second partitioning level above the tree. RequiresConfigBuilder::tree.
Enums§
- Autopilot
Rules - Which rules
ConfigBuilder::autopilot_withchooses the configuration with (Python:autopilot(rules=...)). - Distance
Measure - Hash
Type - Incremental
Mode - Python:
scann_builder.IncrementalMode. - Incremental
Threshold - When a partition has grown enough to be retrained in place (Python’s
incremental_threshold: an int is a point count, a float a fraction). - Quantization
- How vectors are stored for scoring (Python:
scann.ReorderType). - Scann
Error - Error from scann-core, or from argument validation in these bindings.