A class that extends the BaseDocumentLoader and implements the DocumentLoader interface. It represents a document loader that loads documents from an Apify dataset.

const loader = new ApifyDatasetLoader("your-dataset-id", {
datasetMappingFunction: (item) =>
new Document({
pageContent: item.text || "",
metadata: { source: item.url },
}),
clientOptions: {
token: "your-apify-token",
},
});

const docs = await loader.load();

const chain = new RetrievalQAChain();
const res = await chain.invoke({ query: "What is LangChain?" });

console.log(res.text);
console.log(res.sourceDocuments.map((d) => d.metadata.source));

Type Parameters

  • Metadata extends Record<string, any>

Hierarchy (view full)

Implements

Constructors

Properties

apifyClient: ApifyClient
caller: AsyncCaller
datasetId: string
datasetMappingFunction: ApifyDatasetMappingFunction<Metadata>

Methods

  • Parameters

    • Optionalsplitter: BaseDocumentTransformer<DocumentInterface<Record<string, any>>[], DocumentInterface<Record<string, any>>[]>

    Returns Promise<Document<Record<string, any>>[]>

    A Promise that resolves with an array of Document instances, each split according to the provided TextSplitter.

    Use this.load() and splitter.splitDocuments() individually. Loads the documents and splits them using a specified text splitter.

  • Create an ApifyDatasetLoader by calling an Actor on the Apify platform and waiting for its results to be ready.

    Type Parameters

    • Metadata extends Record<string, any>

    Parameters

    • actorId: string

      The ID or name of the Actor on the Apify platform.

    • input: Record<string | number, unknown>

      The input object of the Actor that you're trying to run.

    • config: {
          callOptions?: ActorCallOptions;
          clientOptions?: ApifyClientOptions;
          datasetMappingFunction: ApifyDatasetMappingFunction<Metadata>;
      }

      Options specifying settings for the Actor run.

      • OptionalcallOptions?: ActorCallOptions
      • OptionalclientOptions?: ApifyClientOptions
      • datasetMappingFunction: ApifyDatasetMappingFunction<Metadata>

        A function that takes a single object (an Apify dataset item) and converts it to an instance of the Document class.

    Returns Promise<ApifyDatasetLoader<Metadata>>

    An instance of ApifyDatasetLoader with the results from the Actor run.

  • Create an ApifyDatasetLoader by calling a saved Actor task on the Apify platform and waiting for its results to be ready.

    Type Parameters

    • Metadata extends Record<string, any>

    Parameters

    • taskId: string

      The ID or name of the task on the Apify platform.

    • input: Record<string | number, unknown>

      The input object of the task that you're trying to run. Overrides the task's saved input.

    • config: {
          callOptions?: TaskCallOptions;
          clientOptions?: ApifyClientOptions;
          datasetMappingFunction: ApifyDatasetMappingFunction<Metadata>;
      }

      Options specifying settings for the task run.

      • OptionalcallOptions?: TaskCallOptions

        Options specifying settings for the task run.

      • OptionalclientOptions?: ApifyClientOptions

        Options specifying settings for the Apify client.

      • datasetMappingFunction: ApifyDatasetMappingFunction<Metadata>

        A function that takes a single object (an Apify dataset item) and converts it to an instance of the Document class.

    Returns Promise<ApifyDatasetLoader<Metadata>>

    An instance of ApifyDatasetLoader with the results from the task's run.