What is .load()?
.load() is the primary method on every LangChain document loader. It reads the entire source — a file, a URL, a database query result, an API response — into memory and returns a List[Document]. Each Document has a page_content string (the extracted text) and a metadata dict populated by the loader with source-specific fields: for file loaders that's typically {"source": "/path/to/file"}; for PDF loaders that's the page number; for web loaders that's the URL.
The method is synchronous and blocking: it does not return until all content has been fetched and parsed. This is fine for small sources — single files, short web pages, or a handful of database rows — but can be slow and memory-intensive for large corpora. For processing hundreds of files or multi-gigabyte documents, use .lazy_load() to stream documents one at a time instead.
Each loader class (TextLoader, PyPDFLoader, WebBaseLoader, GitLoader, S3FileLoader, and dozens of others in langchain_community) implements .load() with source-specific parsing logic but exposes the same Document list interface, so the rest of your pipeline — splitters, embeddings, vector stores — doesn't need to know which loader was used. The async counterpart is .aload(), which wraps the same parsing logic in an async function so it can be awaited inside async frameworks without blocking the event loop.
Use Cases
- • Load all documents
- • File processing
- • URL scraping
- • Document indexing
- • Preprocessing
- • Initial import
Key Features
- ✓ Load all at once
- ✓ Document objects
- ✓ Metadata included
- ✓ Blocking operation
- ✓ Simple API
- ✓ Returns list
When NOT to Use
For very large sources—use lazy_load().
Notes
Each loader adds its own metadata fields
TextLoader adds {"source": "path"}. PyPDFLoader adds {"source": "path", "page": 0}. WebBaseLoader adds {"source": "url", "title": "...", "description": "..."}. These metadata fields flow through splitters and into vector store metadata, so downstream filter queries depend on knowing what the loader actually provides.
.aload() is the async variant — not always implemented natively
Some loaders implement aload() as a true async coroutine using httpx or aiofiles. Others just run self.load() in a thread via asyncio.to_thread. The API is the same — await loader.aload() — but the performance characteristics differ. Check the loader's source if you need true non-blocking I/O.
For large sources, .load() loads everything into memory at once
A directory with 10,000 Markdown files loaded with .load() creates 10,000 Document objects in memory simultaneously. Use .lazy_load() to process them one at a time or in batches, especially before embedding — embedding APIs have rate limits, and buffering everything first wastes memory.
loader.load_and_split() combines loading and chunking in one call
If you need to split immediately after loading, loader.load_and_split(text_splitter) avoids creating the intermediate list. It is a convenience wrapper and carries the same memory caveat as .load() for large sources.
Method Signature
documents = loader.load()
Return Value
Type:
List[Document]
Description:
All loaded documents
Example Output:
[Document(...), Document(...), ...]
Code Examples
Load a text file
from langchain_community.document_loaders import TextLoader
loader = TextLoader('file.txt')
docs = loader.load()
print(f'Loaded {len(docs)} documents')
Load a PDF — one Document per page
from langchain_community.document_loaders import PyPDFLoader
loader = PyPDFLoader('report.pdf')
pages = loader.load() # One Document per page
for page in pages:
print(page.metadata["page"], page.page_content[:80])
Load a web page with metadata
from langchain_community.document_loaders import WebBaseLoader
loader = WebBaseLoader(['https://docs.python.org/3/'])
docs = loader.load()
print(docs[0].metadata) # {"source": "https://...", "title": "..."}
Common Mistakes
❌ Load huge files with .load()
✅ Use lazy_load() or streaming for large files
Related LangChain References
Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with .load() and the wider framework.
.load() FAQ
What does .load() do in LangChain?
Load all documents from source. .load() is the primary method on every LangChain document loader. It reads the entire source — a file, a URL, a database query result, an API response — into memory and returns a List[Document]. Each Document has a page_content string (the extracted text) and a metadata dict populated by the loader with source-specific fields: for file loaders that's typically {"source": "/path/to/file"}; for PDF loaders that's the page number; for web loaders that's the URL. The method is s…
Which LangChain classes support .load()?
.load() is available on Document loaders. Pin your installed LangChain version and verify the method exists in that release before deploying.
When should I use .load()?
Use .load() when your LangChain chains, agents, or pipelines need the behavior described in this guide.
What does .load() return?
.load() returns a List[Document]. All loaded documents
Does .load() have an async equivalent?
Yes — use aload() for async contexts such as FastAPI handlers or asyncio-based pipelines. It is the non-blocking counterpart to .load().
Where can I explore more LangChain API reference pages?
Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.