Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Late Chunking support for Jina Embeddings #4002

Merged
merged 3 commits into from
Feb 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Inter
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
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 {
label: string
name: string
Expand All @@ -17,7 +27,7 @@ class JinaAIEmbedding_Embeddings implements INode {
constructor() {
this.label = 'Jina Embeddings'
this.name = 'jinaEmbeddings'
this.version = 2.0
this.version = 3.0
this.type = 'JinaEmbeddings'
this.icon = 'JinaAIEmbedding.svg'
this.category = 'Embeddings'
Expand All @@ -34,7 +44,7 @@ class JinaAIEmbedding_Embeddings implements INode {
label: 'Model Name',
name: 'modelName',
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'
},
{
Expand All @@ -44,20 +54,31 @@ class JinaAIEmbedding_Embeddings implements INode {
default: 1024,
description:
'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
}
]
}

async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const modelName = nodeData.inputs?.modelName as string
const modelDimensions = nodeData.inputs?.modelDimensions as number
const allowLateChunking = nodeData.inputs?.modelDimensions as boolean
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const apiKey = getCredentialParam('jinaAIAPIKey', credentialData, nodeData)

const model = new JinaEmbeddings({
const model = new ExtendedJinaEmbeddings({
apiKey: apiKey,
model: modelName,
dimensions: modelDimensions
dimensions: modelDimensions,
late_chunking: allowLateChunking
})

return model
Expand Down