RAG · Lesson 13 of 120
Documents and Metadata
Text plus labels.
Every RAG system starts with documents. A document is more than its text. It also carries labels, called metadata, like which file it came from, its title, or when it was last updated.

- Text
- Plus labels
- Called metadata
A document with metadata
We store a document as a dictionary. The text holds the words. The metadata holds the source file, a title, and the year it was written. Run it. Both parts print, and we can use either one later.
document.pypython
doc = {
"text": "Standard delivery in the UK takes 3 to 5 working days and costs £4.99.",
"metadata": {"source": "shipping.md", "title": "Shipping and delivery", "year": 2026},
}
print("Text:", doc["text"])
print("From:", doc["metadata"]["source"], "|", doc["metadata"]["title"], "|", doc["metadata"]["year"])Output
Text: Standard delivery in the UK takes 3 to 5 working days and costs £4.99. From: shipping.md | Shipping and delivery | 2026
Why metadata matters
Metadata does three big jobs. It lets us cite the source of an answer. It lets us filter, for example searching only this year's price list. And it helps us keep the index fresh, by knowing which file each piece came from.
| key | value |
|---|---|
| Cite | show the source |
| Filter | only search some docs |
| Freshness | know what to update |
| Store it | from the start |
Summary
A document is text plus metadata. Keep the source, the title, and dates from the start. Next, loading files.
Key takeaways- Text
- Metadata
- Source, title, date
Next up: Loading Files — markdown and text