Study notesWeek 7: Giving Models Knowledge: Context, Retrieval, Embeddings, Tools
Week 7 / AI and LLMs from zero

Giving Models Knowledge

Outcomes

What You Will Be Able To Do

Recap

Recap Of Week 6: Prompting

Why it matters

The Knowledge Problem

Map of the week

Four Ways To Add Knowledge

MethodBest when
Paste into the promptThe text is short
Retrieval (RAG)Large, changing documents
ToolsLive data or actions are needed
Fine-tuningYou need a style or skill, not facts
Method 1

The Context Window

Method 2

Embeddings Turn Meaning Into Numbers

Comparing vectors

Cosine Similarity

import math

def cosine(a, b):
    dot = sum(x * y for x, y in zip(a, b))
    na = math.sqrt(sum(x * x for x in a))
    nb = math.sqrt(sum(y * y for y in b))
    return dot / (na * nb)

print(cosine([1, 2, 3], [2, 4, 6]))  # 1.0
Finding neighbors

Vector Search

Method 3

RAG: The Pipeline

question -> embed -> top 3 chunks
   |
   v
prompt = rules + chunks + question
   |
   v
model -> answer with citations
Augment and generate

A Grounded Prompt

Answer using only the sources below.
Cite sources like [1]. If the answer is
not in the sources, reply: not found.

[1] Refunds are accepted within 30 days.
[2] Shipping takes 3 to 5 days.

Question: How long do I have to return an item?
Where RAG is won

Chunking Choices

Debug retrieval first

Why RAG Fails

Method 4

Tool Use: The Model Asks, You Run

user: What is 1843 * 27?
model: call calculator(expr='1843*27')
app:   result = 49761
model: 1843 times 27 is 49,761.
Decision guide

Choosing An Approach

SituationStart with
One small documentPut it in the prompt
Thousands of documentsRAG
Prices that change hourlyA tool call to an API
Consistent toneFine-tuning or a system prompt
Week 7 in five lines

Recap

Week 8

Next Week: Agents And Workflows

Your turn

Questions And Exercise