兼容性:仅在 Node.js 上可用。
本笔记本提供了 TextLoader 文档加载器 的快速入门概述。有关所有 TextLoader 功能和配置的详细文档,请参阅 API 参考

概述

集成详情

ClassPackageCompatibilityLocalPY support
TextLoaderlangchainNode-only

设置

要访问 TextLoader 文档加载器,您需要安装 langchain 包。

安装

LangChain TextLoader 集成位于 langchain 包中:
npm install langchain

实例化

现在我们可以实例化模型对象并加载文档:
import { TextLoader } from "@langchain/classic/document_loaders/fs/text"

const loader = new TextLoader("../../../../../../examples/src/document_loaders/example_data/example.txt")

加载

const docs = await loader.load()
docs[0]
Document {
  pageContent: 'Foo\nBar\nBaz\n\n',
  metadata: {
    source: '../../../../../../examples/src/document_loaders/example_data/example.txt'
  },
  id: undefined
}
console.log(docs[0].metadata)
{
  source: '../../../../../../examples/src/document_loaders/example_data/example.txt'
}

API 参考

有关所有 TextLoader 功能和配置的详细文档,请参阅 API 参考
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.