mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-19 09:35:51 +08:00
Breaking change: remove vector for score details
This commit is contained in:
parent
5509bafff8
commit
928e6e4c05
@ -633,10 +633,8 @@ pub fn perform_search(
|
|||||||
|
|
||||||
let mut semantic_score = None;
|
let mut semantic_score = None;
|
||||||
for details in &score {
|
for details in &score {
|
||||||
if let ScoreDetails::Vector(score_details::Vector {
|
if let ScoreDetails::Vector(score_details::Vector { similarity: Some(similarity) }) =
|
||||||
target_vector: _,
|
details
|
||||||
value_similarity: Some((_matching_vector, similarity)),
|
|
||||||
}) = details
|
|
||||||
{
|
{
|
||||||
semantic_score = Some(*similarity);
|
semantic_score = Some(*similarity);
|
||||||
break;
|
break;
|
||||||
|
@ -98,9 +98,9 @@ impl ScoreDetails {
|
|||||||
ScoreDetails::ExactWords(e) => RankOrValue::Rank(e.rank()),
|
ScoreDetails::ExactWords(e) => RankOrValue::Rank(e.rank()),
|
||||||
ScoreDetails::Sort(sort) => RankOrValue::Sort(sort),
|
ScoreDetails::Sort(sort) => RankOrValue::Sort(sort),
|
||||||
ScoreDetails::GeoSort(geosort) => RankOrValue::GeoSort(geosort),
|
ScoreDetails::GeoSort(geosort) => RankOrValue::GeoSort(geosort),
|
||||||
ScoreDetails::Vector(vector) => RankOrValue::Score(
|
ScoreDetails::Vector(vector) => {
|
||||||
vector.value_similarity.as_ref().map(|(_, s)| *s as f64).unwrap_or(0.0f64),
|
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 }),
|
ScoreDetails::Skipped => RankOrValue::Rank(Rank { rank: 0, max_rank: 1 }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,16 +249,13 @@ impl ScoreDetails {
|
|||||||
order += 1;
|
order += 1;
|
||||||
}
|
}
|
||||||
ScoreDetails::Vector(s) => {
|
ScoreDetails::Vector(s) => {
|
||||||
let vector = format!("vectorSort({:?})", s.target_vector);
|
let similarity = s.similarity.as_ref();
|
||||||
let value = s.value_similarity.as_ref().map(|(v, _)| v);
|
|
||||||
let similarity = s.value_similarity.as_ref().map(|(_, s)| s);
|
|
||||||
|
|
||||||
let details = serde_json::json!({
|
let details = serde_json::json!({
|
||||||
"order": order,
|
"order": order,
|
||||||
"value": value,
|
|
||||||
"similarity": similarity,
|
"similarity": similarity,
|
||||||
});
|
});
|
||||||
details_map.insert(vector, details);
|
details_map.insert("vectorSort".into(), details);
|
||||||
order += 1;
|
order += 1;
|
||||||
}
|
}
|
||||||
ScoreDetails::Skipped => {
|
ScoreDetails::Skipped => {
|
||||||
@ -494,8 +491,7 @@ impl PartialOrd for GeoSort {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd)]
|
#[derive(Debug, Clone, PartialEq, PartialOrd)]
|
||||||
pub struct Vector {
|
pub struct Vector {
|
||||||
pub target_vector: Vec<f32>,
|
pub similarity: Option<f32>,
|
||||||
pub value_similarity: Option<(Vec<f32>, f32)>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GeoSort {
|
impl GeoSort {
|
||||||
|
@ -12,7 +12,7 @@ pub struct VectorSort<Q: RankingRuleQueryTrait> {
|
|||||||
query: Option<Q>,
|
query: Option<Q>,
|
||||||
target: Vec<f32>,
|
target: Vec<f32>,
|
||||||
vector_candidates: RoaringBitmap,
|
vector_candidates: RoaringBitmap,
|
||||||
cached_sorted_docids: std::vec::IntoIter<(DocumentId, f32, Vec<f32>)>,
|
cached_sorted_docids: std::vec::IntoIter<(DocumentId, f32)>,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
distribution_shift: Option<DistributionShift>,
|
distribution_shift: Option<DistributionShift>,
|
||||||
embedder_index: u8,
|
embedder_index: u8,
|
||||||
@ -70,14 +70,9 @@ impl<Q: RankingRuleQueryTrait> VectorSort<Q> {
|
|||||||
for reader in readers.iter() {
|
for reader in readers.iter() {
|
||||||
let nns_by_vector =
|
let nns_by_vector =
|
||||||
reader.nns_by_vector(ctx.txn, target, self.limit, None, Some(vector_candidates))?;
|
reader.nns_by_vector(ctx.txn, target, self.limit, None, Some(vector_candidates))?;
|
||||||
let vectors: std::result::Result<Vec<_>, _> = nns_by_vector
|
results.extend(nns_by_vector.into_iter());
|
||||||
.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.sort_unstable_by_key(|(_, distance, _)| OrderedFloat(*distance));
|
results.sort_unstable_by_key(|(_, distance)| OrderedFloat(*distance));
|
||||||
self.cached_sorted_docids = results.into_iter();
|
self.cached_sorted_docids = results.into_iter();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -118,14 +113,11 @@ impl<'ctx, Q: RankingRuleQueryTrait> RankingRule<'ctx, Q> for VectorSort<Q> {
|
|||||||
return Ok(Some(RankingRuleOutput {
|
return Ok(Some(RankingRuleOutput {
|
||||||
query,
|
query,
|
||||||
candidates: universe.clone(),
|
candidates: universe.clone(),
|
||||||
score: ScoreDetails::Vector(score_details::Vector {
|
score: ScoreDetails::Vector(score_details::Vector { similarity: None }),
|
||||||
target_vector: self.target.clone(),
|
|
||||||
value_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) {
|
if vector_candidates.contains(docid) {
|
||||||
let score = 1.0 - distance;
|
let score = 1.0 - distance;
|
||||||
let score = self
|
let score = self
|
||||||
@ -135,10 +127,7 @@ impl<'ctx, Q: RankingRuleQueryTrait> RankingRule<'ctx, Q> for VectorSort<Q> {
|
|||||||
return Ok(Some(RankingRuleOutput {
|
return Ok(Some(RankingRuleOutput {
|
||||||
query,
|
query,
|
||||||
candidates: RoaringBitmap::from_iter([docid]),
|
candidates: RoaringBitmap::from_iter([docid]),
|
||||||
score: ScoreDetails::Vector(score_details::Vector {
|
score: ScoreDetails::Vector(score_details::Vector { similarity: Some(score) }),
|
||||||
target_vector: self.target.clone(),
|
|
||||||
value_similarity: Some((vector, score)),
|
|
||||||
}),
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,10 +143,7 @@ impl<'ctx, Q: RankingRuleQueryTrait> RankingRule<'ctx, Q> for VectorSort<Q> {
|
|||||||
return Ok(Some(RankingRuleOutput {
|
return Ok(Some(RankingRuleOutput {
|
||||||
query,
|
query,
|
||||||
candidates: universe.clone(),
|
candidates: universe.clone(),
|
||||||
score: ScoreDetails::Vector(score_details::Vector {
|
score: ScoreDetails::Vector(score_details::Vector { similarity: None }),
|
||||||
target_vector: self.target.clone(),
|
|
||||||
value_similarity: None,
|
|
||||||
}),
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user