Thuta Learning
ExercisesAIbeginner

Warm-Up Practice — RAG Fundamentals Drills

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

What you'll walk away with

  • Practice the RAG fundamentals 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 lesson isn't new material — it's a chance to drill the chunking, embeddings, and search-then-read fundamentals you learned in earlier lessons. Each task is small, but it's designed to put you in direct contact with the core skills of a RAG pipeline. Splitting a document into pieces, turning it into vectors, and searching before reading — these four things are RAG's foundation. Get real hands-on practice with all of them and the advanced lessons ahead will click a lot faster.

Practice Exercises

Task 1: Work out how to split a .txt file containing 5 paragraphs into 200-character chunks (with a 20-character overlap). Task 2: Imagine 5 chunks as embedding vectors, and manually pick out the 2 closest chunks to a given query by cosine similarity. Task 3: Following the search-then-read pattern, fill in the code skeleton for how chunks returned from the retrieve() function should be added into the prompt as context. Task 4 (optional): Try chunk sizes of 100 vs 400 characters and observe how retrieval quality changes.

Code Example

javascript
// Task skeleton — ဖြည့်ရမယ့်နေရာတွေကို TODO နဲ့ မှတ်ထားပါတယ်

function chunkText(text, size = 200, overlap = 20) {
  const chunks = [];
  // TODO: text ကို size အလိုက်ဖြတ်ပြီး overlap ထည့်ပါ
  return chunks;
}

function cosineSimilarity(vecA, vecB) {
  // TODO: dot product / (magnitudeA * magnitudeB)
}

function retrieve(query, chunks, embeddings, topK = 2) {
  const queryVec = embed(query); // embed() က already implement လုပ်ပြီးသား ဟု assume
  const scored = chunks.map((chunk, i) => ({
    chunk,
    score: cosineSimilarity(queryVec, embeddings[i]),
  }));
  // TODO: score အလိုက် sort ပြီး topK ကို return ပါ
}

function buildPrompt(query, retrievedChunks) {
  // TODO: retrievedChunks တွေကို context block အဖြစ် join ပြီး
  // query နဲ့ တွဲထည့်တဲ့ prompt string တစ်ခု return ပါ
}
You should see
Once you correctly fill in all four of chunkText, cosineSimilarity, retrieve, and buildPrompt, you'll get back a grounded prompt string containing the 2 closest chunks for a sample query.

5-minute try-it

Open Notepad and write a text with 5 paragraphs. In 5 minutes, try finishing the chunkText() function the paper-code way (writing it out by hand) — no computer needed.

One quick warning

These exercises are about understanding the pipeline's mechanics. In production, you'd use a real embedding model (OpenAI, Cohere, etc.), so it won't match hand-computed vectors exactly.

Easy traps

  • Chopping chunks at fixed intervals with no overlap at all — a single sentence can end up split across two chunks
  • Mistaking chunk length for the score instead of cosine similarity — the longest chunks end up dominating the top results

Now try it yourself

Open Notepad and write a text with 5 paragraphs. In 5 minutes, try finishing the chunkText() function the paper-code way (writing it out by hand) — no computer needed.

You'll know it worked when: Once you correctly fill in all four of chunkText, cosineSimilarity, retrieve, and buildPrompt, you'll get back a grounded prompt string containing the 2 closest chunks for a sample query.