AI School Pakistan
← Applied AI Builder0 of 18 complete
LessonCourse overview

Module 4 · Grounded Knowledge Systems · 55 min

RAG, Embeddings, Chunking, and Retrieval in Plain English

Lesson 10 of 18

Is lesson ke baad tum

A useful chunk preserves a complete rule and its scope; retrieval must exclude unauthorized and inactive evidence before a model uses it.

In this lesson

Choose the evidence that can answer one fee question, then design a chunk that keeps the rule and exception together. The five short policy excerpts below are the entire fictional corpus. You need only a text editor for this preparation task; the following lesson builds a local answer gate.

Four Terms You Will Use

Retrieval-augmented generation (RAG) searches approved material and supplies it to a model before an answer. Retrieval supplies candidates, not proof. A keyword search can support RAG; embeddings are a useful option, not a requirement.

An embedding is a numerical representation used to compare patterns in content. Related meaning often has nearby representations. It is neither a fact store nor a confidence score. Keyword retrieval helps exact codes such as FORM-17B; hybrid retrieval combines keyword and semantic search.

A chunk is one retrievable unit. Keep a complete rule with its heading, scope, and exception. A short sentence without its exception can be dangerously incomplete; an entire handbook can bury the relevant rule. Generation turns the selected evidence into an answer, with citations and an option to abstain.

Worked Example

All excerpts are teaching fixtures, not AI School's actual fees or policies. Evaluate them on 2026-10-05 for a public learner.

IDScope and validityExact text
A3public, all campuses, fees v3, from 2026-01-01Admission fees must be paid in one payment, including the evening program.
T3public, all campuses, fees v3, from 2026-01-01Tuition may be paid in two installments. This rule does not cover the admission fee.
A2public, all campuses, fees v2, ended 2025-12-31Admission fees may be paid in two installments.
M1manager-only, all campuses, activeManagers review exceptional fee arrangements through the internal process.
F1public, all campuses, activeUse FORM-17B to request a change of program.

Question: “Can an evening applicant split the admission fee?” A3 answers it: one payment, including evening. T3 is related but explicitly excludes admission fees. A2 is expired. M1 is outside the learner's access and must be filtered before any model context, citation, or ordinary learner log.

Make A3 one complete chunk with source title Demo Fees, section Admission fee, version 3, audience public, campus all, effective date, and source ID. Keep both sentences of T3 together: separating its exception would change what a retrieved chunk appears to permit.

An appropriate answer is: “The demo policy requires the admission fee in one payment, including the evening program [A3].” It does not say tuition installments are banned or promise management will make an exception.

From This Table to a Search System

First filter by trusted user scope, authority, and effective dates. Search only eligible material, cap the candidate count, then inspect whether it supports the question. A similarity threshold must be chosen from labeled tests for your corpus; there is no universal score that proves an answer.

For managed retrieval, OpenAI vector stores can chunk, embed, and index uploaded files. Hosted storage, search, and model usage have their own access and cost requirements; none is needed here. File attributes/filters operate at the documented file level, so do not mix confidential and public sections in one uploaded file and assume a chunk label creates an access boundary. Separate scopes before indexing. Wait for ingestion to complete; provider deletion can be eventually consistent, so revoke application access immediately instead of assuming a delete request instantly removes every search hit.

Why a Similar Paragraph Can Give the Wrong Answer

Retrieval and answering solve different problems. Retrieval asks which passages are worth inspecting. Answering asks whether those passages establish the requested fact. In our fee corpus, both A3 and T3 discuss payments. T3 may look attractive for a query containing split because it mentions installments, yet its exception explicitly excludes admission fees. Better wording in the final prompt cannot recover an exception that was removed from the retrieved text.

