Generative AI · Foundations & Applications  ·  Session 4 · Day 2 · TCE Madurai 1 / 1
next  ·  back  ·  F fullscreen  ·  O overview
S4/6 day_2 · generative_ai · foundations_&_applications

Giving AI
your knowledge

The model has read the internet — but not your notes, your syllabus, your company's documents. Today: search that understands meaning, then RAG — the architecture inside nearly every "chat with your docs" product ever shipped. By lunch you'll have built "chat with my notes."

Session 4 of 6Got your documents? You'll need them
01 good_morning — 90_second_recap_of_day_1

Did it survive the night?

True or false
0 / 0
02 live_demo · the_problem

Watch it not know — loudly

Ask about YOUR world
"What topics are in Unit 3 of the OS course at TCE Madurai this semester?"

It cannot know — your syllabus isn't in its training data. Watch what it does instead of admitting that: a plausible OS syllabus, invented on the spot. Some models even apologise first — then produce a typical syllabus anyway. The hedge is not knowledge. Session 2's disease, aimed directly at your college life — today we cure it.

03 the_obvious_fix, and_its_bill

"Just paste all my notes!" — let's price that

Drag: how much are you pasting per question?
2 pages400 pages
20 ≈ unit notes · 120 ≈ all five units · 380 ≈ the Galvin OS textbook
pricing: Gemini 3.5 Flash input @ $1.50 per 1M tokens · ₹95.5 per USD (July 2026)

Three taxes on pasting

1. The window — remember, everything must fit (Session 1). A textbook doesn't.

2. The meter — you pay per token, per question. Every "what's a deadlock?" re-sends all 400 pages.

3. The middle — even long-window models attend unevenly; whatever's buried mid-window is likeliest to be missed. More haystack, worse needle-finding.

04 the_insight

Don't send everything.
Send the right 3 paragraphs.

Nobody reads the whole book in an open-book exam — toppers walk in with sticky flags already on the right pages. That's a good index. We need a search engine that finds paragraphs by meaning, staples them to the question, and lets the model answer from them.

Retrieval → Augmentation → Generation. RAG. Let's build the R first.

05 live_demo · why_ctrl-f_isn't_enough

Keyword search misses meaning

Query: "marks required to clear the subject" · Notes say: "…minimum of 50% aggregate across internals and end-semester…"

Zero shared words — "marks/clear/subject" vs "50% aggregate/internals". Keyword search: nothing. But the meanings are neighbours… and you already know a machine that maps meaning to coordinates.

06 session_1's_map_grows_up

Embeddings, now for whole paragraphs

Same trick, bigger units

Session 1: words → coordinates (idli next to dosa). Today: entire chunks of text → coordinates. "Minimum 50% aggregate to pass" and "marks required to clear" land near each other in meaning-space — zero shared words needed.

Search = nearest neighbours

Embed all your chunks once (cheap). Embed the question. Find the chunks whose vectors sit closest — cosine similarity, one line of numpy. That's semantic search. That's the R in RAG.

# the entire search engine. no, really. scores = chunk_vectors @ question_vector # cosine similarity (normalized) top3 = [chunks[i] for i in scores.argsort()[-3:][::-1]]
07 live_demo · search_by_meaning

The search playground

6 chunks from an OS notes file, plotted in meaning-space — pick a query
08 the_unglamorous_decision_that_decides_everything

Chunking: how you cut the book

Same document, three knife settings — query: "marks needed to pass"

Too small → the retrieved fragment lacks context. Too big → the right sentence drowns, similarity dilutes. Paragraph-with-overlap is the boring default that wins. Chunking bugs cause more RAG failures than model choice does.

09 where_the_vectors_live

Vector databases, in plain words

What it is

A library shelved by meaning — hands back the k nearest vectors to any query, fast, even across millions.

Names you'll meet

FAISS (library), Chroma (dev-friendly), pgvector (Postgres extension), Pinecone/Weaviate (managed). Same idea, different packaging — like filter coffee from a tumbler, a flask, or a ₹300 café cup.

What YOU need today

A numpy array. Truly. Below ~100k chunks, one argsort is instant. Don't add a database until you have a database-sized problem.

today's lab ≈ 6 chunks your full notes ≈ 300 every TCE course ≈ 50k — still just numpy English Wikipedia ≈ 30M — NOW buy the database

Resume line, unlocked: "built semantic search over a vector store" — that sentence is the numpy array you'll write in the next 20 minutes.

10 assemble_the_machine · drive_it_yourself

RAG, end to end

One question's journey — press Step
Press Step to follow one real question through the pipeline.
11 the_A_in_RAG — the_prompt_that_changes_everything

The grounded prompt template

# memorize this shape — it powers most AI products Answer the question using ONLY the context below. Cite which chunk you used, like [1] or [2]. If the answer is not in the context, reply exactly: "I don't know based on the provided documents." CONTEXT: [1] {chunk_1} [2] {chunk_2} [3] {chunk_3} QUESTION: {question}

Three load-bearing lines

ONLY the context — blocks its internet-memories from overriding your documents.

Cite the chunk — users can verify; hallucinations become visible.

