mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 03:01:10 +03:00
Late Chunking support for Jina Embeddings (#4002)
* Late Chunking support for Jina Embeddings * improved constructor handling. remove redundant code. * remove unnessary function overrides, since late_chunking parameter only needs to be stored in the class.
This commit is contained in:
@@ -2,6 +2,16 @@ import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Inter
|
|||||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
import { JinaEmbeddings } from '@langchain/community/embeddings/jina'
|
import { JinaEmbeddings } from '@langchain/community/embeddings/jina'
|
||||||
|
|
||||||
|
class ExtendedJinaEmbeddings extends JinaEmbeddings {
|
||||||
|
private late_chunking: boolean
|
||||||
|
|
||||||
|
constructor(fields: ConstructorParameters<typeof JinaEmbeddings>[0] & { late_chunking?: boolean }) {
|
||||||
|
const { late_chunking = false, ...restFields } = fields
|
||||||
|
super(restFields)
|
||||||
|
this.late_chunking = late_chunking
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class JinaAIEmbedding_Embeddings implements INode {
|
class JinaAIEmbedding_Embeddings implements INode {
|
||||||
label: string
|
label: string
|
||||||
name: string
|
name: string
|
||||||
@@ -17,7 +27,7 @@ class JinaAIEmbedding_Embeddings implements INode {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.label = 'Jina Embeddings'
|
this.label = 'Jina Embeddings'
|
||||||
this.name = 'jinaEmbeddings'
|
this.name = 'jinaEmbeddings'
|
||||||
this.version = 2.0
|
this.version = 3.0
|
||||||
this.type = 'JinaEmbeddings'
|
this.type = 'JinaEmbeddings'
|
||||||
this.icon = 'JinaAIEmbedding.svg'
|
this.icon = 'JinaAIEmbedding.svg'
|
||||||
this.category = 'Embeddings'
|
this.category = 'Embeddings'
|
||||||
@@ -34,7 +44,7 @@ class JinaAIEmbedding_Embeddings implements INode {
|
|||||||
label: 'Model Name',
|
label: 'Model Name',
|
||||||
name: 'modelName',
|
name: 'modelName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: 'jina-embeddings-v2-base-en',
|
default: 'jina-embeddings-v3',
|
||||||
description: 'Refer to <a href="https://jina.ai/embeddings/" target="_blank">JinaAI documentation</a> for available models'
|
description: 'Refer to <a href="https://jina.ai/embeddings/" target="_blank">JinaAI documentation</a> for available models'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -44,6 +54,15 @@ class JinaAIEmbedding_Embeddings implements INode {
|
|||||||
default: 1024,
|
default: 1024,
|
||||||
description:
|
description:
|
||||||
'Refer to <a href="https://jina.ai/embeddings/" target="_blank">JinaAI documentation</a> for available dimensions'
|
'Refer to <a href="https://jina.ai/embeddings/" target="_blank">JinaAI documentation</a> for available dimensions'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Allow Late Chunking',
|
||||||
|
name: 'allowLateChunking',
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'Refer to <a href="https://jina.ai/embeddings/" target="_blank">JinaAI documentation</a> guidance on late chunking',
|
||||||
|
default: false,
|
||||||
|
optional: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -51,13 +70,15 @@ class JinaAIEmbedding_Embeddings implements INode {
|
|||||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
const modelName = nodeData.inputs?.modelName as string
|
const modelName = nodeData.inputs?.modelName as string
|
||||||
const modelDimensions = nodeData.inputs?.modelDimensions as number
|
const modelDimensions = nodeData.inputs?.modelDimensions as number
|
||||||
|
const allowLateChunking = nodeData.inputs?.modelDimensions as boolean
|
||||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
const apiKey = getCredentialParam('jinaAIAPIKey', credentialData, nodeData)
|
const apiKey = getCredentialParam('jinaAIAPIKey', credentialData, nodeData)
|
||||||
|
|
||||||
const model = new JinaEmbeddings({
|
const model = new ExtendedJinaEmbeddings({
|
||||||
apiKey: apiKey,
|
apiKey: apiKey,
|
||||||
model: modelName,
|
model: modelName,
|
||||||
dimensions: modelDimensions
|
dimensions: modelDimensions,
|
||||||
|
late_chunking: allowLateChunking
|
||||||
})
|
})
|
||||||
|
|
||||||
return model
|
return model
|
||||||
|
|||||||
Reference in New Issue
Block a user