Skip to content

Document and loaders

A LangChain Document holds page_content, a metadata dictionary, and an optional ID. A loader converts a file or external source into these objects.

from langchain_core.documents import Document
document = Document(
page_content="Refunds are available for 30 days after delivery.",
metadata={
"source": "returns-policy.pdf",
"page": 4,
"tenant_id": "shop-17",
"version": "2026-08-01",
},
)
  1. Load bytes from the authorized source.
  2. Preserve headings, tables, page numbers, and document IDs where possible.
  3. Attach version, tenant, permission, and provenance metadata.
  4. Inspect extracted text before chunking.

Retrieval cannot recover text a loader lost. PDFs can scramble columns, omit scanned pages, or flatten tables. Test representative files, record parse failures, and never trust a source filename as an authorization boundary.

Text splitters · Embeddings and vector stores · Retrievers