| π View Lecture Slides | Full-screen presentation with navigation |
Session 4: Context Engineering
| Session Duration: 2 Hours | Block: 1 β Foundations & The Exocortex |
Learning Objectives
By the end of this session, students will be able to:
- Explain the concept of context engineering and how it differs from prompt engineering
- Design reusable templates for structuring knowledge before AI ingestion
- Apply formatting techniques to transform raw web content into AI-ready Markdown
- Identify context design choices that reduce hallucination and improve relevance
Hour 1: Designing What the AI Sees (Instructor-Led β 60 minutes)
1.1 Prompt Engineering vs. Context Engineering
Prompt engineering focuses on how you instruct the model β the words you use to direct its behaviour.
Context engineering focuses on the information you provide alongside those instructions β what you feed the model to inform its response.
Both matter. But context engineering has a more direct impact on whether an AI application produces factually grounded, reliable outputs.
The fundamental principle: Garbage in, garbage out β at scale.
If your knowledge base contains poorly structured, redundant, or contradictory information, your AI application will reflect that. If your context is clean, well-structured, and relevant, the AI has the best possible chance of producing accurate, useful responses.
1.2 The Context Window as a Constraint
Every AI model has a context window β the maximum amount of text it can process in a single call. Current models range from 4,000 tokens (older models) to over 1,000,000 tokens (Gemini 1.5 Pro).
One token β 0.75 words in English.
| Tokens | Approx. Word Count | Practical Equivalent |
|---|---|---|
| 4,000 | ~3,000 words | A short essay |
| 32,000 | ~24,000 words | A short report |
| 128,000 | ~96,000 words | A small book |
| 1,000,000 | ~750,000 words | A large textbook |
For RAG systems, this means you cannot simply dump your entire knowledge base into every prompt. You must:
- Retrieve only the relevant sections
- Format those sections efficiently
- Fit them alongside the userβs query and system instructions
This is why context engineering matters before RAG is even built.
1.3 Principles of Well-Engineered Context
Principle 1: Remove Redundancy Duplicate information wastes context tokens and can confuse the model. If the same fact appears in three notes, consolidate it.
Principle 2: Be Explicit About Structure AI models perform better when sections are clearly labelled. Use headings, bullet points, and explicit labels.
# BAD (implicit structure)
The product costs Β£12. It comes in red and blue. Delivery is 5 days.
# GOOD (explicit structure)
## Product Details
- Price: Β£12
- Colours: red, blue
- Delivery: 5 business days
Principle 3: Include Metadata Date, source, and relevance signals help the model weight information correctly.
## [Source: Official API Documentation | Updated: 2024-06]
Principle 4: Chunk Logically Break documents into semantically coherent sections. A chunk should answer a specific type of question. Avoid arbitrary character-length splits.
1.4 The Context Template Pattern
A context template is a reusable Markdown structure that ensures all notes in your knowledge base follow the same format. For a course knowledge assistant:
---
topic: [Topic Name]
type: [concept | procedure | example | definition]
related: [[related-note-1]], [[related-note-2]]
---
## Core Idea
[One-sentence summary of the main point]
## Explanation
[2β4 paragraphs of clear explanation]
## Key Terms
- **Term 1:** Definition
- **Term 2:** Definition
## Examples
[Concrete example or case study]
## Common Mistakes
[What people typically misunderstand]
Every note written in this format contributes high-quality, retrievable context to your AI system.
Hour 2: Practical β Format Web Data for AI Ingestion (60 minutes)
Lab 4.1 β Clean a Raw Web Page
Find a Wikipedia article or documentation page relevant to your project. Paste the raw content into a text editor.
Tasks:
- Remove all navigation text, footer content, and metadata that adds no information value
- Structure the content using clear Markdown headings
- Convert any tables to Markdown table format
- Add a frontmatter block with
topic,type, andsourcefields - Ensure each section answers exactly one question
Save the result as a note in your 04-References/ vault folder.
Lab 4.2 β Apply the Context Template
Using the template from section 1.4, create three structured notes for your project domain. These should cover:
- A core concept your project depends on
- A procedure your project will perform
- An example of the problem your project solves
Lab 4.3 β Test Context Quality
Open AI Studio. Paste one of your structured notes as context. Ask a question that should be answerable from that context.
Now compare:
- Ask the same question without providing context (pure model knowledge)
- Ask the same question with your structured note as context
Document the differences in your prompts.md file. Which approach gives a more precise, grounded answer? Does the model cite specific details from your note?
Key Takeaways
- Context engineering designs the information fed to the AI, not just the instructions
- Context window limits require deliberate selection of relevant content
- Well-structured Markdown with explicit headings, metadata, and logical chunks improves AI output quality
- Context templates ensure consistent, high-quality knowledge base entries
- Testing context quality before building the retrieval pipeline prevents compounded errors later
Further Reading
- βHow to Think About Context Windowsβ β Anthropic documentation
- LangChain text splitter documentation (for RAG chunking strategies)
- Obsidian Templater plugin documentation


