AI Hints
Home›RAG Tutorial›Loading Documents
RAG · Lesson 13 of 120

Documents and Metadata

Text plus labels.

⏱ 2 min read▶ Video at 12:36🎓 Free
Watch this lesson in the RAG courseWatch on YouTube ↗Full RAG course

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.

Documents and Metadata
From the video: Documents and Metadata
  • 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.

keyvalue
Citeshow the source
Filteronly search some docs
Freshnessknow what to update
Store itfrom 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