@n8n/n8n-nodes-langchain
Version:
150 lines • 6.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmbeddingsNvidia = void 0;
const ai_utilities_1 = require("@n8n/ai-utilities");
const n8n_workflow_1 = require("n8n-workflow");
const helpers_1 = require("./helpers");
const searchModels_1 = require("./methods/searchModels");
class EmbeddingsNvidia {
constructor() {
this.methods = {
listSearch: {
searchModels: searchModels_1.searchModels,
},
};
this.description = {
displayName: 'NVIDIA Nemotron Embeddings',
name: 'embeddingsNvidia',
icon: { light: 'file:nvidia.svg', dark: 'file:nvidia.dark.svg' },
group: ['transform'],
version: [1],
description: 'Use NVIDIA NeMo Retriever embedding models from build.nvidia.com or a self-hosted NIM',
defaults: {
name: 'NVIDIA Nemotron Embeddings',
},
credentials: [
{
name: 'nvidiaApi',
required: true,
},
],
codex: {
categories: ['AI'],
subcategories: {
AI: ['Embeddings'],
},
alias: ['nvidia', 'nemotron', 'nemo', 'embeddings'],
resources: {
primaryDocumentation: [
{
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingsnvidia/',
},
],
},
},
inputs: [],
outputs: [n8n_workflow_1.NodeConnectionTypes.AiEmbedding],
outputNames: ['Embeddings'],
requestDefaults: {
ignoreHttpStatusErrors: true,
baseURL: '={{ $credentials?.url }}',
},
properties: [
(0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiVectorStore]),
{
displayName: 'Model',
name: 'model',
type: 'resourceLocator',
default: { mode: 'list', value: searchModels_1.DEFAULT_NVIDIA_EMBEDDING_MODEL },
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: 'nvidia/llama-3.2-nv-embedqa-1b-v2',
},
],
description: 'The NeMo Retriever embedding model. Choose from the list, or specify an ID for a self-hosted NIM. input_type is set automatically (passage when indexing, query when searching). <a href="https://build.nvidia.com/models">Learn more</a>.',
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
description: 'Additional options to add',
type: 'collection',
default: {},
options: [
{
displayName: 'Batch Size',
name: 'batchSize',
default: 512,
typeOptions: { maxValue: 2048 },
description: 'Maximum number of documents to send in each request',
type: 'number',
},
{
displayName: 'Strip New Lines',
name: 'stripNewLines',
default: true,
description: 'Whether to strip new lines from the input text',
type: 'boolean',
},
{
displayName: 'Dimensions',
name: 'dimensions',
default: undefined,
description: 'The number of dimensions the resulting output embeddings should have. Only supported by models with dynamic (Matryoshka) embeddings; leave unset to use the model default.',
type: 'number',
},
{
displayName: 'Timeout',
name: 'timeout',
default: -1,
description: 'Maximum amount of time a request is allowed to take in seconds. Set to -1 for no timeout.',
type: 'number',
},
],
},
],
};
}
async supplyData(itemIndex) {
this.logger.debug('Supply data for NVIDIA Nemotron embeddings');
const credentials = await this.getCredentials('nvidiaApi');
const modelName = this.getNodeParameter('model', itemIndex, '', {
extractValue: true,
});
const options = this.getNodeParameter('options', itemIndex, {});
if (options.timeout === -1) {
options.timeout = undefined;
}
const configuration = {
baseURL: credentials.url,
fetchOptions: {
dispatcher: (0, ai_utilities_1.getProxyAgent)(credentials.url, {}),
},
};
const embeddings = new helpers_1.NvidiaEmbeddings({
apiKey: credentials.apiKey || 'unused',
model: modelName,
...options,
configuration,
});
return {
response: (0, ai_utilities_1.logWrapper)(embeddings, this),
};
}
}
exports.EmbeddingsNvidia = EmbeddingsNvidia;
//# sourceMappingURL=EmbeddingsNvidia.node.js.map