พื้นฐานการสร้างแบบเสริมด้วยการค้นคืน (RAG)
เรียนรู้ว่า RAG ทำให้คำตอบของ LLM อ้างอิงเอกสารของคุณเองได้อย่างไร ด้วยการค้นคืนบริบทที่เกี่ยวข้องขณะรับคำค้นและป้อนบริบทนั้นเข้าสู่พรอมต์
พื้นฐานการสร้างแบบเสริมด้วยการค้นคืน (RAG) เป็นบทเรียน Prompt Engineering & LLM Optimization for Developers ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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)” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Prompt Engineering & LLM Optimization for Developers ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Prompt Engineering & LLM Optimization for Developers มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “พื้นฐานการสร้างแบบเสริมด้วยการค้นคืน (RAG)”
เรียนรู้ว่า RAG ทำให้คำตอบของ LLM อ้างอิงเอกสารของคุณเองได้อย่างไร ด้วยการค้นคืนบริบทที่เกี่ยวข้องขณะรับคำค้นและป้อนบริบทนั้นเข้าสู่พรอมต์ คุณปฏิบัติ Prompt Engineering & LLM Optimization for Developers ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 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 ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การโต้ตอบกับ API ของ LLM (OpenAI, Anthropic)
- พื้นฐาน LangChain และ LlamaIndex
- การจัดการและการกำหนดเวอร์ชันพรอมต์
- พื้นฐานการสร้างแบบเสริมด้วยการค้นคืน (RAG)