pub struct Faithfulness<M: BaseChatModel> { /* private fields */ }Expand description
忠实度评测器(幻觉检测):回答有多忠于参考上下文。
把 prediction 拆成原子陈述,逐条问裁判能否从 reference 推导, 通过率 = 能推导的陈述数 / 总陈述数。
Implementations§
Source§impl<M: BaseChatModel> Faithfulness<M>
impl<M: BaseChatModel> Faithfulness<M>
pub fn new(judge: M) -> Self
Sourcepub fn with_llm_split(self, v: bool) -> Self
pub fn with_llm_split(self, v: bool) -> Self
用 LLM 拆原子陈述(默认按标点规则拆;LLM 拆能处理逗号复合句)
Sourcepub fn with_empty_score(self, score: f64) -> Self
pub fn with_empty_score(self, score: f64) -> Self
空预测的得分:默认 0.0(没回答=不忠实),可设 1.0 表示“没编造即忠实“
Sourcepub fn with_max_context_chars(self, max: usize) -> Self
pub fn with_max_context_chars(self, max: usize) -> Self
参考上下文单条传输上限(字符)。P2-5: 默认 2000,防止长参考被每条陈述重复完整塞进 prompt。
Trait Implementations§
Source§impl<M: BaseChatModel> Evaluator for Faithfulness<M>
impl<M: BaseChatModel> Evaluator for Faithfulness<M>
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,
对单条预测打分
Auto Trait Implementations§
impl<M> Freeze for Faithfulness<M>where
M: Freeze,
impl<M> RefUnwindSafe for Faithfulness<M>where
M: RefUnwindSafe,
impl<M> Send for Faithfulness<M>
impl<M> Sync for Faithfulness<M>
impl<M> Unpin for Faithfulness<M>where
M: Unpin,
impl<M> UnsafeUnpin for Faithfulness<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for Faithfulness<M>where
M: 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