Ein Golden Test Set für RAG erstellen
Erstellen Sie einen kuratierten Frage-Antwort-Datensatz, mit dem Sie die RAG-Qualität objektiv über die Zeit messen und vergleichen können.
Ein Golden Test Set für RAG erstellen ist eine kostenlose LangChain / RAG / Vector DBs-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 LangChain / RAG / Vector DBs-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der LangChain / RAG / Vector DBs-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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.
questionground_truthanswerrelevant_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
Häufig gestellte Fragen
Ist die Lektion „Ein Golden Test Set für RAG erstellen“ kostenlos?
Ja — der vollständige Text von „Ein Golden Test Set für RAG erstellen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des LangChain / RAG / Vector DBs-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der LangChain / RAG / Vector DBs-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Ein Golden Test Set für RAG erstellen“?
Erstellen Sie einen kuratierten Frage-Antwort-Datensatz, mit dem Sie die RAG-Qualität objektiv über die Zeit messen und vergleichen können. Du übst LangChain / RAG / Vector DBs 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 LangChain / RAG / Vector DBs zu starten?
Keine Vorkenntnisse erforderlich. LangChain / RAG / Vector DBs 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 „Ein Golden Test Set für RAG erstellen“?
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 LangChain / RAG / Vector DBs-Lektion Code schreiben und ausführen?
Ja. Jede LangChain / RAG / Vector DBs-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
- Alle RAG-Komponenten integrieren
- Anfragen verarbeiten und Antworten generieren
- Die Leistung eines RAG-Systems bewerten
- Ein Golden Test Set für RAG erstellen