Introducing Documents and Context for RAG
Introduction: The Power of Context in Email Assistants
Welcome to the first lesson of the course, "Document Context and Retrieval-Augmented Generation." In this lesson, you will learn how external documents and context can make an email assistant much smarter and more helpful.
Imagine you are using an email assistant at work. If the assistant only knows what is in your current email, it can answer simple questions. But what if you want to know about your company’s meeting policy, your coworker’s availability, or how to handle urgent requests? For the assistant to answer these questions, it needs access to more information — such as company policies, calendars, and FAQs. These are called context documents.
By the end of this lesson, you will know what a context document is, why it matters, and how to load one into your assistant using Mastra. This is the first step in making your assistant truly useful.
Quick Recall: What is RAG?
Before we dive in, let's quickly remind ourselves about Retrieval-Augmented Generation, or RAG. If this is your first time hearing about it, don't worry — here's a simple explanation.
RAG is a method that combines two things:
- Retrieval: Finding useful information from external documents by searching through them based on the user's question or request.
- Generation: Using that retrieved information, along with the user's question, to create a helpful and accurate response through a language model.
For example, if your assistant is asked, "When is Emily available for a meeting?" it can look up Emily's calendar (retrieval), find the relevant availability information, and then use a language model to write a clear, natural-sounding answer (generation) like "Emily is available on weekdays from 10am to 4pm."
The key advantage of RAG is that it allows the assistant to provide accurate, up-to-date information from your documents, rather than relying only on what the language model learned during training.
In this lesson, we will focus on the first part: how to give your assistant access to the right documents so it can retrieve useful information.
Understanding Context Documents
A context document is any piece of information that helps your assistant answer questions better. Here are some examples:
| Document Type | Example Content |
|---|---|
| Company Policy | "All meetings must be scheduled 24 hours in advance." |
| Calendar | "Emily is available on weekdays from 10am to 4pm." |
| FAQ | "For urgent requests, mark your email as 'High Priority'." |
These documents are important because they give your assistant the background knowledge it needs. Without them, the assistant can only guess or give generic answers.
For a smart email assistant, context documents might include:
- Company rules and policies
- Employee calendars
- Frequently asked questions (FAQs)
- Contact lists
By loading these documents, you make your assistant much more capable.
