Skip to main content

LshIndex

Struct LshIndex 

Source
pub struct LshIndex { /* private fields */ }
Expand description

LSH index for finding candidate similar document pairs.

Documents are inserted into buckets based on their band hashes. Documents in the same bucket are candidate pairs for similarity checking.

Implementations§

Source§

impl LshIndex

Source

pub fn new(config: &Config) -> Result<Self>

Create a new LSH index from configuration.

§Errors

Returns an error if the configuration has incompatible parameters.

Source

pub fn clear(&mut self)

Clear all indexed documents and derived cluster state, keeping the band and row structure and the similarity threshold.

This is the infallible way to empty an index for reuse. Unlike rebuilding via Self::new (which is fallible and, when a caller swallowed its error, could leave a stale populated index while surrounding state was reset), clear() cannot fail and cannot leave the index half-reset.

Source

pub fn insert(&mut self, signature: MinHashSignature) -> Result<Vec<usize>>

Insert a signature into the LSH index.

Returns a list of candidate similar document indices that collided in at least one bucket.

§Errors

Returns Error::InvalidConfig when doc_id exceeds the configured maximum (prevents unbounded allocation from adversarial identifiers).

Source

pub fn query(&self, signature: &MinHashSignature) -> Vec<usize>

Query for candidate similar documents.

Returns document indices that collided with the given signature in at least one LSH bucket.

Source

pub fn verify_similarity(&self, doc_a: usize, doc_b: usize) -> Option<f64>

Verify similarity between two documents using their signatures.

Source

pub fn find_clusters(&mut self) -> &[DuplicateCluster]

Find all duplicate clusters in the index.

This performs pairwise verification of all candidate pairs and groups documents into clusters.

Source

pub fn get_cluster_for_doc(&self, doc_id: usize) -> Option<&DuplicateCluster>

Get the cluster for a document index.

Source

pub fn is_duplicate(&self, doc_id: usize) -> bool

Check if a document is a duplicate (belongs to any cluster).

Source

pub fn get_unique_indices(&self) -> Vec<usize>

Get all unique documents (first in each cluster + non-duplicate documents).

Source

pub const fn doc_count(&self) -> usize

Get the total number of documents indexed.

Source

pub fn cluster_count(&self) -> usize

Get the number of duplicate clusters.

Source

pub fn duplicate_count(&self) -> usize

Get the number of duplicate documents (documents in clusters, excluding representatives).

Source

pub fn stats(&self) -> LshStats

Get statistics about the LSH index.

Source

pub fn memory_usage(&self) -> usize

Estimate memory usage in bytes.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more