artefactual.adapters.langfuse.evaluator.HallucinationEvaluator#
- class artefactual.adapters.langfuse.evaluator.HallucinationEvaluator(name, langfuse_client, detector)[source]#
Bases:
objectScores a Langfuse trace’s output and writes the result back as a trace score.
The trace output must be the completion response itself, carrying logprobs — the same object a LogProbParser pipeline’s predict_proba accepts.
Methods
Fetch a trace, score its output, and attach the probability to it.
- __init__(name, langfuse_client, detector)[source]#
- Parameters:
name (
str) – Score name recorded in Langfuse, used as the metric label in its UI.langfuse_client (
Langfuse) – An authenticated Langfuse client.detector (
Pipeline) – A fitted pipeline from completion responses to probabilities, e.g. make_pipeline(LogProbParser(k=15), EPR.from_pretrained(“artefactory/epr-ministral”, k=15)).
- score_trace(trace_id)[source]#
Fetch a trace, score its output, and attach the probability to it.
The score id is derived from the trace id and the metric name, so a trace carries one score per metric however often it is re-scored. Keying on the value instead would mint a fresh id whenever the score moved — after a weights update or a detector swap — and accumulate rows rather than replacing them.
- Parameters:
trace_id (
str) – Id of the trace to fetch and score.- Return type:
- Returns:
P(hallucination) for the trace’s first sequence, as a plain float — Langfuse serialises the value to JSON, which numpy scalars do not survive.
- Raises:
TypeError – If the trace output is not a completion response carrying logprobs.