diff --git a/src/hnsw/hnsw_const.rs b/src/hnsw/hnsw_const.rs index 2a76e21..aae9b41 100644 --- a/src/hnsw/hnsw_const.rs +++ b/src/hnsw/hnsw_const.rs @@ -64,6 +64,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 @@ -307,7 +322,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] }