UNPKG

n8n-nodes-google-vertex-embeddings-extended

Version:

n8n community sub-node for Google Vertex AI Embeddings with output dimensions and configurable batch size support - resolves LangChain compatibility issues

83 lines 4.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.logWrapper = logWrapper; const n8n_workflow_1 = require("n8n-workflow"); async function callMethodAsync(parameters) { try { return await parameters.method.call(this, ...parameters.arguments); } catch (error) { const connectedNode = parameters.executeFunctions.getNode(); throw new n8n_workflow_1.NodeOperationError(connectedNode, error); } } function logAiEvent(executeFunctions, eventType) { try { if ('logAiEvent' in executeFunctions && typeof executeFunctions.logAiEvent === 'function') { executeFunctions.logAiEvent({ type: eventType, }); } } catch (error) { } } function logWrapper(originalInstance, executeFunctions) { console.log('VertexEmbeddingsLogWrapper: Wrapping instance of type:', originalInstance.constructor.name); return new Proxy(originalInstance, { get(target, prop, receiver) { const originalValue = Reflect.get(target, prop, receiver); if (typeof originalValue === 'function' && typeof prop === 'string') { console.log('VertexEmbeddingsLogWrapper: Method accessed:', prop); } if ('embedDocuments' in target || 'embedQuery' in target) { if (prop === 'embedDocuments' && 'embedDocuments' in target) { return async (documents) => { console.log('VertexEmbeddingsLogWrapper: embedDocuments intercepted, docs:', documents?.length || 0); const connectionType = "ai_embedding"; const { index } = executeFunctions.addInputData(connectionType, [ [{ json: { documents } }], ]); const response = (await callMethodAsync.call(target, { executeFunctions, connectionType, currentNodeRunIndex: index, method: target[prop], arguments: [documents], })); console.log('VertexEmbeddingsLogWrapper: embedDocuments completed, embeddings:', response?.length || 0); logAiEvent(executeFunctions, 'ai-document-embedded'); executeFunctions.addOutputData(connectionType, index, [ [{ json: { response } }], ]); return response; }; } if (prop === 'embedQuery' && 'embedQuery' in target) { return async (query) => { console.log('VertexEmbeddingsLogWrapper: embedQuery intercepted, query length:', query?.length || 0); const connectionType = "ai_embedding"; const { index } = executeFunctions.addInputData(connectionType, [ [{ json: { query } }], ]); const response = (await callMethodAsync.call(target, { executeFunctions, connectionType, currentNodeRunIndex: index, method: target[prop], arguments: [query], })); console.log('VertexEmbeddingsLogWrapper: embedQuery completed, embedding dimension:', response?.length || 0); logAiEvent(executeFunctions, 'ai-query-embedded'); executeFunctions.addOutputData(connectionType, index, [ [{ json: { response } }], ]); return response; }; } } return originalValue; }, }); } //# sourceMappingURL=logWrapper.js.map