Thuta Learning
ရှာဖွေရန်
ExercisesAIbeginner

Level-Up Practice — RAG ပေါင်းစပ် စမ်းသပ်ခန်း

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Level-Up Practice — RAG ပေါင်းစပ် စမ်းသပ်ခန်း ကို ကိုယ်တိုင် လေ့ကျင့်ကြည့်မယ်
  • သင်ခဲ့ပြီးသား skill တွေကို practice လုပ်ပြီး ခိုင်မာအောင်လုပ်မယ်
  • အမှားရှာ၊ ပြင်တတ်၊ ကိုယ်တိုင် check လုပ်တတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

ဒီ round ကတော့ round-one ထက် တစ်ဆင့်တက်ပါတယ်။ Skill တစ်ခုချင်းစီကို သီးခြားမကျင့်တော့ဘဲ၊ real RAG app တစ်ခုမှာ ဖြစ်လေ့ဖြစ်ထ ရှိတဲ့ scenario တွေကို ပေါင်းစပ်ပြီး ကိုင်တွယ်ကြည့်ပါမယ်။ Grounded answer ရေးတာ၊ source ကို cite လုပ်တာ၊ document ထဲက secret ကို leak မဖြစ်အောင် စစ်တာ၊ document မတွေ့တဲ့အခါ "I don't know" လို့ ရိုးသားစွာ ပြန်ပြောတာ — ဒါတွေအားလုံးက production RAG app တစ်ခု trustworthy ဖြစ်ဖို့ လိုအပ်တဲ့ core skill တွေပါ။ Test case တွေကို ကိုယ်တိုင်ရေးပြီး ကိုယ့် logic ကို ကိုယ်တိုင် စစ်ကြည့်ရမယ့် lesson ပါ။

လေ့ကျင့်ခန်းများ

Task 1: Retrieved chunk ၃ ခုပါတဲ့ sample context ကို ကြည့်ပြီး, chunk ထဲက vocab ကိုပဲ သုံးပြီး citation number [1][2] ပါတဲ့ grounded answer တစ်ပုဒ် ကိုယ်တိုင်ရေးကြည့်ပါ။ Task 2: Sample document တစ်ခုထဲမှာ phone number, password, student ID ပါတဲ့ paragraph ကို ဖော်ပြပြီး၊ ဘယ် sentence တွေကို ingest မလုပ်ဘဲ filter ချရမလဲ ရွေးထုတ်ပါ။ Task 3: Query တစ်ခုကို retrieve() ကနေ empty result (chunk ဘာမှမတွေ့) ပြန်လာအောင် simulate လုပ်ပြီး, model က hallucinate မဖြစ်ဘဲ "I don't know" ပြန်ပြောအောင် guard condition ရေးပါ။ Task 4: အထက်ပါ ၃ ခုစလုံးကို check လုပ်တဲ့ simple test function 3 ခု (assertion) ရေးပါ.

Code နမူနာ

javascript
// Combined practice skeleton

const sampleChunks = [
  { id: 1, text: "Office hours are 9am to 5pm, Monday to Friday." },
  { id: 2, text: "Contact email is support@example.com for general questions." },
  { id: 3, text: "Student login password: sw0rdFish123, do not share." },
];

function filterSecrets(chunks) {
  // TODO: password / phone number / student ID pattern ပါတဲ့ chunk တွေကို
  // regex နဲ့ detect လုပ်ပြီး ဖယ်ထုတ်ပါ (redact or drop)
  return chunks;
}

function answerWithCitation(query, retrievedChunks) {
  if (retrievedChunks.length === 0) {
    // TODO: hallucinate မဖြစ်ဘဲ ဒီနေရာမှာ ဘာလုပ်သင့်လဲ ရေးပါ
    return "I don't know based on the given documents.";
  }
  // TODO: retrievedChunks ထဲက text ကိုပဲသုံးပြီး
  // "...office hours are 9-5 [1]." လို citation ပါတဲ့ answer string ဆောက်ပါ
}

// Task 4: assertion tests
function runTests() {
  const filtered = filterSecrets(sampleChunks);
  console.assert(filtered.some((c) => c.id === 3) === false, "secret chunk should be filtered");

  const noAnswer = answerWithCitation("What is the CEO's salary?", []);
  console.assert(noAnswer.includes("don't know"), "should refuse when no context");

  const answer = answerWithCitation("What are office hours?", [sampleChunks[0]]);
  console.assert(answer.includes("[1]"), "answer should cite source");
}
You should see
runTests() ကို run လိုက်ရင် assertion သုံးခုစလုံး error မတက်ဘဲ pass ဖြစ်ရပါမယ် — secret chunk filter ဖြစ်, empty retrieval မှာ don't-know ပြန်, နဲ့ citation ပါတဲ့ answer ရမယ်။

၅ မိနစ် စမ်းကြည့်

ကိုယ်ပိုင် notes file တစ်ခုထဲမှာ secret line တစ်ကြောင်း တမင်ထည့်ပြီး, ၅ မိနစ်အတွင်း filterSecrets() regex ကို အဲ့ဒီ line ကို ဖမ်းမိအောင် ရေးကြည့်ပါ။

သတိလေးတစ်ချက်

Regex တစ်ခုတည်းနဲ့ secret ကို ၁၀၀% ဖမ်းလို့မရပါဘူး။ Production မှာ layered filtering (regex + keyword list + human review) သုံးမှ ပိုလုံခြုံပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Citation number ကို retrieved chunk ရဲ့ real id နဲ့ မတိုက်ဆိုင်ဘဲ 1,2,3 အစဉ်လိုက် ကိုယ်ပိုင်ရေးလိုက်တာ — source နဲ့ citation မကိုက်ညီတော့ဘူး
  • Empty retrieval ကို catch လုပ်ဖို့ မေ့ပြီး, chunk မတွေ့ရင်တောင် model ကို free-form ဖြေခိုင်းလိုက်တာ — hallucination ဖြစ်တတ်တယ်

အခု ကိုယ်တိုင် စမ်းကြည့်

ကိုယ်ပိုင် notes file တစ်ခုထဲမှာ secret line တစ်ကြောင်း တမင်ထည့်ပြီး, ၅ မိနစ်အတွင်း filterSecrets() regex ကို အဲ့ဒီ line ကို ဖမ်းမိအောင် ရေးကြည့်ပါ။

You'll know it worked when: runTests() ကို run လိုက်ရင် assertion သုံးခုစလုံး error မတက်ဘဲ pass ဖြစ်ရပါမယ် — secret chunk filter ဖြစ်, empty retrieval မှာ don't-know ပြန်, နဲ့ citation ပါတဲ့ answer ရမယ်။