pub struct DiskANN<T, D>{
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: usizeDimensionality of vectors in the index
num_vectors: usizeNumber of vectors in the index
max_degree: usizeMaximum number of edges per node
distance_name: StringInformational: type name of the distance (from metadata)
Implementations§
Source§impl<T, D> DiskANN<T, D>
impl<T, D> DiskANN<T, D>
Sourcepub fn build_index_default(
vectors: &[Vec<T>],
dist: D,
file_path: &str,
) -> Result<Self, DiskAnnError>
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).
Sourcepub fn build_index_with_params(
vectors: &[Vec<T>],
dist: D,
file_path: &str,
p: DiskAnnParams,
) -> Result<Self, DiskAnnError>
pub fn build_index_with_params( vectors: &[Vec<T>], dist: D, file_path: &str, p: DiskAnnParams, ) -> Result<Self, DiskAnnError>
Build with a DiskAnnParams bundle.
Sourcepub fn open_index_with(path: &str, dist: D) -> Result<Self, DiskAnnError>
pub fn open_index_with(path: &str, dist: D) -> Result<Self, DiskAnnError>
Opens an existing index file, supplying the distance strategy explicitly.
Source§impl<T, D> DiskANN<T, D>
Extra sugar when your distance type implements Default.
impl<T, D> DiskANN<T, D>
Extra sugar when your distance type implements Default.
Sourcepub fn build_index_default_metric(
vectors: &[Vec<T>],
file_path: &str,
) -> Result<Self, DiskAnnError>
pub fn build_index_default_metric( vectors: &[Vec<T>], file_path: &str, ) -> Result<Self, DiskAnnError>
Build with default params and D::default() metric.
Sourcepub fn open_index_default_metric(path: &str) -> Result<Self, DiskAnnError>
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>
impl<T, D> DiskANN<T, D>
Sourcepub fn build_index(
vectors: &[Vec<T>],
max_degree: usize,
build_beam_width: usize,
alpha: f32,
dist: D,
file_path: &str,
) -> Result<Self, DiskAnnError>
pub fn build_index( vectors: &[Vec<T>], max_degree: usize, build_beam_width: usize, alpha: f32, 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)dist- Anyanndists::Distance<T>file_path- Path of index file
Sourcepub fn search_with_dists(
&self,
query: &[T],
k: usize,
beam_width: usize,
) -> Vec<(u32, f32)>
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.
Like search but also returns the distance for each neighbor.
Sourcepub fn search(&self, query: &[T], k: usize, beam_width: usize) -> Vec<u32>
pub fn search(&self, query: &[T], k: usize, beam_width: usize) -> Vec<u32>
search but only return neighbor ids
Sourcepub fn get_vector(&self, idx: usize) -> Vec<T>
pub fn get_vector(&self, idx: usize) -> Vec<T>
Gets a vector from the index
Auto Trait Implementations§
impl<T, D> Freeze for DiskANN<T, D>where
D: Freeze,
impl<T, D> RefUnwindSafe for DiskANN<T, D>where
D: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, D> Send for DiskANN<T, D>
impl<T, D> Sync for DiskANN<T, D>
impl<T, D> Unpin for DiskANN<T, D>
impl<T, D> UnwindSafe for DiskANN<T, D>where
D: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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