I’m missing something obvious, and hopefully, someone can point me in the right direction.
I’m trying to extend the AI options using the LangChain Code nodes.
I want to build a few different LangChain nodes, but for the sake of this example, let’s use a custom Document loader.
Here’s the code (inside Supply Data) for my custom Document loader (tested and works with built-in AI nodes like In-Memory Vector Store). The output Type of this sub-node has been set to Document:
const { Document } = require("langchain/document");
class MockDocumentLoader {
constructor(mockData) {
this.mockData = mockData;
}
async load() {
// Construct Document objects from your mock data
const documents = this.mockData.map((data) => {
return new Document({ pageContent: data.page_content, metadata: data.metadata || {} });
});
return documents;
}
}
const mockData = [
{ page_content: "The first document.", metadata: { source: "Wikipedia" } },
{ page_content: "Another document for testing.", metadata: { source: "Google" } },
];
return new MockDocumentLoader(mockData)
Now, in my root LangChain node, I call the custom Document loader through this code (as explained here):
const loader = (await this.getInputConnectionData("ai_document", 0))[0]
const parentDocuments = await loader.load()
The root LangChain Code node has input Type set to Main and to Document.
Now, no matter what I try, when I run this root node, the sub-node always returns the following error message: this.getMode is not a function.
Again, what surprises me is that the sub-node works just fine with the built-in AI nodes, just not (yet) with a custom LangChain Code root node.
What am I missing?
Information on your n8n setup
- n8n version: 1.33.1
- Database: SQLite
- n8n EXECUTIONS_PROCESS setting: own, main
- Running n8n via: npm
- Operating system: Ubuntu 22.02