> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# UnstructuredLoader 集成

> 使用 LangChain JavaScript 集成 UnstructuredLoader 文档加载器。

<Tip>
  **兼容性**：仅适用于 Node.js 环境。
</Tip>

本笔记本提供了快速入门 `UnstructuredLoader` [文档加载器](/oss/javascript/integrations/document_loaders) 的简要概述。有关 `UnstructuredLoader` 所有功能和配置的详细文档，请参阅 [API 参考](https://reference.langchain.com/javascript/langchain-community/document_loaders/fs/unstructured/UnstructuredLoader)。

## 概述

### 集成详情

| 类                                                                                                                                          | 包                                                                            |    兼容性    | 本地运行 | [Python 支持](https://python.langchain.com/docs/integrations/document_loaders/unstructured_file) |
| :----------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------- | :-------: | :--: | :--------------------------------------------------------------------------------------------: |
| [`UnstructuredLoader`](https://reference.langchain.com/javascript/langchain-community/document_loaders/fs/unstructured/UnstructuredLoader) | [`@langchain/community`](https://www.npmjs.com/package/@langchain/community) | 仅 Node.js |   ✅  |                                                ✅                                               |

## 设置

要使用 `UnstructuredLoader` 文档加载器，您需要安装 `@langchain/community` 集成包，并创建一个 Unstructured 账户以获取 API 密钥。

### 本地运行

您可以使用 Docker 在本地计算机上运行 Unstructured。为此，您需要先[安装 Docker](https://docs.docker.com/get-docker/)。

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docker run -p 8000:8000 -d --rm --name unstructured-api downloads.unstructured.io/unstructured-io/unstructured-api:latest --port 8000 --host 0.0.0.0
```

### 凭证

前往 [unstructured.io](https://unstructured.io/api-key-hosted) 注册 Unstructured 并生成 API 密钥。完成后，设置 `UNSTRUCTURED_API_KEY` 环境变量：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export UNSTRUCTURED_API_KEY="your-api-key"
```

### 安装

LangChain UnstructuredLoader 集成位于 `@langchain/community` 包中：

<CodeGroup>
  ```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  npm install @langchain/community @langchain/core
  ```

  ```bash yarn theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  yarn add @langchain/community @langchain/core
  ```

  ```bash pnpm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pnpm add @langchain/community @langchain/core
  ```
</CodeGroup>

## 实例化

现在我们可以实例化模型对象并加载文档：

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { UnstructuredLoader } from "@langchain/community/document_loaders/fs/unstructured"

const loader = new UnstructuredLoader("../../../../../../examples/src/document_loaders/example_data/notion.mdx")
```

## 加载

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const docs = await loader.load()
docs[0]
```

```javascript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
Document {
  pageContent: '# Testing the notion markdownloader',
  metadata: {
    filename: 'notion.mdx',
    languages: [ 'eng' ],
    filetype: 'text/plain',
    category: 'NarrativeText'
  },
  id: undefined
}
```

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
console.log(docs[0].metadata)
```

```javascript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  filename: 'notion.mdx',
  languages: [ 'eng' ],
  filetype: 'text/plain',
  category: 'NarrativeText'
}
```

## 目录加载

您还可以使用 [`UnstructuredDirectoryLoader`](https://reference.langchain.com/javascript/langchain-community/document_loaders/fs/unstructured/UnstructuredDirectoryLoader) 加载目录中的所有文件，它继承自 [`DirectoryLoader`](/oss/javascript/integrations/document_loaders/file_loaders/directory)：

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { UnstructuredDirectoryLoader } from "@langchain/community/document_loaders/fs/unstructured";

const directoryLoader = new UnstructuredDirectoryLoader(
  "../../../../../../examples/src/document_loaders/example_data/",
  {}
);
const directoryDocs = await directoryLoader.load();
console.log("directoryDocs.length: ", directoryDocs.length);
console.log(directoryDocs[0])

```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
Unknown file type: Star_Wars_The_Clone_Wars_S06E07_Crisis_at_the_Heart.srt
Unknown file type: test.mp3
```

```javascript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
directoryDocs.length:  247
Document {
  pageContent: 'Bitcoin: A Peer-to-Peer Electronic Cash System',
  metadata: {
    filetype: 'application/pdf',
    languages: [ 'eng' ],
    page_number: 1,
    filename: 'bitcoin.pdf',
    category: 'Title'
  },
  id: undefined
}
```

***

## API 参考

有关 `UnstructuredLoader` 所有功能和配置的详细文档，请参阅 [API 参考](https://reference.langchain.com/javascript/langchain-community/document_loaders/fs/unstructured/UnstructuredLoader)。

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\javascript\integrations\document_loaders\file_loaders\unstructured.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
