RAG المتقدّم / Advanced RAG

الترتيب / Order
11 من 14 / 11 of 14
آخر تحديث / Updated
8 أكتوبر 2026 / 8 October 2026

المستوى: متقدّم · الدرس 11 من 14

أهداف الدرس

  1. أن تحسّن دقّة الاسترجاع.
  2. أن تعرف البحث الهجين وإعادة الترتيب والاسترجاع الوكيلي.

البحث بالمعنى وحده قد يفوّت رقم مادة أو اسماً دقيقاً، والبحث بالكلمات وحده يفوّت المرادفات. الحل: بحث هجين يجمعهما، ثم إعادة ترتيب بنموذج يقرأ السؤال والقطعة معاً.

Python
def rrf(rankings, k=60):
    """Reciprocal Rank Fusion: merge several ranked lists into one."""
    scores = {}
    for ranking in rankings:
        for rank, doc in enumerate(ranking, start=1):
            scores[doc] = scores.get(doc, 0) + 1 / (k + rank)
    return sorted(scores, key=scores.get, reverse=True)

keyword  = ["d3", "d1", "d7"]   # word-match search
semantic = ["d1", "d5", "d3"]   # meaning search
print(rrf([keyword, semantic]))  # ['d1', 'd3', 'd5', 'd7']
التقنيةالفكرة
بحث هجينكلمات + معنى، ثم دمج الترتيبين
إعادة الترتيبنموذج دقيق يرتّب أفضل 20 نتيجة من جديد
استرجاع سياقينضيف لكل قطعة جملة تشرح موضعها من المستند
إعادة صياغة السؤالنحوّل السؤال العامّي إلى صيغ بحث أوضح
استرجاع بالرسم المعرفينربط الكيانات والعلاقات للأسئلة التي تجمع مصادر كثيرة
استرجاع وكيليالنموذج يقرّر أن يبحث مرة أخرى إن لم تكفِه النتائج
  • الأمانة: هل الإجابة من المصادر فعلاً؟
  • الصلة: هل أجابت عن السؤال؟
  • الاسترجاع: هل جاءت القطع الصحيحة؟

تمرين

سأل طالب «متى ITDB 2301؟» فلم يجد البحث بالمعنى شيئاً. ما الحل؟

الإجابة

البحث الهجين: البحث بالكلمات يطابق رمز المادة حرفياً.

Level: Advanced · Lesson 11 of 14

Lesson goals

  1. Make retrieval more accurate.
  2. Know hybrid search, reranking and agentic retrieval.

Meaning-only search can miss an exact course code or name; word-only search misses synonyms. The answer: hybrid search combining both, then reranking with a model that reads the question and chunk together.

Python
def rrf(rankings, k=60):
    """Reciprocal Rank Fusion: merge several ranked lists into one."""
    scores = {}
    for ranking in rankings:
        for rank, doc in enumerate(ranking, start=1):
            scores[doc] = scores.get(doc, 0) + 1 / (k + rank)
    return sorted(scores, key=scores.get, reverse=True)

keyword  = ["d3", "d1", "d7"]   # word-match search
semantic = ["d1", "d5", "d3"]   # meaning search
print(rrf([keyword, semantic]))  # ['d1', 'd3', 'd5', 'd7']
TechniqueThe idea
Hybrid searchWords + meaning, then merge both rankings
RerankingA precise model re-orders the top 20 results
Contextual retrievalAdd a sentence to each chunk explaining where it sits in its document
Query rewritingTurn a casual question into clearer search queries
GraphRAGLink entities and relations for questions spanning many sources
Agentic RAGThe model decides to search again if results are not enough
  • Faithfulness: is the answer really from the sources?
  • Relevance: did it answer the question?
  • Recall: did the right chunks come back?

Exercise

A student asked «when is ITDB 2301?» and meaning search found nothing. The fix?

Answer

Hybrid search: word search matches the course code exactly.

التعليقات / Comments

لا تعليقات بعد. كن أول من يسأل. / No comments yet. Be the first to ask.

تعليق الطالب يظهر فوراً، وتعليق الزائر بعد موافقة المدرّس. / A student's comment shows at once; a visitor's once the teacher approves it.

في «الذكاء الاصطناعي: من الصفر إلى الاحتراف» / In “AI: from zero to hero”

  1. 1ما الذكاء الاصطناعي التوليدي؟ / What is generative AI?فيها صور / has picturesالتعليقات مفتوحة / comments open
  2. 2الرموز والتضمينات / Tokens and embeddingsفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  3. 3المحوّل والانتباه / Transformers and attentionفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  4. 4التدريب المسبق / Pre-trainingفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  5. 5الضبط بالتعليمات / Instruction tuning (SFT)فيها كود / has codeالتعليقات مفتوحة / comments open
  6. 6التعلّم من التفضيلات / Learning from preferencesفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  7. 7نماذج الاستدلال / Reasoning modelsفيها كود / has codeالتعليقات مفتوحة / comments open
  8. 8الضبط الدقيق الفعّال / Efficient fine-tuningفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  9. 9هندسة الأوامر والسياق / Prompt and context engineeringفيها كود / has codeالتعليقات مفتوحة / comments open
  10. 10الاسترجاع المعزّز (RAG) من الصفر / RAG from scratchفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  11. 11RAG المتقدّم / Advanced RAGفيها كود / has codeالتعليقات مفتوحة / comments open
  12. 12الوكلاء والأدوات / Agents and toolsفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  13. 13التقييم والأمان / Evaluation and safetyفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  14. 14مشروع ختامي: مساعد عربي / Capstone: an Arabic assistantفيها كود / has codeفيها صور / has picturesفيها نموذج / has a formالتعليقات مفتوحة / comments open

↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق↑ ↓ to move · Enter to open · Esc to close