Skip to main content

文档加载器 Document loaders

info

请前往Integrations查看内置文档加载器与第三方工具的文档。

使用文档加载器从源加载数据作为DocumentDocument是一段文本和相关元数据。例如,有用于加载简单的.txt文件的文档加载器,用于加载任何网页的文本内容,甚至用于加载YouTube视频的转录。

文档加载器提供了一个"load"方法,用于从配置的源加载数据作为文档。它们还可以选择实现"lazy load",以便将数据延迟加载到内存中。

入门

最简单的加载器将文件读取为文本,并将其全部放入一个文档中。

from langchain.document_loaders import TextLoader

loader = TextLoader("./index.md")
loader.load()
[
Document(page_content='---\nsidebar_position: 0\n---\n# Document loaders\n\nUse document loaders to load data from a source as `Document`\'s. A `Document` is a piece of text\nand associated metadata. For example, there are document loaders for loading a simple `.txt` file, for loading the text\ncontents of any web page, or even for loading a transcript of a YouTube video.\n\nEvery document loader exposes two methods:\n1. "Load": load documents from the configured source\n2. "Load and split": load documents from the configured source and split them using the passed in text splitter\n\nThey optionally implement:\n\n3. "Lazy load": load documents into memory lazily\n', metadata={'source': '../docs/docs_skeleton/docs/modules/data_connection/document_loaders/index.md'})
]