From b8fd85a46d4f5034b32805a0e59653cffbe2dd58 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 19 Sep 2024 15:57:38 +0200 Subject: [PATCH] Get rids of useless collect before an iteration on the readers --- milli/src/search/new/vector_sort.rs | 7 ++----- milli/src/search/similar.rs | 8 ++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/milli/src/search/new/vector_sort.rs b/milli/src/search/new/vector_sort.rs index 47480c315..de1dacbe7 100644 --- a/milli/src/search/new/vector_sort.rs +++ b/milli/src/search/new/vector_sort.rs @@ -52,15 +52,12 @@ impl VectorSort { ctx: &mut SearchContext<'_>, vector_candidates: &RoaringBitmap, ) -> Result<()> { - let readers: Result> = - ctx.index.arroy_readers(ctx.txn, self.embedder_index, self.quantized).collect(); - let target = &self.target; let mut results = Vec::new(); - for reader in readers?.iter() { + for reader in ctx.index.arroy_readers(ctx.txn, self.embedder_index, self.quantized) { let nns_by_vector = - reader.nns_by_vector(ctx.txn, target, self.limit, Some(vector_candidates))?; + reader?.nns_by_vector(ctx.txn, target, self.limit, Some(vector_candidates))?; results.extend(nns_by_vector.into_iter()); } results.sort_unstable_by_key(|(_, distance)| OrderedFloat(*distance)); diff --git a/milli/src/search/similar.rs b/milli/src/search/similar.rs index ac56e10fa..a9072f723 100644 --- a/milli/src/search/similar.rs +++ b/milli/src/search/similar.rs @@ -70,14 +70,10 @@ impl<'a> Similar<'a> { .get(self.rtxn, &self.embedder_name)? .ok_or_else(|| crate::UserError::InvalidEmbedder(self.embedder_name.to_owned()))?; - let readers: Result> = - self.index.arroy_readers(self.rtxn, embedder_index, self.quantized).collect(); - let readers = readers?; - let mut results = Vec::new(); - for reader in readers.iter() { - let nns_by_item = reader.nns_by_item( + for reader in self.index.arroy_readers(self.rtxn, embedder_index, self.quantized) { + let nns_by_item = reader?.nns_by_item( self.rtxn, self.id, self.limit + self.offset + 1,