
إمتى RAG وإمتى Fine-tuning؟ ليه الـ Fine-tuning مش الطريقة لتعليم الموديل مستنداتك
- كاتب موثّق
محتويات المقال
الفكرة الغلط الشائعة
الـ pretraining علّم الموديل معلوماته من النص، فـ training أكتر على نصك المفروض يضيف معلوماتك. الموديل بعد الـ fine-tuning بيتغيّر بشكل واضح: بياخد مصطلحاتك وشكل الكتابة والنبرة، فيبان إنه اتعلّم المحتوى. الـ fine-tuning بقى script قصير أو كام click على منصات كتير. الـ retrieval شكله حل مؤقت. "إنك تلزق المستندات في الـ prompt" إحساسه أقل ثبات من training حقيقي.
اللي بيحصل فعلًا
المعرفة ليها مكانين
الـ fine-tuning على المستندات اتقاس فعلًا
ليه مرة واحدة على مستنداتك مش بتثبت
الـ retrieval بيحط المعلومة قدام الموديل
الـ fine-tuning معمول لإيه أصلًا
نفس السؤال، مرة من الـ weights ومرة من المستندات
search_result blocks والـ citations شغالة.
import anthropicclient = anthropic.Anthropic()reply = client.messages.create( model="claude-opus-5-5", max_tokens=16000, messages=[{"role": "user", "content": QUESTION}],)# Fine-tuned or not, the answer comes from the weights alone: no page# behind it, and a policy change means a new training run.print(next(b.text for b in reply.content if b.type == "text"))import anthropicclient = anthropic.Anthropic()hits = search_handbook(QUESTION, user=employee, k=5) # pages they may readresults = [ {"type": "search_result", "source": h.source, "title": h.title, "content": [{"type": "text", "text": h.text}], "citations": {"enabled": True}} for h in hits]reply = client.messages.create( model="claude-opus-5-5", max_tokens=16000, system="Answer only from the search results. If they don't cover the " "question, say the handbook doesn't answer it.", messages=[{"role": "user", "content": [*results, {"type": "text", "text": QUESTION}]}],)for block in reply.content: if block.type == "text": # cited blocks name the page they came from print(block.text, [c.source for c in block.citations or []])search_result blocks للحالة دي بالظبط: كل واحد محتاج source وtitle وcontent نصي. الـ citations مقفولة بشكل افتراضي، وكل الـ search results في الـ request لازم يبقى ليها نفس الإعداد. ولما تشغّلها، الـ text blocks اللي معتمدة على المحتوى بتاعك بييجي معاها citations من نوع search_result_location، فيها الـ source والـ title اللي إنت بعتهم. فأي إجابة غلط بقت بتشاور على صفحة تقدر تفتحها.
تطبقها إزاي في مشروعك
ابني الـ index قبل أي training set قسّم المستندات لـ passages، وخزّن مع كل واحد المصدر والنسخة والمسؤول عنه ومين مسموحله يشوفه. ده هو طبقة المعرفة بتاعتك. فلتر بالصلاحيات وقت البحث هات بس من المستندات اللي المستخدم الحالي مسموحله يقراها، فالـ access control يبقى في query واحدة مش في الـ prompt. اطلب مصدر مع كل إجابة ابعت الـ passages كـ search_resultblocks والـ citations شغالة، وقول للموديل يجاوب منها بس، واعتبر أي كلام من غير citation إنه bug.اعمل re-index مع كل تغيير اربط سيستم المستندات بحيث أي صفحة تتعدّل أو تتمسح تتحدّث في الـ index أو تتشال في دقايق، مش مع الـ release الجاية. اعمل fine-tuning للسلوك بس، والـ retrieval جوه الـ loop لو شكل الإجابة أو أسلوبها لسه مش مظبوط بعد الـ prompting، اعمل fine-tuning على أمثلة فيها passages متجابة بالـ retrieval، وشوية منها ملهاش لازمة، زي ما RAFT عمل.
الخلاصة
الـ fine-tuning على المستندات بيعلّم أسلوبها أوثق بكتير من معلوماتها. في اختبارات Ovadia وزمايله سنة 2023 على تلات موديلات 7B، الـ RAG غلب الـ fine-tuning في المعلومات القديمة والجديدة. المعلومات الجديدة مش بتثبت إلا بتكرار كتير، والـ training عليها ممكن يزوّد الـ hallucination. الـ retrieval بيخلّي المعرفة قابلة للتحديث والفلترة لكل مستخدم والـ citation، من غير ما تلمس الـ weights. اعمل fine-tuning للسلوك، ومنه إزاي الموديل يقرا الـ passages، وهات المعلومات بالـ retrieval.
📚 المصادر
Ovadia et al., Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMs, arXiv:2312.05934 Gekhman et al., Does Fine-Tuning LLMs on New Knowledge Encourage Hallucinations?, arXiv:2405.05904 Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, arXiv:2005.11401 Zhang et al., RAFT: Adapting Language Model to Domain Specific RAG, arXiv:2403.10131 Search results — Claude API Docs
التعليقات (0)