0Pricing
LLM Apps in Production (RAG + Vector DB + Caching) · บทเรียน

การค้นหาด้วยตนเองและการอ้างอิงแหล่งที่มา

ต่อยอด RAG ด้วยตัวดึงข้อมูลที่แปลงภาษาธรรมชาติเป็นตัวกรองข้อมูลกำกับ และสร้างคำตอบที่อ้างอิงแหล่งที่มา เพื่อให้ผู้ใช้เชื่อถือและตรวจสอบได้

การค้นหาด้วยตนเองและการอ้างอิงแหล่งที่มา เป็นบทเรียน LLM Apps in Production (RAG + Vector DB + Caching) ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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.

คำถามที่พบบ่อย

บทเรียน “การค้นหาด้วยตนเองและการอ้างอิงแหล่งที่มา” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การค้นหาด้วยตนเองและการอ้างอิงแหล่งที่มา” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 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) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การเขียนคำค้นใหม่และการจัดอันดับซ้ำ
  2. รูปแบบ RAG หลายขั้นตอนและแบบใช้เอเจนต์
  3. การจัดการโครงสร้างเอกสารที่ซับซ้อน
  4. การค้นหาด้วยตนเองและการอ้างอิงแหล่งที่มา
← กลับไปที่ LLM Apps in Production (RAG + Vector DB + Caching)