ワンクリックで
langchain-document-loaders
Guide to using document loader integrations in LangChain for PDFs, web pages, text files, and APIs
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Guide to using document loader integrations in LangChain for PDFs, web pages, text files, and APIs
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Using the Deep Agents CLI - terminal interface, persistent memory with AGENTS.md, project conventions, skills directories, and CLI commands.
Understanding Deep Agents framework - what they are, how to create them with createDeepAgent, and the agent harness architecture with built-in middleware for planning, filesystems, and subagents.
Creating and using custom skills with progressive disclosure, SKILL.md format, and the Agent Skills protocol in Deep Agents.
Using the Deep Agents CLI - terminal interface, persistent memory with AGENTS.md, project conventions, skills directories, and CLI commands.
Using FilesystemMiddleware with virtual filesystems, backends (State, Store, Filesystem, Composite), and context management for Deep Agents.
Using FilesystemMiddleware with virtual filesystems, backends (State, Store, Filesystem, Composite), and context management for Deep Agents.
| name | langchain-document-loaders |
| description | Guide to using document loader integrations in LangChain for PDFs, web pages, text files, and APIs |
| language | js |
Document loaders extract data from various sources and formats into LangChain's standardized Document format. They're essential for building RAG systems, as they convert raw data into processable text chunks with metadata.
pageContent (text) and metadata (source info, page numbers, etc.)| Loader Type | Best For | Package | Key Features |
|---|---|---|---|
| PDFLoader | PDF files | @langchain/community | Extracts text and page numbers |
| CheerioWebBaseLoader | Web pages (static) | @langchain/community | HTML parsing with Cheerio |
| PlaywrightWebBaseLoader | Web pages (dynamic) | @langchain/community | JavaScript-rendered content |
| TextLoader | Plain text files | langchain/document_loaders/fs/text | Simple text files |
| JSONLoader | JSON files/APIs | langchain/document_loaders/fs/json | Extract specific JSON fields |
| CSVLoader | CSV files | @langchain/community | Tabular data |
| DirectoryLoader | Multiple files | langchain/document_loaders/fs/directory | Bulk loading from directories |
| GithubRepoLoader | GitHub repos | @langchain/community | Clone and load repo files |
| NotionLoader | Notion pages | @langchain/community | Notion workspace data |
Choose PDFLoader if:
Choose CheerioWebBaseLoader if:
Choose PlaywrightWebBaseLoader if:
Choose TextLoader if:
import { PDFLoader } from "@langchain/community/document_loaders/fs/pdf";
// Load PDF file
const loader = new PDFLoader("path/to/document.pdf");
const docs = await loader.load();
console.log(`Loaded ${docs.length} pages`);
docs.forEach((doc, i) => {
console.log(`Page ${i + 1}:`, doc.metadata);
console.log(doc.pageContent.substring(0, 100));
});
// Each page is a separate document
// metadata includes: source, pdf.totalPages, loc.pageNumber
import { CheerioWebBaseLoader } from "@langchain/community/document_loaders/web/cheerio";
// Load single URL
const loader = new CheerioWebBaseLoader(
"https://docs.langchain.com"
);
const docs = await loader.load();
console.log(docs[0].pageContent);
console.log(docs[0].metadata); // { source: url, ... }
// With custom selector
const loaderWithSelector = new CheerioWebBaseLoader(
"https://news.ycombinator.com",
{
selector: ".storylink", // Only extract specific elements
}
);
// Multiple URLs
const loaderMultiple = new CheerioWebBaseLoader([
"https://example.com/page1",
"https://example.com/page2",
]);
const allDocs = await loaderMultiple.load();
import { PlaywrightWebBaseLoader } from "@langchain/community/document_loaders/web/playwright";
// For JavaScript-rendered pages
const loader = new PlaywrightWebBaseLoader("https://spa-app.com", {
launchOptions: {
headless: true,
},
gotoOptions: {
waitUntil: "networkidle", // Wait for JS to finish
},
evaluateOptions: {
// Custom evaluation function
evaluate: (page) => page.evaluate(() => document.body.innerText),
},
});
const docs = await loader.load();
import { TextLoader } from "langchain/document_loaders/fs/text";
const loader = new TextLoader("path/to/file.txt");
const docs = await loader.load();
// Returns single document with entire file content
console.log(docs[0].pageContent);
console.log(docs[0].metadata.source); // File path
import { JSONLoader } from "langchain/document_loaders/fs/json";
// Load JSON with specific field extraction
const loader = new JSONLoader(
"path/to/data.json",
["/texts/*/content"] // JSONPointer to extract specific fields
);
const docs = await loader.load();
// Example JSON: { "texts": [{ "content": "...", "id": 1 }] }
// Each matching field becomes a document
import { CSVLoader } from "@langchain/community/document_loaders/fs/csv";
const loader = new CSVLoader("path/to/data.csv", {
column: "text", // Column to use as page_content
separator: ",",
});
const docs = await loader.load();
// Each row becomes a document
// Other columns stored in metadata
import { DirectoryLoader } from "langchain/document_loaders/fs/directory";
import { TextLoader } from "langchain/document_loaders/fs/text";
import { PDFLoader } from "@langchain/community/document_loaders/fs/pdf";
// Load all files from directory
const loader = new DirectoryLoader(
"path/to/documents",
{
".txt": (path) => new TextLoader(path),
".pdf": (path) => new PDFLoader(path),
}
);
const docs = await loader.load();
console.log(`Loaded ${docs.length} documents from directory`);
import { GithubRepoLoader } from "@langchain/community/document_loaders/web/github";
const loader = new GithubRepoLoader(
"https://github.com/langchain-ai/langchainjs",
{
branch: "main",
recursive: true,
ignorePaths: ["node_modules/**", "dist/**"],
maxConcurrency: 5,
}
);
const docs = await loader.load();
// Each file becomes a document
import { CheerioWebBaseLoader } from "@langchain/community/document_loaders/web/cheerio";
const loader = new CheerioWebBaseLoader("https://blog.com/post");
const docs = await loader.load();
// Add custom metadata
const enrichedDocs = docs.map(doc => ({
...doc,
metadata: {
...doc.metadata,
loadedAt: new Date().toISOString(),
category: "blog",
},
}));
import { PDFLoader } from "@langchain/community/document_loaders/fs/pdf";
const loader = new PDFLoader("large-file.pdf");
// Use lazy() for large files - streams documents
for await (const doc of loader.lazy()) {
console.log("Processing page:", doc.metadata.loc.pageNumber);
// Process one page at a time without loading all into memory
}
✅ Load from various sources
✅ Extract with metadata
✅ Process efficiently
✅ Customize extraction
❌ Extract from encrypted/protected files
❌ Process binary data directly
❌ Handle all PDF types
❌ Bypass rate limits
// ❌ Will fail if pdf-parse not installed
import { PDFLoader } from "@langchain/community/document_loaders/fs/pdf";
const loader = new PDFLoader("file.pdf");
// ✅ Install dependencies first
// npm install pdf-parse
const loader = new PDFLoader("file.pdf");
const docs = await loader.load(); // Works!
Fix: Install required peer dependencies: npm install pdf-parse
// ❌ May fail due to CORS or blocking
const loader = new CheerioWebBaseLoader("https://protected-site.com");
await loader.load(); // Error!
// ✅ Check robots.txt and use appropriate loader
// For client-side blocking, run in Node.js (server-side)
// For dynamic content, use Playwright
const loader = new PlaywrightWebBaseLoader("https://protected-site.com");
Fix: Use PlaywrightWebBaseLoader for blocked sites or check robots.txt.
// ❌ Loading huge PDF into memory
const loader = new PDFLoader("huge-book.pdf");
const docs = await loader.load(); // May crash!
// ✅ Use lazy loading
for await (const doc of loader.lazy()) {
processDocument(doc);
// Only one page in memory at a time
}
Fix: Use lazy() method for large files.
// ❌ Relative paths may not work as expected
const loader = new TextLoader("./data/file.txt");
// ✅ Use absolute paths or path module
import path from "path";
const filePath = path.join(process.cwd(), "data", "file.txt");
const loader = new TextLoader(filePath);
Fix: Use absolute paths or path module for reliability.
// ❌ Using Cheerio for dynamic content
const loader = new CheerioWebBaseLoader("https://react-app.com");
const docs = await loader.load();
// Content is empty or incomplete!
// ✅ Use Playwright for JavaScript-rendered pages
const loader = new PlaywrightWebBaseLoader("https://react-app.com", {
gotoOptions: { waitUntil: "networkidle" }
});
Fix: Use Playwright for SPAs and dynamic content.
// ❌ Wrong JSON pointer format
const loader = new JSONLoader("data.json", ["texts.content"]);
// ✅ Correct JSON pointer format (starts with /)
const loader = new JSONLoader("data.json", ["/texts/0/content"]);
Fix: JSON pointers must start with / and use / as separator.
// ❌ Extensions don't match
const loader = new DirectoryLoader("docs", {
"txt": (path) => new TextLoader(path), // Wrong!
});
// ✅ Include the dot
const loader = new DirectoryLoader("docs", {
".txt": (path) => new TextLoader(path),
".pdf": (path) => new PDFLoader(path),
});
Fix: File extensions must include the dot (.txt, .pdf).
# Community loaders
npm install @langchain/community
# PDF support
npm install pdf-parse
# Playwright for dynamic web pages
npm install playwright
npx playwright install