UNPKG

@n8n/n8n-nodes-langchain

Version:
125 lines 4.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmbeddingsOracleDb = exports.generationFields = void 0; const embeddings_1 = require("@langchain/core/embeddings"); const ai_utilities_1 = require("@n8n/ai-utilities"); const langchain_oracledb_1 = require("@oracle/langchain-oracledb"); const transport_1 = require("n8n-nodes-base/dist/nodes/Oracle/Sql/transport"); const n8n_workflow_1 = require("n8n-workflow"); const listModels_1 = require("./listModels"); exports.generationFields = [ { displayName: 'Model', name: 'model', type: 'resourceLocator', default: { mode: 'list', value: 'ALL_MINILM_L12_V2' }, required: true, modes: [ { displayName: 'From List', name: 'list', type: 'list', placeholder: 'Select a model...', typeOptions: { searchListMethod: 'searchModels', searchable: true, }, }, { displayName: 'ID', name: 'id', type: 'string', placeholder: 'ALL_MINILM_L12_V2', }, ], description: 'The model. Choose from the list, or specify an ID.', }, ]; class PooledOracleEmbeddings extends embeddings_1.Embeddings { constructor(getPool, pref) { super({}); this.getPool = getPool; this.pref = pref; } async withConnection(executor) { const pool = await this.getPool(); const connection = await pool.getConnection(); try { const embeddings = new langchain_oracledb_1.OracleEmbeddings(connection, this.pref); return await executor(embeddings); } finally { await connection.close(); } } async embedDocuments(documents) { return await this.withConnection(async (embeddings) => await embeddings.embedDocuments(documents)); } async embedQuery(query) { return await this.withConnection(async (embeddings) => await embeddings.embedQuery(query)); } } class EmbeddingsOracleDb { constructor() { this.methods = { listSearch: { searchModels: listModels_1.searchModels, }, }; this.description = { displayName: 'Embeddings Oracle Database', name: 'embeddingsOracleDb', icon: 'file:../../shared/icons/oracle.svg', group: ['transform'], version: 1, description: 'Use ONNX Embeddings', defaults: { name: 'Embeddings ONNX', }, credentials: [ { name: 'oracleDBApi', required: true, }, ], codex: { categories: ['AI'], subcategories: { AI: ['Embeddings'], }, resources: { primaryDocumentation: [ { url: 'https://docs.oracle.com/en/database/oracle/oracle-database/26/vecse/import-onnx-models-oracle-ai-database-end-end-example.html', }, ], }, }, inputs: [], outputs: [n8n_workflow_1.NodeConnectionTypes.AiEmbedding], outputNames: ['Embeddings'], properties: [ (0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiVectorStore]), ...exports.generationFields, ], }; } async supplyData(itemIndex) { this.logger.debug('Supply data for ONNX embeddings Oracle'); const modelName = this.getNodeParameter('model', itemIndex, '', { extractValue: true, }); const credentials = await this.getCredentials('oracleDBApi'); const pref = { provider: 'database', model: modelName, }; const getPool = async () => await transport_1.configureOracleDB.call(this, credentials); const embeddings = new PooledOracleEmbeddings(getPool, pref); return { response: (0, ai_utilities_1.logWrapper)(embeddings, this), }; } } exports.EmbeddingsOracleDb = EmbeddingsOracleDb; //# sourceMappingURL=EmbeddingsOracleDb.node.js.map