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
// 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 ပါ
}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.