0Pricing
LangChain / RAG / Vector DBs · レッスン

RAG 用のゴールデンテストセットを作成する

RAG の品質を長期的に客観測定・比較できる、厳選された質問と回答のデータセットを作成します。

「RAG 用のゴールデンテストセットを作成する」はCoddyKit上の無料LangChain / RAG / Vector DBsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLangChain / RAG / Vector DBs学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 LangChain / RAG / Vector DBsコースには全4レッスンが含まれています。

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

Why You Need a Test Set

Eyeballing a few answers does not tell you if a change helped or hurt. A golden test set of question-answer pairs gives you repeatable, comparable measurements.

Anatomy of a Test Case

Each case captures what to ask, what is correct, and where the answer lives.

  • question
  • ground_truth answer
  • relevant_sources (expected docs)

A Sample Dataset

Store cases as simple records you can load and iterate over.

testset = [
    {"question": "What is the refund window?",
     "ground_truth": "30 days from purchase.",
     "sources": ["policy.pdf#p2"]},
    {"question": "Who approves expenses?",
     "ground_truth": "The department manager.",
     "sources": ["handbook.pdf#p7"]},
]

Manual vs. Synthetic

You can write cases by hand for accuracy, or generate them by prompting an LLM over your documents for scale. A hybrid approach is common: generate, then review.

Generating Questions with an LLM

Feed a chunk to the model and ask it to produce a question whose answer is contained in that chunk, plus the answer itself.

prompt = (
  "Read the passage and write one question a user might ask, "
  "plus the exact answer.\n\nPassage: " + chunk.page_content
)
qa = llm.invoke(prompt)

Reviewing Synthetic Cases

LLM-generated pairs can be ambiguous or unanswerable. Human review filters out weak cases before they pollute your metrics.

Retrieval vs. Generation Metrics

Separate two questions: did we fetch the right docs (retrieval), and did we write the right answer (generation)? Each is measured differently.

Context Recall

Context recall checks whether the expected source appears among the retrieved chunks. It isolates retrieval quality from the LLM.

def context_recall(retrieved_ids, expected_ids):
    hits = sum(1 for e in expected_ids if e in retrieved_ids)
    return hits / len(expected_ids)

Answer Correctness

Compare the generated answer to the ground truth. Exact match is brittle, so use an LLM judge or semantic similarity for fuzzy correctness.

judge_prompt = (
  "Is the ANSWER correct given the REFERENCE? Reply yes or no.\n"
  "REFERENCE: " + truth + "\nANSWER: " + answer
)
verdict = llm.invoke(judge_prompt)

Running the Suite

Loop over every case, run your pipeline, and aggregate scores so one number summarizes the whole system.

scores = []
for case in testset:
    docs = retriever.invoke(case["question"])
    ans = rag_chain.invoke(case["question"])
    scores.append(evaluate(case, docs, ans))
print(sum(scores) / len(scores))

Track Results Over Time

Save each run with a timestamp and the config used. When a metric drops, you can pinpoint the change that caused the regression.

Quick Check

Test your understanding of RAG evaluation.

Recap

You built an evaluation foundation:

  • A golden test set of question, ground truth, and sources
  • Generate then review synthetic cases
  • Measure retrieval (context recall) and generation (answer correctness) separately
  • Track scores across runs

よくある質問

「RAG 用のゴールデンテストセットを作成する」レッスンは無料ですか?

はい。「RAG 用のゴールデンテストセットを作成する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、LangChain / RAG / Vector DBsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 LangChain / RAG / Vector DBsコースには全4レッスンが含まれています。

「RAG 用のゴールデンテストセットを作成する」で何を学びますか?

RAG の品質を長期的に客観測定・比較できる、厳選された質問と回答のデータセットを作成します。 ブラウザで直接実行するハンズオンコードでLangChain / RAG / Vector DBsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

LangChain / RAG / Vector DBsを始めるのに経験は必要ですか?

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

「RAG 用のゴールデンテストセットを作成する」レッスンにはどのくらい時間がかかりますか?

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

このLangChain / RAG / Vector DBsレッスンでコードを書いて実行できますか?

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

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

  1. RAGコンポーネントの統合
  2. クエリ処理と回答生成
  3. RAGシステムの性能評価
  4. RAG 用のゴールデンテストセットを作成する
← LangChain / RAG / Vector DBsに戻る