SimilaritySearch

Struct SimilaritySearch 

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

Similarity search engine for chess positions with production-optimized caching

Implementations§

Source§

impl SimilaritySearch

Source

pub fn new(vector_size: usize) -> Self

Create a new similarity search engine with default caching settings

Source

pub fn with_cache_config( vector_size: usize, max_cache_size: usize, cache_ttl_secs: u64, ) -> Self

Create a new similarity search engine with custom cache configuration

Source

pub fn add_position(&mut self, vector: Array1<f32>, evaluation: f32)

Add a position to the search index

Source

pub fn search_ref( &self, query: &Array1<f32>, k: usize, ) -> Vec<(&Array1<f32>, f32, f32)>

Search for k most similar positions with references (memory efficient)

Source

pub fn search( &mut self, query: &Array1<f32>, k: usize, ) -> Vec<(Array1<f32>, f32, f32)>

Search for k most similar positions with comprehensive caching (automatically chooses best method)

GPU-accelerated similarity search for large datasets

Source

pub fn sequential_search_ref( &self, query: &Array1<f32>, k: usize, ) -> Vec<(&Array1<f32>, f32, f32)>

Sequential search implementation with references (memory efficient)

Sequential search implementation (for small datasets)

Source

pub fn parallel_search_ref( &self, query: &Array1<f32>, k: usize, ) -> Vec<(&Array1<f32>, f32, f32)>

Parallel search implementation with references (memory efficient)

Parallel search implementation (for larger datasets)

Brute force search (for small datasets or comparison)

Source

pub fn search_by_distance( &self, query: &Array1<f32>, k: usize, ) -> Vec<(Array1<f32>, f32, f32)>

Search using Euclidean distance (alternative to cosine similarity)

Source

pub fn size(&self) -> usize

Get number of positions in the index

Source

pub fn is_empty(&self) -> bool

Check if the index is empty

Source

pub fn clear(&mut self)

Clear all positions

Source

pub fn statistics(&self) -> SimilaritySearchStats

Get statistics about the stored vectors

Source

pub fn get_all_positions(&self) -> Vec<(Array1<f32>, f32)>

Get all stored positions (for LSH indexing)

Source

pub fn get_position_ref(&self, index: usize) -> Option<(&Array1<f32>, f32)>

Get position vector by reference to avoid cloning

Source

pub fn iter_positions(&self) -> impl Iterator<Item = (&Array1<f32>, f32)>

Get all positions as references (memory efficient iterator)

Source

pub fn build_cluster_tree(&mut self)

Build hierarchical clustering tree for improved search performance

Source

pub fn rebuild_cluster_tree(&mut self)

Force rebuild of cluster tree (useful after adding many positions)

Source

pub fn cluster_tree_stats(&self) -> Option<ClusterTreeStats>

Get cluster tree statistics

Source

pub fn get_cache_stats(&self) -> SimilarityCacheStats

Get comprehensive cache statistics for performance monitoring

Source

pub fn clear_caches(&mut self)

Clear all caches (useful for benchmarking or memory management)

Source

pub fn reset_cache_stats(&mut self)

Reset cache statistics while preserving cached data

Source§

impl SimilaritySearch

Source

pub fn search_optimized( &self, query: &Array1<f32>, k: usize, ) -> Vec<(Array1<f32>, f32, f32)>

Optimized search with early termination and cached computations

Source

pub fn batch_search_optimized( &self, queries: &[Array1<f32>], k: usize, ) -> Vec<Vec<(Array1<f32>, f32, f32)>>

Batch search optimization for multiple queries

Trait Implementations§

Source§

impl Clone for SimilaritySearch

Source§

fn clone(&self) -> SimilaritySearch

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,