n8n-nodes-databricks
Version:
Databricks node for n8n
36 lines • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleInsertOperation = handleInsertOperation;
const n8n_workflow_1 = require("n8n-workflow");
const helpers_1 = require("../../../../../utils/helpers");
const processDocuments_1 = require("../../processDocuments");
async function handleInsertOperation(context, args, embeddings) {
var _a, _b;
const nodeVersion = context.getNode().typeVersion;
const items = context.getInputData();
const documentInput = (await context.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiDocument, 0));
const resultData = [];
const documentsForEmbedding = [];
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
if ((_a = context.getExecutionCancelSignal()) === null || _a === void 0 ? void 0 : _a.aborted) {
break;
}
const itemData = items[itemIndex];
const processedDocuments = await (0, processDocuments_1.processDocument)(documentInput, itemData, itemIndex);
resultData.push(...processedDocuments.serializedDocuments);
documentsForEmbedding.push(...processedDocuments.processedDocuments);
if (nodeVersion === 1) {
await args.populateVectorStore(context, embeddings, processedDocuments.processedDocuments, itemIndex);
}
(0, helpers_1.logAiEvent)(context, 'ai-vector-store-populated');
}
if (nodeVersion >= 1.1) {
const embeddingBatchSize = (_b = context.getNodeParameter('embeddingBatchSize', 0, 200)) !== null && _b !== void 0 ? _b : 200;
for (let i = 0; i < documentsForEmbedding.length; i += embeddingBatchSize) {
const nextBatch = documentsForEmbedding.slice(i, i + embeddingBatchSize);
await args.populateVectorStore(context, embeddings, nextBatch, 0);
}
}
return resultData;
}
//# sourceMappingURL=insertOperation.js.map