pub struct SimilaritySearch { /* private fields */ }Expand description
Similarity search engine for chess positions with production-optimized caching
Implementations§
Source§impl SimilaritySearch
impl SimilaritySearch
Sourcepub fn new(vector_size: usize) -> Self
pub fn new(vector_size: usize) -> Self
Create a new similarity search engine with default caching settings
Sourcepub fn with_cache_config(
vector_size: usize,
max_cache_size: usize,
cache_ttl_secs: u64,
) -> Self
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
Sourcepub fn add_position(&mut self, vector: Array1<f32>, evaluation: f32)
pub fn add_position(&mut self, vector: Array1<f32>, evaluation: f32)
Add a position to the search index
Sourcepub fn search_ref(
&self,
query: &Array1<f32>,
k: usize,
) -> Vec<(&Array1<f32>, f32, f32)>
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)
Sourcepub fn search(
&mut self,
query: &Array1<f32>,
k: usize,
) -> Vec<(Array1<f32>, f32, f32)>
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)
Sourcepub fn gpu_accelerated_search(
&self,
query: &Array1<f32>,
k: usize,
) -> Result<Vec<(Array1<f32>, f32, f32)>, Box<dyn Error>>
pub fn gpu_accelerated_search( &self, query: &Array1<f32>, k: usize, ) -> Result<Vec<(Array1<f32>, f32, f32)>, Box<dyn Error>>
GPU-accelerated similarity search for large datasets
Sourcepub fn sequential_search_ref(
&self,
query: &Array1<f32>,
k: usize,
) -> Vec<(&Array1<f32>, f32, f32)>
pub fn sequential_search_ref( &self, query: &Array1<f32>, k: usize, ) -> Vec<(&Array1<f32>, f32, f32)>
Sequential search implementation with references (memory efficient)
Sourcepub fn sequential_search(
&self,
query: &Array1<f32>,
k: usize,
) -> Vec<(Array1<f32>, f32, f32)>
pub fn sequential_search( &self, query: &Array1<f32>, k: usize, ) -> Vec<(Array1<f32>, f32, f32)>
Sequential search implementation (for small datasets)
Sourcepub fn parallel_search_ref(
&self,
query: &Array1<f32>,
k: usize,
) -> Vec<(&Array1<f32>, f32, f32)>
pub fn parallel_search_ref( &self, query: &Array1<f32>, k: usize, ) -> Vec<(&Array1<f32>, f32, f32)>
Parallel search implementation with references (memory efficient)
Sourcepub fn parallel_search(
&self,
query: &Array1<f32>,
k: usize,
) -> Vec<(Array1<f32>, f32, f32)>
pub fn parallel_search( &self, query: &Array1<f32>, k: usize, ) -> Vec<(Array1<f32>, f32, f32)>
Parallel search implementation (for larger datasets)
Sourcepub fn brute_force_search(
&self,
query: &Array1<f32>,
k: usize,
) -> Vec<(Array1<f32>, f32, f32)>
pub fn brute_force_search( &self, query: &Array1<f32>, k: usize, ) -> Vec<(Array1<f32>, f32, f32)>
Brute force search (for small datasets or comparison)
Sourcepub fn search_by_distance(
&self,
query: &Array1<f32>,
k: usize,
) -> Vec<(Array1<f32>, f32, f32)>
pub fn search_by_distance( &self, query: &Array1<f32>, k: usize, ) -> Vec<(Array1<f32>, f32, f32)>
Search using Euclidean distance (alternative to cosine similarity)
Sourcepub fn statistics(&self) -> SimilaritySearchStats
pub fn statistics(&self) -> SimilaritySearchStats
Get statistics about the stored vectors
Sourcepub fn get_all_positions(&self) -> Vec<(Array1<f32>, f32)>
pub fn get_all_positions(&self) -> Vec<(Array1<f32>, f32)>
Get all stored positions (for LSH indexing)
Sourcepub fn get_position_ref(&self, index: usize) -> Option<(&Array1<f32>, f32)>
pub fn get_position_ref(&self, index: usize) -> Option<(&Array1<f32>, f32)>
Get position vector by reference to avoid cloning
Sourcepub fn iter_positions(&self) -> impl Iterator<Item = (&Array1<f32>, f32)>
pub fn iter_positions(&self) -> impl Iterator<Item = (&Array1<f32>, f32)>
Get all positions as references (memory efficient iterator)
Sourcepub fn build_cluster_tree(&mut self)
pub fn build_cluster_tree(&mut self)
Build hierarchical clustering tree for improved search performance
Sourcepub fn rebuild_cluster_tree(&mut self)
pub fn rebuild_cluster_tree(&mut self)
Force rebuild of cluster tree (useful after adding many positions)
Sourcepub fn cluster_tree_stats(&self) -> Option<ClusterTreeStats>
pub fn cluster_tree_stats(&self) -> Option<ClusterTreeStats>
Get cluster tree statistics
Sourcepub fn get_cache_stats(&self) -> SimilarityCacheStats
pub fn get_cache_stats(&self) -> SimilarityCacheStats
Get comprehensive cache statistics for performance monitoring
Sourcepub fn clear_caches(&mut self)
pub fn clear_caches(&mut self)
Clear all caches (useful for benchmarking or memory management)
Sourcepub fn reset_cache_stats(&mut self)
pub fn reset_cache_stats(&mut self)
Reset cache statistics while preserving cached data
Trait Implementations§
Source§impl Clone for SimilaritySearch
impl Clone for SimilaritySearch
Source§fn clone(&self) -> SimilaritySearch
fn clone(&self) -> SimilaritySearch
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SimilaritySearch
impl RefUnwindSafe for SimilaritySearch
impl Send for SimilaritySearch
impl Sync for SimilaritySearch
impl Unpin for SimilaritySearch
impl UnwindSafe for SimilaritySearch
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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