"I don't know" escape hatch — gives it a legal way out. Without one, it fills silence with fiction (you watched this at 9 a.m.).

A/B eval, live — ask "attendance policy?" (not in the context)
12 diagnose_before_you_click

Where RAG breaks in the wild

Right answer, wrong words

The user asks "attendance shortage rules" — notes say "condonation policy". Retrieval whiffs. Why?

Vocabulary gap even embeddings can miss. Fix: rephrase the query with the LLM first, retrieve more chunks (k=5), or index chunk summaries too.

Reveal ↓

The answer got cut in half

Rule starts in chunk 7, exception lives in chunk 8. Model sees only chunk 7. Result?

Confidently incomplete answer. Fix: overlapping chunks, or retrieve neighbours of every hit.

Reveal ↓

Stale index

Syllabus PDF updated Monday; embeddings made last month. What happens?

Confident answers from the OLD syllabus — with citations! RAG trusts its shelf. Fix: re-index on change; store doc dates; show them in answers.

Reveal ↓

Model ignores your context

Context says internal exam is 25 marks; the internet-average says 20. Model answers 20. Why?

Training memories leak past weak grounding. Fix: the ONLY line, lower temperature, and put context BEFORE the question. Test it — that's an eval (Session 2 never left).

Reveal ↓
13 choosing (full_framework_next_session)

RAG vs paste-it-all vs fine-tuning

ApproachWhen it winsWhen it loses
Paste into contextFew pages, one-off questions, quick scriptsBig corpora · repeated queries (you re-pay every time)
RAGLarge or changing knowledge · need citations · need freshnessTiny static docs (overkill) · answers needing whole-corpus reasoning
Fine-tuningStyle, format, domain behaviour at scaleTeaching facts — expensive, freezes instantly, no citations. Common ₹-crore mistake.

Interview one-liner: "Fine-tuning teaches behaviour; RAG provides knowledge." Full decision ladder after lunch.

14 look_around

You've been using RAG all along

Support chatbots

"Chat with our help docs." Retrieval over a manual + the grounded template.

NotebookLM-style tools

"Chat with your sources" — RAG with a polished UI.

AI search engines

Search results → context → cited answer. RAG at web scale.

Legal/medical assistants

Retrieval over case law / literature — citations are mandatory there.

"Chat with our wiki"

Every enterprise AI rollout starts here. Somewhere in Bengaluru, someone's entire salary is today's lab.

Yours, in 50 minutes

Chat with your own notes — same architecture, your data.

HT hot_take · argue_with_me

Your final-year project is
one grounded prompt away from being a startup.

Most funded "AI products" are exactly what you build today: retrieval plus a grounded prompt around someone else's model. That is not an insult to them — it is an invitation to you. The moat is the data and the evals, and you have Madurai data nobody in San Francisco has.

Disagree? Good. Bring it to the break — strongest counter-argument gets named on the closing slide.

15 what_you're_about_to_build

Lab architecture: two pipelines

Ingest once (per document) · query forever
Load
PDF/txt → text
Chunk
paragraphs + overlap
Embed
gemini-embedding-2
Store
numpy array
then, per question ↓
Embed question
same model
Top-k
cosine similarity
Augment
grounded template
Answer + cite
generate_content
↑ the highlighted stage is the only genuinely new idea today

~60 lines of Python total. Every stage is something you've already touched this weekend.

16 say_it_before_you_click

Six ideas you own now

Chunk embedding

···

Whole paragraphs → coordinates. Meaning-neighbours, zero shared words needed.

Reveal

Semantic search

···

Embed chunks once + question → cosine similarity → top-k. One numpy line.

Reveal

Chunking

···

Paragraph + overlap. Too small = no context; too big = diluted. Causes more failures than model choice.

Reveal

Augmentation

···

Staple top chunks into the grounded template: ONLY the context · cite · "I don't know" escape hatch.

Reveal

RAG vs fine-tune

···

Fine-tuning teaches behaviour; RAG provides knowledge. Facts → RAG.

Reveal

Fresh index

···

RAG trusts its shelf — stale embeddings give confident, cited, outdated answers. Re-index on change.

Reveal
17 50_minutes · the_weekend's_main_build

Lab 4: chat with YOUR notes

Ingest
Load your document → chunk → embed → store. Print chunk count. ✓ checkpoint 1
Search sanity check
3 test queries → do the top chunks LOOK right? Fix chunking if not. ✓ checkpoint 2
The full RAG loop
Grounded template + citations. Ask 5 real questions about your material.
Break it honestly
Ask something NOT in your docs — does it say "I don't know"? Ask a cut-in-half question. ✓ checkpoint 3: one honest failure + your fix

Stretch

Mini-eval: 5 questions with expected answers → score your RAG (harness from S2!) · k=1 vs k=3 vs k=5 · second document · show similarity scores in answers.

Capstone alert

This app is your capstone foundation. This afternoon adds tools (S5) and hardening + demo (S6). Build it on documents you actually care about.

18 break · session_5_after_lunch

Your AI now knows
what you know.

Next: it stops just answering and starts doing — calculators, search, your files. Tool use, agents, and the honest truth about both.

@intrepidkarthiKeep the RAG notebook open — S5 builds on it