Thuta Learning
ExercisesAIbeginner

Level-Up Practice — RAG Combined Drills

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Practice the RAG combined drills hands-on
  • Reinforce the skills you've already learned through practice
  • Get comfortable finding bugs, fixing them, and checking your own work

Let's think about this for a second

This round steps up a level from round one. Instead of drilling one skill at a time, you'll handle scenarios that come up together in a real RAG app. Writing a grounded answer, citing the source, checking that a secret in a document doesn't leak, and honestly replying "I don't know" when a document isn't found — these are all core skills a production RAG app needs to be trustworthy. In this lesson, you'll write your own test cases and check your own logic.

Practice Exercises

Task 1: Look at a sample context containing 3 retrieved chunks, and write a grounded answer paragraph with citation numbers [1][2], using only vocabulary from those chunks. Task 2: In a sample document, identify a paragraph containing a phone number, a password, and a student ID, and pick out which sentences shouldn't be ingested and need to be filtered out. Task 3: Simulate retrieve() returning an empty result (no chunks found), and write a guard condition so the model replies "I don't know" instead of hallucinating. Task 4: Write 3 simple test functions (assertions) that check all three of the above.

Code Example

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
Running runTests() should pass all three assertions with no errors — the secret chunk gets filtered, an empty retrieval returns a don't-know response, and the answer comes back with a citation.

5-minute try-it

Deliberately add a secret line into one of your own notes files, and in 5 minutes, write a filterSecrets() regex that catches that line.

One quick warning

A single regex can't catch secrets 100% of the time. In production, layered filtering (regex + keyword list + human review) is much safer.

Easy traps

  • Numbering citations 1, 2, 3 in order instead of matching them to the retrieved chunk's real id — the citation ends up not matching the actual source
  • Forgetting to catch an empty retrieval and letting the model answer freely even when no chunk was found — this leads to hallucination

Now try it yourself

Deliberately add a secret line into one of your own notes files, and in 5 minutes, write a filterSecrets() regex that catches that line.

You'll know it worked when: Running runTests() should pass all three assertions with no errors — the secret chunk gets filtered, an empty retrieval returns a don't-know response, and the answer comes back with a citation.

Level-Up Practice — RAG Combined Drills | Thuta Learning