mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-30 15:07:28 -08:00
87def60979
Github issue / Community forum post (link here to close automatically): https://community.n8n.io/t/langchain-memory-chat/23733 --------- Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Val <68596159+valya@users.noreply.github.com> Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: Deborah <deborah@starfallprojects.co.uk> Co-authored-by: Jesper Bylund <mail@jesperbylund.com> Co-authored-by: Jon <jonathan.bennetts@gmail.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Giulio Andreini <andreini@netseven.it> Co-authored-by: Mason Geloso <Mason.geloso@gmail.com> Co-authored-by: Mason Geloso <hone@Masons-Mac-mini.local> Co-authored-by: Mutasem Aldmour <mutasem@n8n.io>
105 lines
3 KiB
TypeScript
105 lines
3 KiB
TypeScript
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
|
|
import {
|
|
NodeConnectionType,
|
|
type IExecuteFunctions,
|
|
type INodeType,
|
|
type INodeTypeDescription,
|
|
type SupplyData,
|
|
} from 'n8n-workflow';
|
|
import { HuggingFaceInferenceEmbeddings } from 'langchain/embeddings/hf';
|
|
import { logWrapper } from '../../../utils/logWrapper';
|
|
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
|
|
|
export class EmbeddingsHuggingFaceInference implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
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/',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
inputs: [],
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
outputs: [NodeConnectionType.AiEmbedding],
|
|
outputNames: ['Embeddings'],
|
|
properties: [
|
|
getConnectionHintNoticeField([NodeConnectionType.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',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
|
|
this.logger.verbose('Supply data for embeddings HF Inference');
|
|
const model = this.getNodeParameter(
|
|
'modelName',
|
|
itemIndex,
|
|
'sentence-transformers/distilbert-base-nli-mean-tokens',
|
|
) as string;
|
|
const credentials = await this.getCredentials('huggingFaceApi');
|
|
const options = this.getNodeParameter('options', itemIndex, {}) as object;
|
|
|
|
const embeddings = new HuggingFaceInferenceEmbeddings({
|
|
apiKey: credentials.apiKey as string,
|
|
model,
|
|
...options,
|
|
});
|
|
|
|
return {
|
|
response: logWrapper(embeddings, this),
|
|
};
|
|
}
|
|
}
|