跳到主要内容
兼容性仅在 Node.js 上可用。
本文档介绍了如何从 S3 文件对象加载文档对象。

设置

要运行此索引,您需要预先设置好 Unstructured,并使其在一个可用的 URL 端点运行。它也可以配置为本地运行。 有关如何执行此操作的信息,请参阅此处的文档。 您还需要安装官方的 AWS SDK:
npm
npm install @langchain/community @langchain/core @aws-sdk/client-s3

用法

一旦 Unstructured 配置完成,您就可以使用 S3 加载器加载文件,然后将其转换为 Document。 您可以选择提供一个 s3Config 参数来指定您的存储桶区域、访问密钥和秘密访问密钥。如果未提供这些信息,您将需要在您的环境中(例如,通过运行 aws configure)设置它们。
import { S3Loader } from "@langchain/community/document_loaders/web/s3";

const loader = new S3Loader({
  bucket: "my-document-bucket-123",
  key: "AccountingOverview.pdf",
  s3Config: {
    region: "us-east-1",
    credentials: {
      accessKeyId: "AKIAIOSFODNN7EXAMPLE",
      secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
    },
  },
  unstructuredAPIURL: "https://:8000/general/v0/general",
  unstructuredAPIKey: "", // this will be soon required
});

const docs = await loader.load();

console.log(docs);

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.