From fb2adcdf292be6dc855850afdfe0abe855900fd3 Mon Sep 17 00:00:00 2001 From: Gavin Mendel-Gleason Date: Fri, 12 May 2023 00:10:58 +0200 Subject: [PATCH 1/2] Adding transformer --- src/hnsw/hnsw_const.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/hnsw/hnsw_const.rs b/src/hnsw/hnsw_const.rs index 863c369..695c995 100644 --- a/src/hnsw/hnsw_const.rs +++ b/src/hnsw/hnsw_const.rs @@ -63,6 +63,21 @@ where params, } } + + pub fn transform_features(self, f: F) -> Hnsw + where + F: Fn(T) -> T2, + { + let features = self.features.into_iter().map(f).collect(); + Hnsw { + metric: self.metric, + zero: self.zero, + features, + layers: self.layers, + prng: self.prng, + params: self.params, + } + } } impl Knn for Hnsw From 161701bbb95d48eaae697f3b86a9e4b21b53aef9 Mon Sep 17 00:00:00 2001 From: Gavin Mendel-Gleason Date: Thu, 6 Jul 2023 13:12:33 +0200 Subject: [PATCH 2/2] Fix copy to work on truncations --- src/hnsw/hnsw_const.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hnsw/hnsw_const.rs b/src/hnsw/hnsw_const.rs index 695c995..a4cb898 100644 --- a/src/hnsw/hnsw_const.rs +++ b/src/hnsw/hnsw_const.rs @@ -320,7 +320,7 @@ where self.search_zero_layer(q, searcher, cap); let found = core::cmp::min(dest.len(), searcher.nearest.len()); - dest.copy_from_slice(&searcher.nearest[..found]); + dest[..found].copy_from_slice(&searcher.nearest[..found]); &mut dest[..found] }