From 3556292367314eed365765fc274537d550baa4f9 Mon Sep 17 00:00:00 2001 From: definitelynotchirag Date: Tue, 15 Oct 2024 02:09:55 +0530 Subject: [PATCH 1/4] added Jina AI Embedding support --- .../credentials/JinaApi.credential.ts | 25 +++++ packages/components/models.json | 9 ++ .../JinaAIEmbedding/JinaAIEmbedding.svg | 5 + .../JinaAIEmbedding/JinaAIEmbedding.ts | 97 +++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 packages/components/credentials/JinaApi.credential.ts create mode 100644 packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.svg create mode 100644 packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts diff --git a/packages/components/credentials/JinaApi.credential.ts b/packages/components/credentials/JinaApi.credential.ts new file mode 100644 index 00000000000..2e6a9e30bbe --- /dev/null +++ b/packages/components/credentials/JinaApi.credential.ts @@ -0,0 +1,25 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class JinaAICredential implements INodeCredential { + label: string + name: string + version: number + description: string + inputs: INodeParams[] + + constructor() { + this.label = 'JinaAI API' + this.name = 'jinaAIApi' + this.version = 1.0 + this.description = 'You can get your API key from official console here.' + this.inputs = [ + { + label: 'JinaAI API Key', + name: 'jinaAIAPIKey', + type: 'password' + } + ] + } +} + +module.exports = { credClass: JinaAICredential } \ No newline at end of file diff --git a/packages/components/models.json b/packages/components/models.json index 83bcf615e77..097bdfe6dbe 100644 --- a/packages/components/models.json +++ b/packages/components/models.json @@ -1141,6 +1141,15 @@ } ] }, + { + "name": "jinaEmbeddings", + "models": [ + { + "label": "jina-embeddings-v2-base-en", + "name": "jina-embeddings-v2-base-en" + } + ] + }, { "name": "voyageAIEmbeddings", "models": [ diff --git a/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.svg b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.svg new file mode 100644 index 00000000000..95b99d8b5e5 --- /dev/null +++ b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts new file mode 100644 index 00000000000..107703aa0bd --- /dev/null +++ b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts @@ -0,0 +1,97 @@ +import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' + +import { MODEL_TYPE, getModels } from '../../../src/modelLoader' + +import { JinaEmbeddings, JinaEmbeddingsParams } from '@langchain/community/embeddings/jina' + +class JinaAIEmbedding_Embeddings implements INode { + label: string + name: string + version: number + type: string + icon: string + category: string + description: string + baseClasses: string[] + credential: INodeParams + inputs: INodeParams[] + + constructor() { + this.label = 'Jina Embeddings' + this.name = 'jinaEmbeddings' + this.version = 1.0 + this.type = 'JinaEmbeddings' + this.icon = 'JinaAIEmbedding.svg' + this.category = 'Embeddings' + this.description = 'JinaAI API to generate embeddings for a given text' + this.baseClasses = [this.type, ...getBaseClasses(JinaEmbeddings)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['jinaAIApi'] + } + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'asyncOptions', + loadMethod: 'listModels', + default: 'jina-embeddings-v2-base-en' + }, + // { + // label: 'Strip New Lines', + // name: 'stripNewLines', + // type: 'boolean', + // optional: true, + // additionalParams: true + // }, + // { + // label: 'Batch Size', + // name: 'batchSize', + // type: 'number', + // optional: true, + // additionalParams: true + // }, + // { + // label: 'Timeout', + // name: 'timeout', + // type: 'number', + // optional: true, + // additionalParams: true + // } + ] + } + + loadMethods = { + async listModels(): Promise { + return await getModels(MODEL_TYPE.EMBEDDING, 'jinaEmbeddings') + } + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + // const batchSize = nodeData.inputs?.batchSize as string + // const stripNewLines = nodeData.inputs?.stripNewLines as boolean + // const overrideEndpoint = nodeData.inputs?.overrideEndpoint as string + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const apiKey = getCredentialParam('jinaAIAPIKey', credentialData, nodeData) + + const obj: JinaEmbeddingsParams = { + apiKey: apiKey, + model: modelName + } + + // if (batchSize) obj.batchSize = parseInom '../../../src/Interface' +// import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils't(batchSize, 10) + // if (stripNewLines) obj.stripNewLines = stripNewLines + // if (overrideEndpoint) obj.endpoint = overrideEndpoint + + const model = new JinaEmbeddings(obj) + return model + } +} + +module.exports = { nodeClass: JinaAIEmbedding_Embeddings } From e3622e731a8a65f1f4472edd49a61bff29bc2d52 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Wed, 16 Oct 2024 16:10:41 +0100 Subject: [PATCH 2/4] Update JinaAIEmbedding.ts Change model name to string type --- .../JinaAIEmbedding/JinaAIEmbedding.ts | 49 ++----------------- 1 file changed, 5 insertions(+), 44 deletions(-) diff --git a/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts index 107703aa0bd..a85c4f88f33 100644 --- a/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts +++ b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts @@ -1,8 +1,5 @@ -import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface' +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' - -import { MODEL_TYPE, getModels } from '../../../src/modelLoader' - import { JinaEmbeddings, JinaEmbeddingsParams } from '@langchain/community/embeddings/jina' class JinaAIEmbedding_Embeddings implements INode { @@ -36,46 +33,15 @@ class JinaAIEmbedding_Embeddings implements INode { { label: 'Model Name', name: 'modelName', - type: 'asyncOptions', - loadMethod: 'listModels', - default: 'jina-embeddings-v2-base-en' - }, - // { - // label: 'Strip New Lines', - // name: 'stripNewLines', - // type: 'boolean', - // optional: true, - // additionalParams: true - // }, - // { - // label: 'Batch Size', - // name: 'batchSize', - // type: 'number', - // optional: true, - // additionalParams: true - // }, - // { - // label: 'Timeout', - // name: 'timeout', - // type: 'number', - // optional: true, - // additionalParams: true - // } + type: 'string', + default: 'jina-embeddings-v2-base-en', + description: 'Refer to JinaAI documentation for available models' + } ] } - loadMethods = { - async listModels(): Promise { - return await getModels(MODEL_TYPE.EMBEDDING, 'jinaEmbeddings') - } - } - async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const modelName = nodeData.inputs?.modelName as string - // const batchSize = nodeData.inputs?.batchSize as string - // const stripNewLines = nodeData.inputs?.stripNewLines as boolean - // const overrideEndpoint = nodeData.inputs?.overrideEndpoint as string - const credentialData = await getCredentialData(nodeData.credential ?? '', options) const apiKey = getCredentialParam('jinaAIAPIKey', credentialData, nodeData) @@ -84,11 +50,6 @@ class JinaAIEmbedding_Embeddings implements INode { model: modelName } - // if (batchSize) obj.batchSize = parseInom '../../../src/Interface' -// import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils't(batchSize, 10) - // if (stripNewLines) obj.stripNewLines = stripNewLines - // if (overrideEndpoint) obj.endpoint = overrideEndpoint - const model = new JinaEmbeddings(obj) return model } From acfa6707dbee0b0d9088f6ea2ed8045c8ff2e9f7 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Wed, 16 Oct 2024 16:11:08 +0100 Subject: [PATCH 3/4] removed jina embeddings --- packages/components/models.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/components/models.json b/packages/components/models.json index 097bdfe6dbe..83bcf615e77 100644 --- a/packages/components/models.json +++ b/packages/components/models.json @@ -1141,15 +1141,6 @@ } ] }, - { - "name": "jinaEmbeddings", - "models": [ - { - "label": "jina-embeddings-v2-base-en", - "name": "jina-embeddings-v2-base-en" - } - ] - }, { "name": "voyageAIEmbeddings", "models": [ From 55a557a59f9e3c01e8174d4eb92ff0e357882512 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Wed, 16 Oct 2024 16:14:02 +0100 Subject: [PATCH 4/4] lint fix --- packages/components/credentials/JinaApi.credential.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/credentials/JinaApi.credential.ts b/packages/components/credentials/JinaApi.credential.ts index 2e6a9e30bbe..4041c7befbd 100644 --- a/packages/components/credentials/JinaApi.credential.ts +++ b/packages/components/credentials/JinaApi.credential.ts @@ -22,4 +22,4 @@ class JinaAICredential implements INodeCredential { } } -module.exports = { credClass: JinaAICredential } \ No newline at end of file +module.exports = { credClass: JinaAICredential }