RAG · Lesson 14 of 120
Loading Files
Markdown and text.
Our help centre pages are markdown files. Loading them is easy. We read each file, and make a document with its text and some metadata.

- Markdown files
- Read each one
- Make documents
Loading the help centre
We use LangChain's Document class, which holds page content and metadata. For each markdown file, the source is the file name, and the title is the first line, without the hash sign. Run it. Fourteen documents, each with a source and a title.
load_files.pypython
from pathlib import Path
from langchain_core.documents import Document
docs = []
for path in sorted(Path("data/rag/northwind").glob("*.md")):
text = path.read_text()
title = text.splitlines()[0].lstrip("# ")
docs.append(Document(page_content=text, metadata={"source": path.name, "title": title}))
print(len(docs), "documents")
for d in docs[:4]:
print(d.metadata)Output
14 documents
{'source': 'ebike_battery.md', 'title': 'E-bike battery guide'}
{'source': 'ebike_errors.md', 'title': 'E-bike display error codes'}
{'source': 'finance.md', 'title': 'Paying monthly'}
{'source': 'membership.md', 'title': 'Northwind Riders club'}Other sources
Real knowledge bases come from many places. Web pages, wikis, PDFs, spreadsheets, and databases. Each needs its own loader, but they all end the same way, as documents with text and metadata.
| key | value |
|---|---|
| Web pages | strip the HTML |
| PDFs | page by page |
| Spreadsheets | rows as text |
| All end as | Documents |
Summary
Loading means reading each file into a document, with its source and title as metadata. Next, loading PDFs.
Key takeaways- Document class
- page_content
- metadata
Next up: Loading PDFs — page by page