المستوى: متقدّم · الدرس 11 من 14
أهداف الدرس
- أن تحسّن دقّة الاسترجاع.
- أن تعرف البحث الهجين وإعادة الترتيب والاسترجاع الوكيلي.
البحث بالمعنى وحده قد يفوّت رقم مادة أو اسماً دقيقاً، والبحث بالكلمات وحده يفوّت المرادفات. الحل: بحث هجين يجمعهما، ثم إعادة ترتيب بنموذج يقرأ السؤال والقطعة معاً.
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
- Make retrieval more accurate.
- 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']| Technique | The idea |
|---|---|
| Hybrid search | Words + meaning, then merge both rankings |
| Reranking | A precise model re-orders the top 20 results |
| Contextual retrieval | Add a sentence to each chunk explaining where it sits in its document |
| Query rewriting | Turn a casual question into clearer search queries |
| GraphRAG | Link entities and relations for questions spanning many sources |
| Agentic RAG | The 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.