Skip to main content

DiskANN

Struct DiskANN 

Source
pub struct DiskANN<T, D>
where T: Pod + Copy + Send + Sync + 'static, D: Distance<T> + Send + Sync + Copy + Clone + 'static,
{ pub dim: usize, pub num_vectors: usize, pub max_degree: usize, pub distance_name: String, /* private fields */ }
Expand description

Main struct representing a DiskANN index (generic over vector element T and distance D)

Fields§

§dim: usize

Dimensionality of vectors in the index

§num_vectors: usize

Number of vectors in the index

§max_degree: usize

Maximum number of edges per node

§distance_name: String

Informational: type name of the distance (from metadata)

Implementations§

Source§

impl<T, D> DiskANN<T, D>
where T: Pod + Copy + Send + Sync + 'static, D: Distance<T> + Send + Sync + Copy + Clone + 'static,

Source

pub fn build_index_default( vectors: &[Vec<T>], dist: D, file_path: &str, ) -> Result<Self, DiskAnnError>

Build with default parameters: (M=64, L=128, alpha=1.2, extra_seeds=1).

Source

pub fn build_index_with_params( vectors: &[Vec<T>], dist: D, file_path: &str, p: DiskAnnParams, ) -> Result<Self, DiskAnnError>

Build with a DiskAnnParams bundle.

Source

pub fn open_index_with(path: &str, dist: D) -> Result<Self, DiskAnnError>

Opens an existing index file, supplying the distance strategy explicitly.

Source

pub fn begin_updates( self, capacity: usize, alpha: f32, path: &str, ) -> Result<Self, DiskAnnError>

Starts a transient update session from a static index.

The default routability-aware deletion guard is initialized as an in-memory sidecar for the session. It is not persisted in a later static commit. Commit the session with commit_updates_to_static; the work file is not a persistent index format and is never accepted by open_index_with.

Source

pub fn is_updating(&self) -> bool

True while this handle is a transient update session.

Source

pub fn enable_routability_guard( &mut self, config: RoutabilityGuardConfig, ) -> Result<RoutabilityGuardStatus, DiskAnnError>

Reconfigures the in-memory routability guard for this update session.

begin_updates enables the default configuration automatically. This method replaces that configuration with caller-supplied settings. The guard is discarded when the session is committed to a static index and never changes the static file format.

Source

pub fn disable_routability_guard(&mut self) -> Result<(), DiskAnnError>

Disables routability admission control for this update session.

This is an explicit opt-out: subsequent ordinary deletion calls use unguarded MERIT repair until enable_routability_guard is called again.

Source

pub fn routability_guard_status( &self, ) -> Result<RoutabilityGuardStatus, DiskAnnError>

Returns the current routability-guard state.

New update sessions are enabled by default.

Source

pub fn assess_delete_admission( &self, ids: &[u32], ) -> Result<RoutabilityAdmissionReport, DiskAnnError>

Runs a virtual routability preflight for a proposed delete batch.

New update sessions have the default guard enabled. The preflight does not mutate the update session.

Source

pub fn capacity(&self) -> usize

Number of addressable slots. Static-v1 capacity equals its vector count.

Source

pub fn insert( &mut self, vector: Vec<T>, beam: usize, ) -> Result<u32, DiskAnnError>

Inserts one vector during a transient update session.

Source

pub fn insert_batch( &mut self, vectors: Vec<Vec<T>>, beam: usize, ) -> Result<Vec<u32>, DiskAnnError>

Inserts a batch during a transient update session.

Source

pub fn delete(&mut self, id: u32) -> Result<Option<DeleteStats>, DiskAnnError>

Deletes one node and repairs its neighborhood with MERIT.

Source

pub fn delete_with_params( &mut self, id: u32, repair_beam: usize, repair_degree: usize, ) -> Result<Option<DeleteStats>, DiskAnnError>

Deletes one node with explicitly configured MERIT repair parameters.

Source

pub fn delete_batch( &mut self, ids: &[u32], ) -> Result<Vec<DeleteStats>, DiskAnnError>

Deletes a batch with MERIT defaults: repair beam 2R and k_r = 2.

Routability admission control is enabled by default. A deferred batch returns an error without mutating the graph; use Self::delete_batch_with_admission_control when the structured admission report is needed. Call Self::disable_routability_guard to explicitly use unguarded MERIT repair.

