Advanced · 03

RAG & AI agents

Giving models fresh knowledge with retrieval, and the ability to act with tools.

7 min read · Tap underlined words for a definition

An 's knowledge is frozen at training time, and it can't see your company's private documents. Two big ideas fix this: retrieval-augmented generation (look things up first) and agents (use tools in a loop).

your docs, chunked &embedded in advance 📚❓ Questionfrom the user🔢 Embedturn into a vector🗄️ Searchvector database💬 Answerwith citations🤖 LLMwrites the reply📝 Promptquestion + top chunkstop-k chunks
RAG: embed the question, find the most similar document chunks, paste them into the prompt, then generate a grounded answer.
Ask a shop assistant bot a question with and without retrieval.

How RAG works

Index: split documents into chunks, embed each chunk, store the vectors in a vector database.

Retrieve: embed the user's question and fetch the top-k most similar chunks.

Generate: put those chunks in the and ask the model to answer using them, ideally with citations.

Making RAG good

Chunk size matters: too big and you dilute relevance, too small and you lose context.

Hybrid search (keywords + ) and a re-ranker often beat embeddings alone.

Evaluate retrieval separately from generation: if the right chunk never arrives, the model can't use it.

Quick check

What's the main benefit of RAG over fine-tuning for new facts?

Agents: models that act

An is an LLM in a loop: think → choose a tool → observe the result → think again, until the task is done.

Tools can be web search, a calculator, a code interpreter, an API, or a browser. The ReAct paper popularised this reason-and-act pattern.

Tool calling & protocols

Modern APIs let you describe tools with a JSON schema; the model replies with a structured call, your code runs it, and you feed back the result.

Open standards like the Model Context Protocol (MCP) let any tool or data source plug into any compatible AI app.

Quick check

What is the core loop of an AI agent?

Before you drift off

  • RAG = retrieve relevant chunks, then generate grounded answers.
  • Chunking, hybrid search and re-ranking make or break RAG.
  • Agents = LLMs that reason and use tools in a loop.
  • MCP standardises how tools plug into AI apps.

Terms in this lesson

Go deeper, free and open

That's the lesson

RAG & AI agents · 7 min

Each lesson you finish lights a star.

Finish & continue · Up nextFine-tuning on a budget: LoRA & quantisationAdvanced · 6 min

Spotted a mistake? Suggest an edit

Previous: How LLMs are trained