pub struct SearchExplainer { /* private fields */ }Expand description
Generates human-readable relevance explanations for semantic search results.
Implementations§
Source§impl SearchExplainer
impl SearchExplainer
Sourcepub fn new(config: ExplainerConfig) -> Self
pub fn new(config: ExplainerConfig) -> Self
Creates a new SearchExplainer with the provided configuration.
Sourcepub fn explain_result(
&mut self,
doc_id: &str,
score: f64,
contributions: Vec<ScoreContribution>,
rank: usize,
ctx: &QueryContext,
) -> ExplanationNode
pub fn explain_result( &mut self, doc_id: &str, score: f64, contributions: Vec<ScoreContribution>, rank: usize, ctx: &QueryContext, ) -> ExplanationNode
Explains a single search result, returning a richly annotated ExplanationNode.
The method filters and sorts contributions according to the current
ExplainerConfig, then generates explanation text.
Sourcepub fn explain_batch(
&mut self,
results: Vec<(String, f64, Vec<ScoreContribution>)>,
ctx: &QueryContext,
) -> Vec<ExplanationNode>
pub fn explain_batch( &mut self, results: Vec<(String, f64, Vec<ScoreContribution>)>, ctx: &QueryContext, ) -> Vec<ExplanationNode>
Explains a batch of results, assigning ranks by order in results.
Each entry in results is (doc_id, score, contributions).
Sourcepub fn format_explanation(node: &ExplanationNode) -> String
pub fn format_explanation(node: &ExplanationNode) -> String
Formats an ExplanationNode into a human-readable multi-line string.
Sourcepub fn top_contributions<'a>(
node: &'a ExplanationNode,
n: usize,
) -> Vec<&'a ScoreContribution>
pub fn top_contributions<'a>( node: &'a ExplanationNode, n: usize, ) -> Vec<&'a ScoreContribution>
Returns up to n contributions sorted by descending absolute weighted score.
Sourcepub fn score_breakdown(
contributions: &[ScoreContribution],
) -> HashMap<String, f64>
pub fn score_breakdown( contributions: &[ScoreContribution], ) -> HashMap<String, f64>
Aggregates contributions by factor name, returning a map of factor → total weighted score.
Sourcepub fn filter_contributions(
&self,
contributions: Vec<ScoreContribution>,
) -> Vec<ScoreContribution>
pub fn filter_contributions( &self, contributions: Vec<ScoreContribution>, ) -> Vec<ScoreContribution>
Filters contributions according to min_contribution_weight and include_negative.
Sourcepub fn cosine_contribution(
query_vec: &[f64],
doc_vec: &[f64],
weight: f64,
) -> ScoreContribution
pub fn cosine_contribution( query_vec: &[f64], doc_vec: &[f64], weight: f64, ) -> ScoreContribution
Builds a ScoreContribution from the cosine similarity between two vectors.
Returns a zero-score contribution when either vector is empty or has zero norm.
Sourcepub fn term_frequency_contribution(
term: &str,
tf: f64,
idf: f64,
weight: f64,
) -> ScoreContribution
pub fn term_frequency_contribution( term: &str, tf: f64, idf: f64, weight: f64, ) -> ScoreContribution
Builds a ScoreContribution from a TF-IDF component.
tf is term frequency, idf is inverse document frequency.
Sourcepub fn compare_explanations(a: &ExplanationNode, b: &ExplanationNode) -> String
pub fn compare_explanations(a: &ExplanationNode, b: &ExplanationNode) -> String
Compares two ExplanationNodes and returns a textual diff explaining
why the higher-ranked result outscored the lower-ranked one.
Sourcepub fn stats(&self) -> &ExplainerStats
pub fn stats(&self) -> &ExplainerStats
Returns a reference to the current running statistics.
Auto Trait Implementations§
impl Freeze for SearchExplainer
impl RefUnwindSafe for SearchExplainer
impl Send for SearchExplainer
impl Sync for SearchExplainer
impl Unpin for SearchExplainer
impl UnsafeUnpin for SearchExplainer
impl UnwindSafe for SearchExplainer
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.