Halluzinationen erkennen und messen
Lernen Sie praxisnahe Techniken, um zu erkennen, wann ein RAG-System Fakten erfindet, die vom abgerufenen Kontext nicht gestützt werden, und die Halluzinationsrate als Teil der Evaluierung zu quantifizieren.
Halluzinationen erkennen und messen ist eine kostenlose LLM Apps in Production (RAG + Vector DB + Caching)-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des LLM Apps in Production (RAG + Vector DB + Caching)-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der LLM Apps in Production (RAG + Vector DB + Caching)-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
What Is a RAG Hallucination?
A hallucination is an answer that is fluent and confident but not supported by the retrieved context. In RAG, the cure is grounding: every claim should trace back to a source.
Measuring hallucination rate is essential to trust your system.
Faithfulness vs Correctness
Two different things to measure:
- Faithfulness — is the answer supported by the provided context?
- Correctness — is the answer factually true in the real world?
A RAG answer can be correct but unfaithful (right by luck) or faithful but wrong (the source was wrong).
Claim Decomposition
To check faithfulness, break the answer into atomic claims, then verify each against the context.
answer = 'Paris is the capital of France and has 5 million people.'
claims = [c.strip() for c in answer.replace(' and ', '. ').split('.') if c.strip()]
for c in claims:
print('CLAIM:', c)Context Entailment
For each claim, ask: does the retrieved context entail it? An NLI model or an LLM judge labels each claim as supported, contradicted, or not-mentioned.
- Supported = grounded
- Not-mentioned = potential hallucination
- Contradicted = definite error
LLM-as-Judge for Faithfulness
A common pattern: prompt a strong model with the context, the answer, and ask it to score whether the answer is fully supported. Calibrate the judge against human labels.
Computing Hallucination Rate
Hallucination rate = fraction of claims (or answers) that are unsupported.
labels = ['supported', 'supported', 'not_mentioned', 'contradicted']
bad = sum(1 for x in labels if x != 'supported')
rate = bad / len(labels)
print('Hallucination rate:', round(rate, 2))Citation Coverage
If your system outputs citations, you can measure citation coverage: the share of sentences that point to a retrieved chunk that actually supports them. Low coverage signals hallucination risk.
Detecting Missing Context
Many hallucinations happen because retrieval failed and the model filled the gap. Track cases where the context lacks the answer but the model still answered confidently instead of saying 'I do not know'.
A Simple Faithfulness Score
Aggregate per-claim labels into a single score per answer.
def faithfulness(labels):
return sum(1 for x in labels if x == 'supported') / len(labels)
print(faithfulness(['supported', 'supported', 'not_mentioned']))Reducing Hallucinations
Once measured, reduce hallucinations by:
- Improving retrieval recall
- Instructing the model to abstain when unsupported
- Requiring inline citations
- Post-hoc filtering of unsupported claims
Tracking Over Time
Add hallucination rate to your regular eval runs. Watch it on every prompt or model change so a regression is caught before it reaches users.
Quick Check
Test your understanding of faithfulness.
Recap
You learned to detect hallucinations by separating faithfulness from correctness, decomposing answers into claims, checking entailment against context with an LLM judge, and computing a hallucination rate. Track it over time and reduce it with better retrieval, abstention, and citations.
Häufig gestellte Fragen
Ist die Lektion „Halluzinationen erkennen und messen“ kostenlos?
Ja — der vollständige Text von „Halluzinationen erkennen und messen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des LLM Apps in Production (RAG + Vector DB + Caching)-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der LLM Apps in Production (RAG + Vector DB + Caching)-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Halluzinationen erkennen und messen“?
Lernen Sie praxisnahe Techniken, um zu erkennen, wann ein RAG-System Fakten erfindet, die vom abgerufenen Kontext nicht gestützt werden, und die Halluzinationsrate als Teil der Evaluierung zu quantif… Du übst LLM Apps in Production (RAG + Vector DB + Caching) mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um LLM Apps in Production (RAG + Vector DB + Caching) zu starten?
Keine Vorkenntnisse erforderlich. LLM Apps in Production (RAG + Vector DB + Caching) auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Halluzinationen erkennen und messen“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser LLM Apps in Production (RAG + Vector DB + Caching)-Lektion Code schreiben und ausführen?
Ja. Jede LLM Apps in Production (RAG + Vector DB + Caching)-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Wichtige Metriken für die RAG-Leistung
- Evaluationsbenchmarks entwickeln
- A/B-Tests und Feedbackschleifen
- Halluzinationen erkennen und messen