التوليد المعزّز بالاسترجاع (RAG)
في هذه الصفحة 8 موضوعات
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
نظرة عامة
الموضوعات
- التقطيع (Chunking)
- الاسترجاع
- تجميع السياق
- الاستشهادات
- إبقاء الفهرس محدّثًا بالأحداث
- جودة الاسترجاع
تعلّم أولًا
3.5 ساعة تدريب (تقدير)
مخرجات التعلم
- Explain why retrieval-augmented generation (RAG) grounds model answers in your own data and where it still fails.
- Chunk documents with sensible size, overlap, and metadata, and retrieve with filters (e.g., language, product, customer tier).
- Assemble a prompt from retrieved chunks with source citations, and make the assistant say "I don't know" when retrieval finds nothing relevant.
- Keep the index fresh by re-embedding on change events instead of nightly full rebuilds.
- Measure retrieval quality (recall of the right chunk) separately from answer quality.
الدروس
المختبر والتمارين
Lab
MID-068-LAB1 · Order-support assistant v1
Outcomes: 1–5 · Time: ~3.5 h Answer customer questions about shipping, returns, and payment policies from the MID-067 index, citing the source articles. When an article changes, a HelpArticleUpdated event re-embeds only that article. Measure retrieval recall on the question set separately from answer quality. Acceptance: every answer cites at least one source or explicitly declines; a changed policy is reflected within one minute; retrieval recall measured on the question set.
Exercises (assessment: diagnose three bad answers)
| ID | Outcome | Task |
|---|---|---|
| MID-068-EX01 | 1 | Explain in five lines why RAG helps with Shop's changing policies and list three ways it can still fail. |
| MID-068-EX02 | 2 | Chunk a 1 500-word returns article: choose size, overlap, and metadata, and justify. Add the filter for an Arabic-speaking customer. |
| MID-068-EX03 | 3 | Write the prompt for the assistant with numbered sources, citation format, and the decline rule. Say what happens when no chunk passes the threshold. |
| MID-068-EX04 | 4 | Sketch the consumer for HelpArticleUpdated: steps, idempotency, deletions, and why not a nightly rebuild. |
| MID-068-EX05 | 5 | Compute recall@4 for 20 questions where the right chunk was in the top 4 for 16; name two fixes for the misses. |
| MID-068-EX06 | 1–5 | Diagnose three bad answers from logs and fix each at the right layer: (a) right article not in retrieved ids; (b) retrieved chunk dated before the policy change; (c) right chunk retrieved but answer contradicts it. |
أظهر الحلول
- EX01 Model lacks private, current data; RAG injects it and enables citations. Failures: retrieval miss, stale chunk, model ignores context, irrelevant context, wrong filter.
- EX02 Split by headings, then to a few hundred tokens with small overlap (tune by recall); metadata: article id, section, language, product, updated time. Filter
lang = 'ar'and customer audience. - EX03 "Answer only from the sources; cite [n]; if not answered, say you could not find it." With no chunk above the threshold: skip the model call and return a fixed decline.
- EX04 Receive event, load article, chunk, compare hashes, embed only changed chunks, delete old and insert new in one transaction. Idempotent by article version or hash.
HelpArticleDeletedremoves chunks. Nightly rebuild is slow, costly, and stale for hours. - EX05 16/20 = 0.80. Fixes: add hybrid search or synonyms; adjust chunk size; add re-ranking; fix metadata filters.
- EX06 (a) Retrieval miss: fix chunking, hybrid search, filters, or threshold. (b) Stale chunk: re-index on event, check the hash comparison. (c) Ignored context: tighten the prompt, reduce irrelevant context, check the model; evaluate in MID-070.
Outcomes 3 and 5 are also covered by the quiz and the lab (citations, decline, recall measurement).
الاختبار
Outcomes: O1 RAG and its limits · O2 chunking and filters · O3 context and citations · O4 freshness · O5 retrieval evaluation.
اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.
الجزء العملي
Diagnosis exercise (MID-068-EX06) plus lab MID-068-LAB1. Pass: quiz at least 8/10, three bad answers correctly diagnosed and fixed at the right layer, and a lab where every answer cites a source or declines, a changed policy is reflected within one minute, and retrieval recall is measured.
أخطاء شائعة
Chunks so large they drown the answer; no citations, so wrong answers cannot be traced; answering from model memory when retrieval is empty; judging RAG only by how fluent the answers sound.
التقييم
Diagnose three bad answers (retrieval miss, stale chunk, ignored context) from logs and fix each at the right layer.
الصلة بالمسار الوظيفي
The most common pattern in enterprise AI features; evaluated in MID-070, secured in MID-071, operated in SRC-022.