mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-06-13 19:41:37 +02:00
Return all the _semanticScore values in the documents
This commit is contained in:
parent
30741d17fa
commit
b2b413db12
@ -228,6 +228,8 @@ pub struct SearchHit {
|
|||||||
pub ranking_score: Option<f64>,
|
pub ranking_score: Option<f64>,
|
||||||
#[serde(rename = "_rankingScoreDetails", skip_serializing_if = "Option::is_none")]
|
#[serde(rename = "_rankingScoreDetails", skip_serializing_if = "Option::is_none")]
|
||||||
pub ranking_score_details: Option<serde_json::Map<String, serde_json::Value>>,
|
pub ranking_score_details: Option<serde_json::Map<String, serde_json::Value>>,
|
||||||
|
#[serde(rename = "_semanticScore", skip_serializing_if = "Option::is_none")]
|
||||||
|
pub semantic_score: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Debug, Clone, PartialEq)]
|
#[derive(Serialize, Debug, Clone, PartialEq)]
|
||||||
@ -462,11 +464,13 @@ pub fn perform_search(
|
|||||||
insert_geo_distance(sort, &mut document);
|
insert_geo_distance(sort, &mut document);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(vector) = query.vector.as_ref() {
|
let semantic_score = match query.vector.as_ref() {
|
||||||
if let Some(vectors) = extract_field("_vectors", &fields_ids_map, obkv)? {
|
Some(vector) => match extract_field("_vectors", &fields_ids_map, obkv)? {
|
||||||
insert_semantic_score(vector, vectors, &mut document);
|
Some(vectors) => compute_semantic_score(vector, vectors)?,
|
||||||
}
|
None => None,
|
||||||
}
|
},
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
let ranking_score =
|
let ranking_score =
|
||||||
query.show_ranking_score.then(|| ScoreDetails::global_score(score.iter()));
|
query.show_ranking_score.then(|| ScoreDetails::global_score(score.iter()));
|
||||||
@ -479,6 +483,7 @@ pub fn perform_search(
|
|||||||
matches_position,
|
matches_position,
|
||||||
ranking_score_details,
|
ranking_score_details,
|
||||||
ranking_score,
|
ranking_score,
|
||||||
|
semantic_score,
|
||||||
};
|
};
|
||||||
documents.push(hit);
|
documents.push(hit);
|
||||||
}
|
}
|
||||||
@ -553,18 +558,15 @@ fn insert_geo_distance(sorts: &[String], document: &mut Document) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_semantic_score(query: &[f32], vectors: Value, document: &mut Document) {
|
fn compute_semantic_score(query: &[f32], vectors: Value) -> milli::Result<Option<f32>> {
|
||||||
let vectors =
|
let vectors = serde_json::from_value(vectors)
|
||||||
match serde_json::from_value(vectors).map(VectorOrArrayOfVectors::into_array_of_vectors) {
|
.map(VectorOrArrayOfVectors::into_array_of_vectors)
|
||||||
Ok(vectors) => vectors,
|
.map_err(InternalError::SerdeJson)?;
|
||||||
Err(_) => return,
|
Ok(vectors
|
||||||
};
|
|
||||||
let similarity = vectors
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v| OrderedFloat(dot_product_similarity(query, &v)))
|
.map(|v| OrderedFloat(dot_product_similarity(query, &v)))
|
||||||
.max()
|
.max()
|
||||||
.map(OrderedFloat::into_inner);
|
.map(OrderedFloat::into_inner))
|
||||||
document.insert("_semanticScore".to_string(), json!(similarity));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_formatted_options(
|
fn compute_formatted_options(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user