Skip to main content

Crate scann_core

Crate scann_core 

Source
Expand description

Rust bindings for scann-core, the TensorFlow- and Python-independent core of ScaNN.

Two types do the work:

  • ConfigBuilder turns high-level options into a ScaNN config, like scann.scann_ops_pybind.builder(...) in Python (it is the same builder ported to C++; see core/scann_core/config_builder.h).
  • ScannIndex is 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.
AutopilotOptions
Options for ConfigBuilder::autopilot_with (Python: autopilot()).
ConfigBuilder
Builds a ScaNN config from high-level options, like Python’s scann_ops_pybind.builder(db, num_neighbors, distance_measure).
HealthStats
SingleMachineSearcherBase::HealthStats.
L2AsDotProductOptions
Python: ScannBuilder.l2_as_dot_product(): squared L2 search through an inner-product index (the exact L2 -> MIPS reduction). The index stores each datapoint x as [x, (center - |x|²) / (2 scale)] and searches [q, scale] by dot product; results are squared L2 distances, and upserts, rebalancing and saved indexes keep scale and center. See ConfigBuilder::l2_as_dot_product.
Neighbors
Nearest neighbours of one query, best first.
PcaOptions
Python: ScannBuilder.pca(). Set at most one of reduction_dim and pca_significance_threshold; with neither, the threshold is 0.8.
ReorderOptions
Python: ScannBuilder.reorder(): rescore the top candidates exactly (or with a finer quantization).
ScannIndex
A built ScaNN index (research_scann::ScannInterface).
SearchOptions
Per-query search overrides. None uses the value from the config the index was built with (Python: passing None).
TreeOptions
Python: ScannBuilder.tree(). Defaults match Python’s.
UpperTreeOptions
Python: ScannBuilder.upper_tree(): a second partitioning level above the tree. Requires ConfigBuilder::tree.

Enums§

AutopilotRules
Which rules ConfigBuilder::autopilot_with chooses the configuration with (Python: autopilot(rules=...)).
DistanceMeasure
HashType
IncrementalMode
Python: scann_builder.IncrementalMode.
IncrementalThreshold
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).
ScannError
Error from scann-core, or from argument validation in these bindings.

Type Aliases§

Result