Skip to main content

TextLoader integration

还没翻译译自英文(docs.langchain.com)本页 16 段都还没译

Tip

Compatibility: Only available on Node.js.

This notebook provides a quick overview for getting started with TextLoader document loaders. For detailed documentation of all TextLoader features and configurations head to the API reference.

Overview

Integration details

ClassPackageCompatibilityLocalPY support
TextLoaderlangchainNode-only✅❌

Setup

To access TextLoader document loader you'll need to install the langchain package.

Installation

The LangChain TextLoader integration lives in the langchain package:

npm install langchain
yarn add langchain
pnpm add langchain

Instantiation

Now we can instantiate our model object and load documents:

import { TextLoader } from "@langchain/classic/document_loaders/fs/text"

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

Load

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 reference

For detailed documentation of all TextLoader features and configurations head to the API reference.