KnowledgeTripletHallucinationDetector<T>
Models & Types · AiDotNet.Safety.Text
Detects hallucinations by extracting (subject, predicate, object) knowledge triplets and verifying them against reference documents.
Inheritance: ModelBase<T, Vector<T>, Vector<T>> → SafetyModuleBase<T> → TextSafetyModuleBase<T> → KnowledgeTripletHallucinationDetector<T>
For Beginners
Imagine breaking every sentence into simple facts like “X is related to Y in way Z”. Then we check each fact against the source documents. If a fact doesn’t appear in any source, the AI probably made it up.
How It Works
Parses the model output into knowledge triplets (e.g., “Paris – capital of – France”) and checks each triplet against the reference corpus. Triplets that cannot be grounded in any reference document are flagged as potential hallucinations. This approach is more precise than sentence-level grounding because it isolates individual factual claims.
References:
- RefChecker: Reference-based fine-grained hallucination via knowledge triplets (Amazon, 2024, arxiv:2405.14486)
- HHEM 2.1: Production-grade hallucination evaluation outperforming GPT-4 (Vectara, 2024)
- Triplet extraction for hallucination detection survey (2025, arxiv:2503.08100)
Constructors
| Constructor | Summary |
|---|---|
KnowledgeTripletHallucinationDetector(string[] referenceDocuments, double threshold, int embeddingDim) |
Initializes a new knowledge triplet hallucination detector. |
Properties
| Property | Summary |
|---|---|
string ModuleName { get; } |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<SafetyFinding> EvaluateText(string text) |
|
KnowledgeTripletHallucinationDetector<T> WithReferences(string[] documents) |
Returns a new detector with updated reference documents. |