إنشاء مجموعة اختبارات مرجعية لـ RAG
أنشئ مجموعة بيانات منتقاة من الأسئلة والإجابات تتيح لك قياس جودة RAG ومقارنتها بموضوعية بمرور الوقت.
إنشاء مجموعة اختبارات مرجعية لـ RAG درس مجاني في LangChain / RAG / Vector DBs على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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.
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
الأسئلة الشائعة
هل درس «إنشاء مجموعة اختبارات مرجعية لـ RAG» مجاني؟
نعم — نص درس «إنشاء مجموعة اختبارات مرجعية لـ RAG» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة LangChain / RAG / Vector DBs، انتقل إلى CoddyKit PRO. تتضمن دورة LangChain / RAG / Vector DBs 4 دروس في المجموع.
ماذا ستتعلم في «إنشاء مجموعة اختبارات مرجعية لـ RAG»؟
أنشئ مجموعة بيانات منتقاة من الأسئلة والإجابات تتيح لك قياس جودة RAG ومقارنتها بموضوعية بمرور الوقت. تتمرن على LangChain / RAG / Vector DBs مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ LangChain / RAG / Vector DBs؟
لا تُشترط خبرة سابقة. LangChain / RAG / Vector DBs على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «إنشاء مجموعة اختبارات مرجعية لـ RAG»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس LangChain / RAG / Vector DBs هذا؟
نعم. كل درس في LangChain / RAG / Vector DBs يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- دمج جميع مكوّنات RAG
- الاستعلام وتوليد الإجابات
- تقييم أداء نظام RAG
- إنشاء مجموعة اختبارات مرجعية لـ RAG