pub struct AnswerRelevancy<M: BaseChatModel, E: Embeddings> { /* private fields */ }Expand description
RAGAS answer relevancy: does the answer actually address the question?
The generator produces n questions that the answer could address (one LLM call); the score
is the mean cosine similarity between the original question’s embedding and the generated
questions’ embeddings. An answer full of on-topic-looking but non-answer text generates
off-target questions and scores low, without needing a reference answer.
Uses one chat call (plain-text question list) plus one embedding batch per evaluation.
Implementations§
Source§impl<M: BaseChatModel, E: Embeddings> AnswerRelevancy<M, E>
impl<M: BaseChatModel, E: Embeddings> AnswerRelevancy<M, E>
Sourcepub fn with_n_questions(self, n: usize) -> Self
pub fn with_n_questions(self, n: usize) -> Self
Sets how many questions the generator should produce (clamped to at least 1).
Sourcepub fn with_empty_score(self, score: f64) -> Self
pub fn with_empty_score(self, score: f64) -> Self
Score for an empty prediction (default 0.0: no answer is not relevant).
Trait Implementations§
Source§impl<M: BaseChatModel, E: Embeddings> Evaluator for AnswerRelevancy<M, E>
impl<M: BaseChatModel, E: Embeddings> Evaluator for AnswerRelevancy<M, E>
Source§fn eval<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
input: &'life1 str,
prediction: &'life2 str,
_reference: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<Score, EvalError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn eval<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
input: &'life1 str,
prediction: &'life2 str,
_reference: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<Score, EvalError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Scores a single prediction
Source§impl<M: BaseChatModel, E: Embeddings> RagEvaluator for AnswerRelevancy<M, E>
impl<M: BaseChatModel, E: Embeddings> RagEvaluator for AnswerRelevancy<M, E>
Source§fn eval_rag<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
input: &'life1 str,
prediction: &'life2 str,
_contexts: &'life3 [String],
_reference: &'life4 str,
) -> Pin<Box<dyn Future<Output = Result<Score, EvalError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn eval_rag<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
input: &'life1 str,
prediction: &'life2 str,
_contexts: &'life3 [String],
_reference: &'life4 str,
) -> Pin<Box<dyn Future<Output = Result<Score, EvalError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Scores a single prediction given the question, retrieved contexts, and reference answer.
Auto Trait Implementations§
impl<M, E> Freeze for AnswerRelevancy<M, E>
impl<M, E> RefUnwindSafe for AnswerRelevancy<M, E>where
M: RefUnwindSafe,
E: RefUnwindSafe,
impl<M, E> Send for AnswerRelevancy<M, E>
impl<M, E> Sync for AnswerRelevancy<M, E>
impl<M, E> Unpin for AnswerRelevancy<M, E>
impl<M, E> UnsafeUnpin for AnswerRelevancy<M, E>where
M: UnsafeUnpin,
E: UnsafeUnpin,
impl<M, E> UnwindSafe for AnswerRelevancy<M, E>where
M: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more