diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index db58c6102..2e0df18ad 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -633,10 +633,8 @@ pub fn perform_search( let mut semantic_score = None; for details in &score { - if let ScoreDetails::Vector(score_details::Vector { - target_vector: _, - value_similarity: Some((_matching_vector, similarity)), - }) = details + if let ScoreDetails::Vector(score_details::Vector { similarity: Some(similarity) }) = + details { semantic_score = Some(*similarity); break; diff --git a/milli/src/score_details.rs b/milli/src/score_details.rs index 08dfcdbb6..0a9b77e2b 100644 --- a/milli/src/score_details.rs +++ b/milli/src/score_details.rs @@ -98,9 +98,9 @@ impl ScoreDetails { ScoreDetails::ExactWords(e) => RankOrValue::Rank(e.rank()), ScoreDetails::Sort(sort) => RankOrValue::Sort(sort), ScoreDetails::GeoSort(geosort) => RankOrValue::GeoSort(geosort), - ScoreDetails::Vector(vector) => RankOrValue::Score( - vector.value_similarity.as_ref().map(|(_, s)| *s as f64).unwrap_or(0.0f64), - ), + ScoreDetails::Vector(vector) => { + RankOrValue::Score(vector.similarity.as_ref().map(|s| *s as f64).unwrap_or(0.0f64)) + } ScoreDetails::Skipped => RankOrValue::Rank(Rank { rank: 0, max_rank: 1 }), } } @@ -249,16 +249,13 @@ impl ScoreDetails { order += 1; } ScoreDetails::Vector(s) => { - let vector = format!("vectorSort({:?})", s.target_vector); - let value = s.value_similarity.as_ref().map(|(v, _)| v); - let similarity = s.value_similarity.as_ref().map(|(_, s)| s); + let similarity = s.similarity.as_ref(); let details = serde_json::json!({ "order": order, - "value": value, "similarity": similarity, }); - details_map.insert(vector, details); + details_map.insert("vectorSort".into(), details); order += 1; } ScoreDetails::Skipped => { @@ -494,8 +491,7 @@ impl PartialOrd for GeoSort { #[derive(Debug, Clone, PartialEq, PartialOrd)] pub struct Vector { - pub target_vector: Vec, - pub value_similarity: Option<(Vec, f32)>, + pub similarity: Option, } impl GeoSort { diff --git a/milli/src/search/new/vector_sort.rs b/milli/src/search/new/vector_sort.rs index b29a72827..476477218 100644 --- a/milli/src/search/new/vector_sort.rs +++ b/milli/src/search/new/vector_sort.rs @@ -12,7 +12,7 @@ pub struct VectorSort { query: Option, target: Vec, vector_candidates: RoaringBitmap, - cached_sorted_docids: std::vec::IntoIter<(DocumentId, f32, Vec)>, + cached_sorted_docids: std::vec::IntoIter<(DocumentId, f32)>, limit: usize, distribution_shift: Option, embedder_index: u8, @@ -70,14 +70,9 @@ impl VectorSort { for reader in readers.iter() { let nns_by_vector = reader.nns_by_vector(ctx.txn, target, self.limit, None, Some(vector_candidates))?; - let vectors: std::result::Result, _> = nns_by_vector - .iter() - .map(|(docid, _)| reader.item_vector(ctx.txn, *docid).transpose().unwrap()) - .collect(); - let vectors = vectors?; - results.extend(nns_by_vector.into_iter().zip(vectors).map(|((x, y), z)| (x, y, z))); + results.extend(nns_by_vector.into_iter()); } - results.sort_unstable_by_key(|(_, distance, _)| OrderedFloat(*distance)); + results.sort_unstable_by_key(|(_, distance)| OrderedFloat(*distance)); self.cached_sorted_docids = results.into_iter(); Ok(()) @@ -118,14 +113,11 @@ impl<'ctx, Q: RankingRuleQueryTrait> RankingRule<'ctx, Q> for VectorSort { return Ok(Some(RankingRuleOutput { query, candidates: universe.clone(), - score: ScoreDetails::Vector(score_details::Vector { - target_vector: self.target.clone(), - value_similarity: None, - }), + score: ScoreDetails::Vector(score_details::Vector { similarity: None }), })); } - for (docid, distance, vector) in self.cached_sorted_docids.by_ref() { + for (docid, distance) in self.cached_sorted_docids.by_ref() { if vector_candidates.contains(docid) { let score = 1.0 - distance; let score = self @@ -135,10 +127,7 @@ impl<'ctx, Q: RankingRuleQueryTrait> RankingRule<'ctx, Q> for VectorSort { return Ok(Some(RankingRuleOutput { query, candidates: RoaringBitmap::from_iter([docid]), - score: ScoreDetails::Vector(score_details::Vector { - target_vector: self.target.clone(), - value_similarity: Some((vector, score)), - }), + score: ScoreDetails::Vector(score_details::Vector { similarity: Some(score) }), })); } } @@ -154,10 +143,7 @@ impl<'ctx, Q: RankingRuleQueryTrait> RankingRule<'ctx, Q> for VectorSort { return Ok(Some(RankingRuleOutput { query, candidates: universe.clone(), - score: ScoreDetails::Vector(score_details::Vector { - target_vector: self.target.clone(), - value_similarity: None, - }), + score: ScoreDetails::Vector(score_details::Vector { similarity: None }), })); }