أساسيات التوليد المعزَّز بالاسترجاع (RAG)
تعلّم كيف يجعل RAG استجابات LLM مستندة إلى مستنداتك الخاصة، عبر استرجاع السياق ذي الصلة وقت تنفيذ الاستعلام وإدخاله في prompt.
أساسيات التوليد المعزَّز بالاسترجاع (RAG) درس مجاني في Prompt Engineering & LLM Optimization for Developers على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Prompt Engineering & LLM Optimization for Developers، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Prompt Engineering & LLM Optimization for Developers 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
The Knowledge Gap
An LLM only knows what it was trained on. It cannot answer questions about your private docs or recent events. RAG (Retrieval-Augmented Generation) closes this gap by fetching relevant text and putting it in the prompt.
The Core Idea
Instead of fine-tuning the model on your data, you retrieve the most relevant snippets at query time and let the model answer using them as context. Cheaper, faster to update, and easy to cite.
Step 1: Chunking
Documents are split into small chunks (a few hundred tokens each). Chunks small enough to be precise, large enough to keep meaning.
chunks = split(document, size=500, overlap=50)Step 2: Embeddings
Each chunk is converted to a vector with an embedding model. Similar meanings produce nearby vectors, enabling semantic search.
vector = embed("Refunds are processed in 5 days.")
// -> [0.012, -0.43, 0.88, ...]Step 3: The Vector Store
Vectors are saved in a vector database like Pinecone, Weaviate, or pgvector. It supports fast nearest-neighbor search over millions of chunks.
Step 4: Retrieve at Query Time
When a user asks a question, you embed the question and find the top-k most similar chunks.
q = embed(userQuestion);
results = store.search(q, topK=4);Step 5: Augment the Prompt
The retrieved chunks are inserted into the prompt as context, and the model is told to answer using only that context.
Use only the context below to answer.
Context:
{retrieved_chunks}
Question: {user_question}Grounding and Citations
Because the answer is built from real chunks, you can show citations back to the source documents, and you can instruct the model to say I do not know when the context lacks the answer.
Why Not Just Fine-Tune?
- RAG updates instantly: change a doc, re-index, done.
- Fine-tuning is slow and bakes knowledge in.
- RAG gives traceable sources; fine-tuning does not.
Common RAG Problems
Poor chunking, weak embeddings, or retrieving too few chunks all hurt quality. If answers are wrong, inspect what was retrieved first; the issue is usually retrieval, not the model.
Improving Retrieval
- Add overlap between chunks.
- Use hybrid keyword + vector search.
- Re-rank results with a cross-encoder.
- Tune top-k for your context window.
Quick Check
Test your understanding of RAG.
Recap
RAG chunks documents, embeds them into a vector store, retrieves the most relevant chunks for each query, and augments the prompt. It grounds answers, enables citations, and stays current without retraining.
الأسئلة الشائعة
هل درس «أساسيات التوليد المعزَّز بالاسترجاع (RAG)» مجاني؟
نعم — نص درس «أساسيات التوليد المعزَّز بالاسترجاع (RAG)» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Prompt Engineering & LLM Optimization for Developers، انتقل إلى CoddyKit PRO. تتضمن دورة Prompt Engineering & LLM Optimization for Developers 4 دروس في المجموع.
ماذا ستتعلم في «أساسيات التوليد المعزَّز بالاسترجاع (RAG)»؟
تعلّم كيف يجعل RAG استجابات LLM مستندة إلى مستنداتك الخاصة، عبر استرجاع السياق ذي الصلة وقت تنفيذ الاستعلام وإدخاله في prompt. تتمرن على Prompt Engineering & LLM Optimization for Developers مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Prompt Engineering & LLM Optimization for Developers؟
لا تُشترط خبرة سابقة. Prompt Engineering & LLM Optimization for Developers على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «أساسيات التوليد المعزَّز بالاسترجاع (RAG)»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Prompt Engineering & LLM Optimization for Developers هذا؟
نعم. كل درس في Prompt Engineering & LLM Optimization for Developers يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- التفاعل مع واجهات LLM البرمجية (OpenAI وAnthropic)
- أساسيات LangChain وLlamaIndex
- إدارة المطالبات وإصداراتها
- أساسيات التوليد المعزَّز بالاسترجاع (RAG)