0Pricing
LLM Apps in Production (RAG + Vector DB + Caching) · レッスン

ハルシネーションの検出と測定

RAGシステムが取得したコンテキストに裏付けられていない事実を生成したタイミングを検出する実践的な技術と、評価の一環としてハルシネーション率を定量化する方法を学びます。

「ハルシネーションの検出と測定」はCoddyKit上の無料LLM Apps in Production (RAG + Vector DB + Caching)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLLM Apps in Production (RAG + Vector DB + Caching)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 LLM Apps in Production (RAG + Vector DB + Caching)コースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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.

よくある質問

「ハルシネーションの検出と測定」レッスンは無料ですか?

はい。「ハルシネーションの検出と測定」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、LLM Apps in Production (RAG + Vector DB + Caching)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 LLM Apps in Production (RAG + Vector DB + Caching)コースには全4レッスンが含まれています。

「ハルシネーションの検出と測定」で何を学びますか?

RAGシステムが取得したコンテキストに裏付けられていない事実を生成したタイミングを検出する実践的な技術と、評価の一環としてハルシネーション率を定量化する方法を学びます。 ブラウザで直接実行するハンズオンコードでLLM Apps in Production (RAG + Vector DB + Caching)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

LLM Apps in Production (RAG + Vector DB + Caching)を始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのLLM Apps in Production (RAG + Vector DB + Caching)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「ハルシネーションの検出と測定」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このLLM Apps in Production (RAG + Vector DB + Caching)レッスンでコードを書いて実行できますか?

はい。すべてのLLM Apps in Production (RAG + Vector DB + Caching)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. RAG性能の主要指標
  2. 評価ベンチマークの開発
  3. A/Bテストとユーザーフィードバックループ
  4. ハルシネーションの検出と測定
← LLM Apps in Production (RAG + Vector DB + Caching)に戻る