การสร้างแบบเสริมด้วยการค้นคืน (RAG)
ผสานข้อมูลของคุณเองเข้ากับ LLM ด้วยการค้นคืนเอกสารที่เกี่ยวข้องและแทรกเอกสารเหล่านั้นลงในพรอมต์ เพื่อสร้างคำตอบที่อ้างอิงข้อมูลจริงและเป็นปัจจุบัน
การสร้างแบบเสริมด้วยการค้นคืน (RAG) เป็นบทเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Powered SaaS: Stripe + Auth + Billing + Deploy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
What is RAG?
Retrieval-Augmented Generation gives an LLM access to external knowledge at query time. Instead of relying only on training data, you fetch relevant text and add it to the prompt.
- Answers stay current without retraining
- Reduces hallucinations
- Lets the model cite your private documents
The RAG Pipeline
A typical pipeline has two phases:
- Indexing: split documents into chunks, embed them, store vectors
- Retrieval + generation: embed the query, find similar chunks, feed them to the LLM
Chunking Documents
Split long documents into smaller chunks (often 200-500 tokens) with slight overlap. Good chunking keeps related ideas together so retrieval returns coherent context.
Creating Embeddings
An embedding model turns text into a numeric vector. Similar meanings produce nearby vectors. You embed every chunk during indexing.
const emb = await client.embeddings.create({
model: "text-embedding-3-small",
input: chunkText,
});
const vector = emb.data[0].embedding;Storing Vectors
Vectors live in a vector database such as pgvector, Pinecone, or Qdrant. Each record stores the vector plus metadata (source, title, chunk id) for later filtering and citation.
Retrieving Relevant Chunks
At query time you embed the user question and run a similarity search (cosine distance) to get the top-k closest chunks.
SELECT content FROM docs
ORDER BY embedding <=> $1
LIMIT 5;Building the Augmented Prompt
Insert the retrieved chunks into the prompt as context, then ask the model to answer using only that context.
const prompt = "Context:\n" + chunks.join("\n---\n") +
"\n\nQuestion: " + userQuestion +
"\nAnswer using only the context above.";Citing Sources
Because each chunk carries metadata, you can show citations next to the answer. This builds trust and lets users verify claims against the original document.
Handling No Good Match
If similarity scores are all low, the knowledge base probably lacks the answer. Detect this with a threshold and have the model reply that it does not know, rather than guessing.
Keeping the Index Fresh
When source documents change, re-embed and upsert the affected chunks. Track a content hash per chunk so you only re-index what actually changed, saving embedding cost.
Evaluating RAG Quality
Measure two things: retrieval quality (did we fetch the right chunks?) and answer quality (is the response grounded?). Use a test set of question and answer pairs and check whether the cited chunks contain the supporting facts.
Quick Check
Check your understanding of RAG.
Recap
You learned the full RAG flow:
- Chunk and embed documents into a vector store
- Embed the query and retrieve top-k similar chunks
- Augment the prompt and answer with citations
- Handle low-confidence matches and keep the index fresh
RAG grounds your AI features in your own data without retraining.
เรียนรู้ AI Powered SaaS: Stripe + Auth + Billing + Deploy ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 12
- บทเรียน
- 48
คำถามที่พบบ่อย
บทเรียน “การสร้างแบบเสริมด้วยการค้นคืน (RAG)” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การสร้างแบบเสริมด้วยการค้นคืน (RAG)” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Powered SaaS: Stripe + Auth + Billing + Deploy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Powered SaaS: Stripe + Auth + Billing + Deploy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การสร้างแบบเสริมด้วยการค้นคืน (RAG)”
ผสานข้อมูลของคุณเองเข้ากับ LLM ด้วยการค้นคืนเอกสารที่เกี่ยวข้องและแทรกเอกสารเหล่านั้นลงในพรอมต์ เพื่อสร้างคำตอบที่อ้างอิงข้อมูลจริงและเป็นปัจจุบัน คุณปฏิบัติ AI Powered SaaS: Stripe + Auth + Billing + Deploy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Powered SaaS: Stripe + Auth + Billing + Deploy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การสร้างแบบเสริมด้วยการค้นคืน (RAG)” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy นี้ได้ไหม
ได้ บทเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การปรับแต่ง LLMs
- การประมวลผลปัญญาประดิษฐ์แบบเรียลไทม์
- การตรวจสอบประสิทธิภาพของปัญญาประดิษฐ์
- การสร้างแบบเสริมด้วยการค้นคืน (RAG)