An embedding turns text into a list of numbers called a vector. Think of it as a position used for comparison, not a compressed paragraph you can read back. One common comparison, cosine similarity, compares vector directions. To make the arithmetic visible, use invented two-dimensional vectors, not real model outputs: question Q=(1,0), passage X=(0.8,0.6), and passage Y=(0.6,0.8). Each has length 1 because, for example, 0.8² + 0.6² = 1. Their cosine scores against Q are 0.8 and 0.6. X ranks higher under this toy comparison, but neither number tells us whether X is current, permitted, or actually answers the question. Real embeddings have many more coordinates and must be evaluated on actual queries.

Return to the fee question and follow the intermediate states:

  1. The request supplies an evaluation date and a trusted public-reader scope.
  2. Eligibility removes A2 because it expired and M1 because it is private.
  3. Search compares the question with A3, T3 and F1.
  4. Evidence inspection identifies A3 as decisive; T3 addresses a different fee.
  5. The answer uses A3's complete rule and names A3 as its citation.

Eligibility removes material the answer must not use. Search removes less relevant candidates to reduce reading work. Evidence inspection removes unsupported interpretations. Combining them into one vague instruction to “find the best answer” makes failures harder to diagnose.

A Chunk Repair You Can Inspect

Suppose an importer creates chunk T3a containing only Tuition may be paid in two installments. and T3b containing only This rule does not cover the admission fee. T3b lacks the subject of “this rule.” If search returns T3a alone, a model may extend installments to every fee. Repair the boundary by retaining the heading, both sentences and their shared source metadata. Adding unrelated pages would make the packet longer without repairing this missing relationship.

Try a second scenario: Can I split tuition and admission together into two installments? Predict the evidence packet before reading the answer. One source is insufficient: retain T3 for tuition and A3 for admission. The worked answer distinguishes the charges: tuition may use two installments under T3, while admission requires one payment under A3. It cannot calculate a combined schedule because the corpus supplies neither amounts nor such a schedule.

To diagnose a wrong result, save three observations: which eligible IDs were searched, which IDs were retrieved, and which claims the answer made. If A3 never reached the model, investigate retrieval. If A3 arrived intact but the answer contradicted it, investigate generation or validation. If A3 was excluded by a wrong date, repair eligibility first. This trace tells you where the next experiment belongs.

Failure Cases to Diagnose

  • Scrambled OCR

    inspect the extracted text against the page and reject unusable extraction before indexing.

  • Old and new versions collide

    filter to the approved active version before generation.

  • Exact code missed

    add keyword or hybrid search and test FORM-17B explicitly.

  • Exception lost

    join the rule and exception or use a meaningful overlapping chunk.

  • Unauthorized source ranks highly

    exclude it before retrieval; a high score cannot grant access.

  • No source answers the question

    abstain even when a topically related paragraph exists.

Hands-On Exercise

Create three public chunks from A3, T3, and F1. Include the metadata described above and record why A2/M1 are excluded. Then select evidence for these queries without writing an answer first:

  1. “Tuition do hisson mein de sakte hain?”
  2. “Which form requests a program change?”
  3. “Is there a hardship scholarship?”

Expected selections: T3 for the Roman Urdu tuition question; F1 for the program-change request; no supporting source for scholarship eligibility. A3 must not be used to deny tuition installments. F1 says which form to use, not where an office is located, so do not invent an address.

Change the evaluation date to 2025-12-15. A3/T3 are not yet active and A2 covers admission installments; the same question now needs a different source. Record the version/date with the answer. This manual selection exercises evidence design; it is not a measured embedding search.

Completion Rubric

  • Rule and exception remain in the same T3 chunk, with source/version/scope metadata.
  • Each query has the expected source or an explicit unsupported result.
  • Date and audience exclusions happen before answer generation.
  • Your notes distinguish manual evidence selection from tested search quality.

Sources

Practice quiz

Check yourself

4 questions · practise what you just learned

0/4
  1. 1 / 4 · diagnose

    A scanned notice produces scrambled extracted text that ranks for a fee query. What should happen before indexing it?

Apna kaam check karo.

Practice complete ki? Result ko example aur lesson ke checks se compare karo.

This is your own completion record, not a graded assessment.

Kuch samajh nahi aaya? Ask a question →