Source

pub fn delete_batch_with_params( &mut self, ids: &[u32], repair_beam: usize, repair_degree: usize, ) -> Result<Vec<DeleteStats>, DiskAnnError>

Deletes a batch with explicitly configured MERIT repair parameters.

The default guard is applied before repair. A deferred batch returns an error without changing the update session.

Source

pub fn delete_batch_with_admission_control( &mut self, ids: &[u32], ) -> Result<GuardedDeleteResult, DiskAnnError>

Deletes a batch only when the routability preflight admits it.

This uses the standard MERIT defaults: repair beam 2R and k_r = 2. begin_updates enables the default guard automatically; callers may replace its configuration with Self::enable_routability_guard. A deferred result leaves the update session entirely unchanged.

Source

pub fn delete_batch_with_admission_control_with_params( &mut self, ids: &[u32], repair_beam: usize, repair_degree: usize, ) -> Result<GuardedDeleteResult, DiskAnnError>

Deletes a batch only when the optional routability preflight admits it, with explicitly configured MERIT repair parameters.

Source

pub fn flush(&self) -> Result<(), DiskAnnError>

Flushes pending update-workspace writes. Static handles are read-only.

Source

pub fn commit_updates_to_static( self, path: &str, ) -> Result<(Self, Vec<Option<u32>>), DiskAnnError>

Finishes an update session and commits it as an ordinary static index.

Only live vectors and live, version-matching edges are written. IDs are compacted to 0..num_vectors; the returned tuple contains the ordinary static search index and the required old-to-new ID mapping.

Source§

impl<T, D> DiskANN<T, D>
where T: Pod + Copy + Send + Sync + 'static, D: Distance<T> + Default + Send + Sync + Copy + Clone + 'static,

Extra sugar when your distance type implements Default.

Source

pub fn build_index_default_metric( vectors: &[Vec<T>], file_path: &str, ) -> Result<Self, DiskAnnError>

Build with default params and D::default() metric.

Source

pub fn open_index_default_metric(path: &str) -> Result<Self, DiskAnnError>

Open an index using D::default() as the distance (matches what you built with).

Source§

impl<T, D> DiskANN<T, D>
where T: Pod + Copy + Send + Sync + 'static, D: Distance<T> + Send + Sync + Copy + Clone + 'static,

Source

pub fn build_index( vectors: &[Vec<T>], max_degree: usize, build_beam_width: usize, alpha: f32, extra_seeds: usize, dist: D, file_path: &str, ) -> Result<Self, DiskAnnError>

Builds a new index from provided vectors

§Arguments
  • vectors - The vectors to index (slice of Vec)
  • max_degree - Maximum edges per node (M ~ 24-64+)
  • build_beam_width - Construction L (e.g., 128-400)
  • alpha - Pruning parameter (1.2–2.0)
  • extra_seeds - Extra random seeds per node (>=0)
  • dist - Any anndists::Distance<T>
  • file_path - Path of index file
Source

pub fn search_with_dists( &self, query: &[T], k: usize, beam_width: usize, ) -> Vec<(u32, f32)>

Searches the index for nearest neighbors using a best-first beam search. Termination rule: continue while the best frontier can still improve the worst in working set.

Source

pub fn search(&self, query: &[T], k: usize, beam_width: usize) -> Vec<u32>

search but only return neighbor ids

Source

pub fn get_vector(&self, idx: usize) -> Vec<T>

Gets a vector from the index

Auto Trait Implementations§

§

impl<T, D> Forget for DiskANN<T, D>

§

impl<T, D> Freeze for DiskANN<T, D>

§

impl<T, D> Move for DiskANN<T, D>

§

impl<T, D> RefUnwindSafe for DiskANN<T, D>

§

impl<T, D> Send for DiskANN<T, D>
where RawVecInner: Send, MmapInner: Send,

§

impl<T, D> Sync for DiskANN<T, D>
where RawVecInner: Sync, MmapInner: Sync,

§

impl<T, D> Unpin for DiskANN<T, D>
where D: Unpin, T: Unpin, *const u8 is !null: Unpin, *mut c_void: Unpin,

§

impl<T, D> UnsafeUnpin for DiskANN<T, D>

§

impl<T, D> UnwindSafe for DiskANN<T, D>
where RawVecInner: UnwindSafe, *mut c_void: UnwindSafe, D: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V