Unstructured document loader interface.

Partition and load files using either the unstructured-client sdk and the Unstructured API or locally using the unstructured library.

API: This package is configured to work with the Unstructured API by default. To use the Unstructured API, set partitionViaApi: true and define apiKey. If you are running the unstructured API locally, you can change the API rule by defining url when you initialize the loader. The hosted Unstructured API requires an API key. See the links below to learn more about our API offerings and get an API key.

Local: To partition files locally, you must have the unstructured package installed. You can install it with pip install unstructured. By default the file loader uses the Unstructured partition function and will automatically detect the file type.

In addition to document specific partition parameters, Unstructured has a rich set of "chunking" parameters for post-processing elements into more useful text segments for uses cases such as Retrieval Augmented Generation (RAG). You can pass additional Unstructured kwargs to the loader to configure different unstructured settings.

Setup: Install the package:

npm install @langchain/unstructured

Set the API key in your environment:

export UNSTRUCTURED_API_KEY="your-api-key"

Instantiate:

import { UnstructuredLoader } from "@langchain/unstructured";

const loader = new UnstructuredLoader({
filePath: ["example.pdf", "fake.pdf"],
apiKey: process.env.UNSTRUCTURED_API_KEY,
partitionViaApi: true,
chunkingStrategy: "by_title",
strategy: "fast",
});
```

Load:
```typescript
const docs = await loader.load();

console.log(docs[0].pageContent.slice(0, 100));
console.log(docs[0].metadata);

https://docs.unstructured.io/api-reference/api-services/sdk https://docs.unstructured.io/api-reference/api-services/overview https://docs.unstructured.io/open-source/core-functionality/partitioning https://docs.unstructured.io/open-source/core-functionality/chunking

Type Parameters

Hierarchy (view full)

Constructors

Properties

client: UnstructuredClient
enableLogs: boolean = false
strategy: UnstructuredLoaderStrategy = "auto"
buffer?: Buffer
fileName?: string
filePath?: string | string[]
partitionViaApi?: boolean
postProcessors?: ((str: string) => string)[]
unstructuredFields?: Omit<PartitionParameters, "files" | "strategy">

Methods