@@ -25,6 +25,21 @@ class HallucinationRequirement(Requirement):
2525 1. In the constructor (for reusable requirements with fixed documents)
2626 2. Attached to the assistant message in the context (for dynamic documents)
2727
28+ Args:
29+ threshold: Faithfulness likelihood threshold (0.0-1.0). Sentences
30+ with faithfulness_likelihood below this value are considered
31+ hallucinated. Default: 0.5
32+ max_hallucinated_ratio: Maximum allowed ratio of hallucinated
33+ content (0.0-1.0). If the ratio of hallucinated characters
34+ to total response length exceeds this, validation fails.
35+ Default: 0.0 (any hallucination fails validation)
36+ documents: Optional documents to validate against. Can be Document
37+ objects or strings (will be converted to Documents). If provided,
38+ these documents will be used instead of documents attached to
39+ messages in the context. Default: None (use context documents)
40+ description: Custom description for the requirement. If None,
41+ generates a description based on threshold and ratio.
42+
2843 Example:
2944 ```python
3045 from mellea.stdlib.requirements.rag import HallucinationRequirement
@@ -51,23 +66,7 @@ def __init__(
5166 documents : Iterable [Document ] | Iterable [str ] | None = None ,
5267 description : str | None = None ,
5368 ):
54- """Initialize hallucination detection requirement.
55-
56- Args:
57- threshold: Faithfulness likelihood threshold (0.0-1.0). Sentences
58- with faithfulness_likelihood below this value are considered
59- hallucinated. Default: 0.5
60- max_hallucinated_ratio: Maximum allowed ratio of hallucinated
61- content (0.0-1.0). If the ratio of hallucinated characters
62- to total response length exceeds this, validation fails.
63- Default: 0.0 (any hallucination fails validation)
64- documents: Optional documents to validate against. Can be Document
65- objects or strings (will be converted to Documents). If provided,
66- these documents will be used instead of documents attached to
67- messages in the context. Default: None (use context documents)
68- description: Custom description for the requirement. If None,
69- generates a description based on threshold and ratio.
70- """
69+ """Initialize hallucination detection requirement."""
7170 if not 0.0 <= threshold <= 1.0 :
7271 raise ValueError (f"threshold must be between 0.0 and 1.0, got { threshold } " )
7372 if not 0.0 <= max_hallucinated_ratio <= 1.0 :
0 commit comments