跳到主要内容
AirtableLoader 类提供了从 Airtable 表中加载文档的功能。它支持两种主要方法:
  1. load(): 一次性检索所有记录,适用于小型到中型数据集。
  2. loadLazy(): 逐条获取记录,对于大型数据集更节省内存。

先决条件

请确保您的 Airtable API 令牌已作为环境变量提供。
process.env.AIRTABLE_API_TOKEN = "YOUR_AIRTABLE_API_TOKEN";

用法

import { AirtableLoader } from "@langchain/community/document_loaders/web/airtable";
import { Document } from "@langchain/core/documents";

// Default airtable loader
const loader = new AirtableLoader({
  tableId: "YOUR_TABLE_ID",
  baseId: "YOUR_BASE_ID",
});

try {
  const documents: Document[] = await loader.load();
  console.log("Loaded documents:", documents);
} catch (error) {
  console.error("Error loading documents:", error);
}

// Lazy airtable loader
const loaderLazy = new AirtableLoader({
  tableId: "YOUR_TABLE_ID",
  baseId: "YOUR_BASE_ID",
});

try {
  console.log("Lazily loading documents:");
  for await (const document of loader.loadLazy()) {
    console.log("Loaded document:", document);
  }
} catch (error) {
  console.error("Error loading documents lazily:", error);
}

// Airtable loader with specific view
const loaderView = new AirtableLoader({
  tableId: "YOUR_TABLE_ID",
  baseId: "YOUR_BASE_ID",
  kwargs: { view: "YOUR_VIEW_NAME" },
});

try {
  const documents: Document[] = await loader.load();
  console.log("Loaded documents with view:", documents);
} catch (error) {
  console.error("Error loading documents with view:", error);
}

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