@n8n/n8n-nodes-langchain
Version:

106 lines • 4.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmbeddingsHuggingFaceInference = void 0;
const inference_1 = require("@huggingface/inference");
const hf_1 = require("@langchain/community/embeddings/hf");
const n8n_workflow_1 = require("n8n-workflow");
const ai_utilities_1 = require("@n8n/ai-utilities");
class EmbeddingsHuggingFaceInference {
constructor() {
this.description = {
displayName: 'Embeddings Hugging Face Inference',
name: 'embeddingsHuggingFaceInference',
icon: 'file:huggingface.svg',
group: ['transform'],
version: 1,
description: 'Use HuggingFace Inference Embeddings',
defaults: {
name: 'Embeddings HuggingFace Inference',
},
credentials: [
{
name: 'huggingFaceApi',
required: true,
},
],
codex: {
categories: ['AI'],
subcategories: {
AI: ['Embeddings'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingshuggingfaceinference/',
},
],
},
},
inputs: [],
outputs: [n8n_workflow_1.NodeConnectionTypes.AiEmbedding],
outputNames: ['Embeddings'],
properties: [
(0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiVectorStore]),
{
displayName: 'Each model is using different dimensional density for embeddings. Please make sure to use the same dimensionality for your vector store. The default model is using 768-dimensional embeddings.',
name: 'notice',
type: 'notice',
default: '',
},
{
displayName: 'Model Name',
name: 'modelName',
type: 'string',
default: 'sentence-transformers/distilbert-base-nli-mean-tokens',
description: 'The model name to use from HuggingFace library',
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
description: 'Additional options to add',
type: 'collection',
default: {},
options: [
{
displayName: 'Custom Inference Endpoint',
name: 'endpointUrl',
default: '',
description: 'Custom endpoint URL',
type: 'string',
},
{
displayName: 'Provider',
name: 'provider',
type: 'options',
options: inference_1.PROVIDERS_OR_POLICIES.map((value) => ({ value, name: value })),
default: 'auto',
},
],
},
],
};
}
async supplyData(itemIndex) {
this.logger.debug('Supply data for embeddings HF Inference');
const model = this.getNodeParameter('modelName', itemIndex, 'sentence-transformers/distilbert-base-nli-mean-tokens');
const credentials = await this.getCredentials('huggingFaceApi');
const options = this.getNodeParameter('options', itemIndex, {});
if ('provider' in options && !isValidHFProviderOrPolicy(options.provider)) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Unsupported provider');
}
const embeddings = new hf_1.HuggingFaceInferenceEmbeddings({
apiKey: credentials.apiKey,
model,
...options,
});
return {
response: (0, ai_utilities_1.logWrapper)(embeddings, this),
};
}
}
exports.EmbeddingsHuggingFaceInference = EmbeddingsHuggingFaceInference;
function isValidHFProviderOrPolicy(provider) {
return (typeof provider === 'string' && inference_1.PROVIDERS_OR_POLICIES.includes(provider));
}
//# sourceMappingURL=EmbeddingsHuggingFaceInference.node.js.map