[−][src]Struct hnsw::HNSW
This provides a HNSW implementation for any distance function.
The type T
must implement FloatingDistance
to get implementations.
Methods
impl<T, M: ArrayLength<u32>, M0: ArrayLength<u32>, R> HNSW<T, M, M0, R> where
R: RngCore + SeedableRng,
[src]
R: RngCore + SeedableRng,
pub fn new() -> Self
[src]
Creates a new HNSW with a PRNG which is default seeded to produce deterministic behavior.
pub fn new_params(params: Params) -> Self
[src]
Creates a new HNSW with a default seeded PRNG and with the specified params.
impl<T, M: ArrayLength<u32>, M0: ArrayLength<u32>, R> HNSW<T, M, M0, R> where
R: RngCore,
T: MetricPoint,
[src]
R: RngCore,
T: MetricPoint,
pub fn new_prng(prng: R) -> Self
[src]
Creates a HNSW with the passed prng
.
pub fn new_params_and_prng(params: Params, prng: R) -> Self
[src]
Creates a HNSW with the passed params
and prng
.
pub fn insert(&mut self, q: T, searcher: &mut Searcher) -> u32
[src]
Inserts a feature into the HNSW.
pub fn nearest<'a>(
&self,
q: &T,
ef: usize,
searcher: &mut Searcher,
dest: &'a mut [Neighbor]
) -> &'a mut [Neighbor]
[src]
&self,
q: &T,
ef: usize,
searcher: &mut Searcher,
dest: &'a mut [Neighbor]
) -> &'a mut [Neighbor]
Does a k-NN search where q
is the query element and it attempts to put up to M
nearest neighbors into dest
.
ef
is the candidate pool size. ef
can be increased to get better recall at the expense of speed.
If ef
is less than dest.len()
then dest
will only be filled with ef
elements.
Returns a slice of the filled neighbors.
pub fn feature(&self, item: u32) -> &T
[src]
Extract the feature for a given item returned by HNSW::nearest
.
The item
must be retrieved from HNSW::search_layer
.
pub fn layer_feature(&self, level: usize, item: u32) -> &T
[src]
Extract the feature from a particular level for a given item returned by HNSW::search_layer
.
pub fn layer_item_id(&self, level: usize, item: u32) -> u32
[src]
Retrieve the item ID for a given layer item returned by HNSW::search_layer
.
pub fn layers(&self) -> usize
[src]
pub fn len(&self) -> usize
[src]
pub fn layer_len(&self, level: usize) -> usize
[src]
pub fn is_empty(&self) -> bool
[src]
pub fn layer_is_empty(&self, level: usize) -> bool
[src]
pub fn search_layer<'a>(
&self,
q: &T,
ef: usize,
level: usize,
searcher: &mut Searcher,
dest: &'a mut [Neighbor]
) -> &'a mut [Neighbor]
[src]
&self,
q: &T,
ef: usize,
level: usize,
searcher: &mut Searcher,
dest: &'a mut [Neighbor]
) -> &'a mut [Neighbor]
Performs the same algorithm as HNSW::nearest
, but stops on a particular layer of the network
and returns the unique index on that layer rather than the item index.
If this is passed a level
of 0
, then this has the exact same functionality as HNSW::nearest
since the unique indices at layer 0
are the item indices.
Trait Implementations
impl<T: Clone, M: Clone + ArrayLength<u32>, M0: Clone + ArrayLength<u32>, R: Clone> Clone for HNSW<T, M, M0, R>
[src]
impl<T, M: ArrayLength<u32>, M0: ArrayLength<u32>, R> Default for HNSW<T, M, M0, R> where
R: SeedableRng,
[src]
R: SeedableRng,
impl<'de, T, M: ArrayLength<u32>, M0: ArrayLength<u32>, R> Deserialize<'de> for HNSW<T, M, M0, R> where
T: Deserialize<'de>,
R: Deserialize<'de>,
[src]
T: Deserialize<'de>,
R: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<T, M: ArrayLength<u32>, M0: ArrayLength<u32>, R> Serialize for HNSW<T, M, M0, R> where
T: Serialize,
R: Serialize,
[src]
T: Serialize,
R: Serialize,
Auto Trait Implementations
impl<T, M, M0, R> RefUnwindSafe for HNSW<T, M, M0, R> where
R: RefUnwindSafe,
T: RefUnwindSafe,
<M as ArrayLength<u32>>::ArrayType: RefUnwindSafe,
<M0 as ArrayLength<u32>>::ArrayType: RefUnwindSafe,
R: RefUnwindSafe,
T: RefUnwindSafe,
<M as ArrayLength<u32>>::ArrayType: RefUnwindSafe,
<M0 as ArrayLength<u32>>::ArrayType: RefUnwindSafe,
impl<T, M, M0, R> Send for HNSW<T, M, M0, R> where
R: Send,
T: Send,
R: Send,
T: Send,
impl<T, M, M0, R> Sync for HNSW<T, M, M0, R> where
R: Sync,
T: Sync,
R: Sync,
T: Sync,
impl<T, M, M0, R> Unpin for HNSW<T, M, M0, R> where
R: Unpin,
T: Unpin,
<M as ArrayLength<u32>>::ArrayType: Unpin,
<M0 as ArrayLength<u32>>::ArrayType: Unpin,
R: Unpin,
T: Unpin,
<M as ArrayLength<u32>>::ArrayType: Unpin,
<M0 as ArrayLength<u32>>::ArrayType: Unpin,
impl<T, M, M0, R> UnwindSafe for HNSW<T, M, M0, R> where
R: UnwindSafe,
T: UnwindSafe,
<M as ArrayLength<u32>>::ArrayType: UnwindSafe,
<M0 as ArrayLength<u32>>::ArrayType: UnwindSafe,
R: UnwindSafe,
T: UnwindSafe,
<M as ArrayLength<u32>>::ArrayType: UnwindSafe,
<M0 as ArrayLength<u32>>::ArrayType: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> Cast<U> for T where
U: FromCast<T>,
U: FromCast<T>,
fn cast(self) -> U
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T> FromCast<T> for T
fn from_cast(t: T) -> T
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,