Tworzenie wzorcowego zbioru testowego dla RAG
Utwórz wyselekcjonowany zbiór pytań i odpowiedzi, który pozwoli obiektywnie mierzyć i porównywać jakość RAG w czasie.
Tworzenie wzorcowego zbioru testowego dla RAG to bezpłatna lekcja LangChain / RAG / Vector DBs na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej LangChain / RAG / Vector DBs, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs LangChain / RAG / Vector DBs zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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
Często zadawane pytania
Czy lekcja „Tworzenie wzorcowego zbioru testowego dla RAG” jest bezpłatna?
Tak — pełny tekst „Tworzenie wzorcowego zbioru testowego dla RAG” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu LangChain / RAG / Vector DBs, przejdź na CoddyKit PRO. Kurs LangChain / RAG / Vector DBs zawiera 4 lekcji w sumie.
Co nauczysz się w „Tworzenie wzorcowego zbioru testowego dla RAG”?
Utwórz wyselekcjonowany zbiór pytań i odpowiedzi, który pozwoli obiektywnie mierzyć i porównywać jakość RAG w czasie. Ćwiczysz LangChain / RAG / Vector DBs z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć LangChain / RAG / Vector DBs?
Nie wymagamy żadnego doświadczenia. LangChain / RAG / Vector DBs w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Tworzenie wzorcowego zbioru testowego dla RAG”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji LangChain / RAG / Vector DBs?
Tak. Każda lekcja LangChain / RAG / Vector DBs zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Integracja wszystkich komponentów RAG
- Wykonywanie zapytań i generowanie odpowiedzi
- Ocena wydajności systemu RAG
- Tworzenie wzorcowego zbioru testowego dla RAG