0Pricing
LLM Apps in Production (RAG + Vector DB + Caching) · درس

الاستعلام الذاتي والاستشهادات

طوّر RAG باستخدام مسترجعات الاستعلام الذاتي التي تحوّل اللغة الطبيعية إلى مرشحات للبيانات الوصفية، وإجابات تستشهد بمصادرها حتى يتمكن المستخدمون من الوثوق بها والتحقق منها.

الاستعلام الذاتي والاستشهادات درس مجاني في LLM Apps in Production (RAG + Vector DB + Caching) على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في LLM Apps in Production (RAG + Vector DB + Caching)، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة LLM Apps in Production (RAG + Vector DB + Caching) 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

When Questions Carry Filters

Users ask things like give me 2023 reports about pricing. That sentence contains a filter (year 2023) and a semantic query (pricing).

A self-querying retriever automatically separates the two.

How Self-Querying Works

An LLM reads the question and emits a structured query: the semantic search string plus a metadata filter. The retriever then applies both to the vector store.

Describing Your Metadata

You tell the retriever what fields exist so it knows what it can filter on.

from langchain.chains.query_constructor.schema import AttributeInfo

fields = [
    AttributeInfo(name='year', description='Publication year', type='integer'),
    AttributeInfo(name='topic', description='Document topic', type='string')
]

Building the Retriever

Combine the LLM, the store, a content description, and the field info into a self-query retriever.

from langchain.retrievers.self_query.base import SelfQueryRetriever

retriever = SelfQueryRetriever.from_llm(
    llm, vectorstore,
    'Company reports', fields
)

Seeing It in Action

Now a natural-language question is split into a filter and a search automatically — no manual filter code.

docs = retriever.invoke(
    'pricing reports from 2023'
)

Why Citations Matter

In production, users must be able to verify answers. Unsourced answers are hard to trust and hide hallucinations. Citations link each claim back to its document.

Carrying Source Metadata

Citations rely on each chunk storing where it came from — file name, page, or URL — in its metadata. Set this at load time.

doc.metadata['source'] = 'policy.pdf#p3'

Prompting for Citations

Number the context chunks and ask the model to cite the numbers it used. This is simple and reliable.

ctx = '\n'.join(
    f'[{i}] {d.page_content}'
    for i, d in enumerate(docs)
)
# 'Cite sources like [1] after each claim.'

Mapping Numbers to Sources

After generation, map the cited numbers back to real source metadata so the UI can show clickable references.

sources = {i: d.metadata['source']
           for i, d in enumerate(docs)}

Verifying Citations

Models sometimes cite wrong or nonexistent sources. A safety check confirms each cited chunk actually supports the claim, flagging unsupported statements.

Putting It Together

Self-querying gets the right documents using filters in the question; citations make the resulting answer transparent. Together they raise both precision and trust in advanced RAG.

Quick Check

Test your advanced RAG knowledge.

Recap

You learned two advanced RAG techniques:

  • Self-querying turns natural language into metadata filters plus a semantic query
  • Describe your fields so the LLM knows what to filter
  • Citations link claims to sources for trust
  • Carry source metadata, prompt for citations, and verify them

Filtering and citing together make RAG both precise and trustworthy.

الأسئلة الشائعة

هل درس «الاستعلام الذاتي والاستشهادات» مجاني؟

نعم — نص درس «الاستعلام الذاتي والاستشهادات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة LLM Apps in Production (RAG + Vector DB + Caching)، انتقل إلى CoddyKit PRO. تتضمن دورة LLM Apps in Production (RAG + Vector DB + Caching) 4 دروس في المجموع.

ماذا ستتعلم في «الاستعلام الذاتي والاستشهادات»؟

طوّر RAG باستخدام مسترجعات الاستعلام الذاتي التي تحوّل اللغة الطبيعية إلى مرشحات للبيانات الوصفية، وإجابات تستشهد بمصادرها حتى يتمكن المستخدمون من الوثوق بها والتحقق منها. تتمرن على LLM Apps in Production (RAG + Vector DB + Caching) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ LLM Apps in Production (RAG + Vector DB + Caching)؟

لا تُشترط خبرة سابقة. LLM Apps in Production (RAG + Vector DB + Caching) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «الاستعلام الذاتي والاستشهادات»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس LLM Apps in Production (RAG + Vector DB + Caching) هذا؟

نعم. كل درس في LLM Apps in Production (RAG + Vector DB + Caching) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. إعادة صياغة الاستعلامات وإعادة ترتيب النتائج
  2. أنماط RAG متعددة المراحل والوكلائية
  3. التعامل مع هياكل المستندات المعقدة
  4. الاستعلام الذاتي والاستشهادات
← العودة إلى LLM Apps in Production (RAG + Vector DB + Caching)