From ba6ab6307efab9437b6b88958473edc63d053c36 Mon Sep 17 00:00:00 2001 From: Psylockz Date: Fri, 12 Dec 2025 20:36:17 +0100 Subject: [PATCH 01/13] Create AzureRerankerApi.credential.ts Add Azure Foundry Reranker integration --- .../AzureRerankerApi.credential.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 packages/components/credentials/AzureRerankerApi.credential.ts diff --git a/packages/components/credentials/AzureRerankerApi.credential.ts b/packages/components/credentials/AzureRerankerApi.credential.ts new file mode 100644 index 00000000000..67bbc1c513a --- /dev/null +++ b/packages/components/credentials/AzureRerankerApi.credential.ts @@ -0,0 +1,33 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class AzureRerankerApi implements INodeCredential { + label: string + name: string + version: number + description: string + inputs: INodeParams[] + + constructor() { + this.label = 'Azure Foundry API' + this.name = 'azureFoundryApi' + this.version = 1.0 + this.description = 'Refer to Azure AI Foundry documentation for setup instructions' + this.inputs = [ + { + label: 'Azure Foundry API Key', + name: 'azureFoundryApiKey', + type: 'password', + description: 'Your Azure AI Foundry API key' + }, + { + label: 'Azure Foundry Endpoint', + name: 'azureFoundryEndpoint', + type: 'string', + placeholder: 'https://your-foundry-instance.services.ai.azure.com/providers/cohere/v2/rerank', + description: 'Your Azure AI Foundry endpoint URL' + } + ] + } +} + +module.exports = { credClass: AzureRerankerApi } From 54a6d919f68e1a4ba6ef8436cda907bf0a96e0f6 Mon Sep 17 00:00:00 2001 From: Psylockz Date: Fri, 12 Dec 2025 20:43:20 +0100 Subject: [PATCH 02/13] Create test --- packages/components/nodes/retrievers/AzureRerankRetriever/test | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/components/nodes/retrievers/AzureRerankRetriever/test diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/test b/packages/components/nodes/retrievers/AzureRerankRetriever/test new file mode 100644 index 00000000000..eb1ae458f8e --- /dev/null +++ b/packages/components/nodes/retrievers/AzureRerankRetriever/test @@ -0,0 +1 @@ +... From a675e904d0a092692c4b8feed14d4fcb6c6b9eee Mon Sep 17 00:00:00 2001 From: Psylockz Date: Fri, 12 Dec 2025 20:44:04 +0100 Subject: [PATCH 03/13] Add files via upload feat: Add Azure Foundry Reranker integration --- .../AzureRerankRetriever/03513-icon-service-AI-Studio.svg | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/components/nodes/retrievers/AzureRerankRetriever/03513-icon-service-AI-Studio.svg diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/03513-icon-service-AI-Studio.svg b/packages/components/nodes/retrievers/AzureRerankRetriever/03513-icon-service-AI-Studio.svg new file mode 100644 index 00000000000..710e86fdb2b --- /dev/null +++ b/packages/components/nodes/retrievers/AzureRerankRetriever/03513-icon-service-AI-Studio.svg @@ -0,0 +1 @@ + \ No newline at end of file From e887f53a732e7f5f3643c5881d61c3d8644d84d8 Mon Sep 17 00:00:00 2001 From: Psylockz Date: Fri, 12 Dec 2025 20:44:52 +0100 Subject: [PATCH 04/13] Delete packages/components/nodes/retrievers/AzureRerankRetriever/test --- packages/components/nodes/retrievers/AzureRerankRetriever/test | 1 - 1 file changed, 1 deletion(-) delete mode 100644 packages/components/nodes/retrievers/AzureRerankRetriever/test diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/test b/packages/components/nodes/retrievers/AzureRerankRetriever/test deleted file mode 100644 index eb1ae458f8e..00000000000 --- a/packages/components/nodes/retrievers/AzureRerankRetriever/test +++ /dev/null @@ -1 +0,0 @@ -... From fd781b3c87d2ed5f26661496962f658da19dc974 Mon Sep 17 00:00:00 2001 From: Psylockz Date: Fri, 12 Dec 2025 20:49:24 +0100 Subject: [PATCH 05/13] feat: Add Azure Foundry Reranker integration --- .../nodes/retrievers/AzureRerankRetriever/azurefoundry.svg | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/components/nodes/retrievers/AzureRerankRetriever/azurefoundry.svg diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/azurefoundry.svg b/packages/components/nodes/retrievers/AzureRerankRetriever/azurefoundry.svg new file mode 100644 index 00000000000..41f503f589a --- /dev/null +++ b/packages/components/nodes/retrievers/AzureRerankRetriever/azurefoundry.svg @@ -0,0 +1 @@ +AzureAI \ No newline at end of file From 1ce5c799fdbff890951df398047b3aa2e65342c5 Mon Sep 17 00:00:00 2001 From: Psylockz Date: Fri, 12 Dec 2025 20:50:21 +0100 Subject: [PATCH 06/13] Delete packages/components/nodes/retrievers/AzureRerankRetriever/03513-icon-service-AI-Studio.svg --- .../AzureRerankRetriever/03513-icon-service-AI-Studio.svg | 1 - 1 file changed, 1 deletion(-) delete mode 100644 packages/components/nodes/retrievers/AzureRerankRetriever/03513-icon-service-AI-Studio.svg diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/03513-icon-service-AI-Studio.svg b/packages/components/nodes/retrievers/AzureRerankRetriever/03513-icon-service-AI-Studio.svg deleted file mode 100644 index 710e86fdb2b..00000000000 --- a/packages/components/nodes/retrievers/AzureRerankRetriever/03513-icon-service-AI-Studio.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file From 94593f45c9b7dda66c294cb9007b6e05230297c3 Mon Sep 17 00:00:00 2001 From: Psylockz Date: Fri, 12 Dec 2025 21:16:08 +0100 Subject: [PATCH 07/13] feat: Add Azure Reranker integration --- .../AzureRerankRetriever/AzureRerank.ts | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts new file mode 100644 index 00000000000..31f45520525 --- /dev/null +++ b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts @@ -0,0 +1,57 @@ +import axios from 'axios' +import { Callbacks } from '@langchain/core/callbacks/manager' +import { Document } from '@langchain/core/documents' +import { BaseDocumentCompressor } from 'langchain/retrievers/document_compressors' + +export class AzureRerank extends BaseDocumentCompressor { + private AzureAPIKey: any + private AZURE_API_URL: string + private readonly model: string + private readonly k: number + private readonly maxChunksPerDoc: number + constructor(AzureAPIKey: string, AZURE_API_URL: string, model: string, k: number, maxChunksPerDoc: number) { + super() + this.AzureAPIKey = AzureAPIKey + this.AZURE_API_URL = AZURE_API_URL + this.model = model + this.k = k + this.maxChunksPerDoc = maxChunksPerDoc + } + async compressDocuments( + documents: Document>[], + query: string, + _?: Callbacks | undefined + ): Promise>[]> { + // avoid empty api call + if (documents.length === 0) { + return [] + } + const config = { + headers: { + 'api-key': `${this.AzureAPIKey}`, + 'Content-Type': 'application/json', + Accept: 'application/json' + } + } + const data = { + model: this.model, + top_n: this.k, + max_chunks_per_doc: this.maxChunksPerDoc, + query: query, + return_documents: false, + documents: documents.map((doc) => doc.pageContent) + } + try { + let returnedDocs = await axios.post(this.AZURE_API_URL, data, config) + const finalResults: Document>[] = [] + returnedDocs.data.results.forEach((result: any) => { + const doc = documents[result.index] + doc.metadata.relevance_score = result.relevance_score + finalResults.push(doc) + }) + return finalResults.splice(0, this.k) + } catch (error) { + return documents + } + } +} From ceee2cf394929d77aa985614666bfa46ee0607d6 Mon Sep 17 00:00:00 2001 From: Psylockz Date: Fri, 12 Dec 2025 21:36:40 +0100 Subject: [PATCH 08/13] feat: Add Azure Reranker integration --- .../AzureRerankRetriever.ts | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts new file mode 100644 index 00000000000..5b3577b8212 --- /dev/null +++ b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts @@ -0,0 +1,157 @@ +import { BaseRetriever } from '@langchain/core/retrievers' +import { VectorStoreRetriever } from '@langchain/core/vectorstores' +import { ContextualCompressionRetriever } from 'langchain/retrievers/contextual_compression' +import { AzureRerank } from './AzureRerank' +import { getCredentialData, getCredentialParam, handleEscapeCharacters } from '../../../src' +import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface' + +class AzureRerankRetriever_Retrievers implements INode { + label: string + name: string + version: number + description: string + type: string + icon: string + category: string + baseClasses: string[] + inputs: INodeParams[] + credential: INodeParams + badge: string + outputs: INodeOutputsValue[] + + constructor() { + this.label = 'Azure Rerank Retriever' + this.name = 'AzureRerankRetriever' + this.version = 1.0 + this.type = 'Azure Rerank Retriever' + this.icon = 'azurefoundry.svg' + this.category = 'Retrievers' + this.description = 'Azure Rerank indexes the documents from most to least semantically relevant to the query.' + this.baseClasses = [this.type, 'BaseRetriever'] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['azureFoundryApi'] + } + this.inputs = [ + { + label: 'Vector Store Retriever', + name: 'baseRetriever', + type: 'VectorStoreRetriever' + }, + { + label: 'Model Name', + name: 'model', + type: 'options', + options: [ + { + label: 'rerank-v3.5', + name: 'rerank-v3.5' + }, + { + label: 'rerank-english-v3.0', + name: 'rerank-english-v3.0' + }, + { + label: 'rerank-multilingual-v3.0', + name: 'rerank-multilingual-v3.0' + }, + { + label: 'Cohere-rerank-v4.0-fast', + name: 'Cohere-rerank-v4.0-fast' + }, + { + label: 'Cohere-rerank-v4.0-pro', + name: 'Cohere-rerank-v4.0-pro' + } + + ], + default: 'Cohere-rerank-v4.0-fast', + optional: true + }, + { + label: 'Query', + name: 'query', + type: 'string', + description: 'Query to retrieve documents from retriever. If not specified, user question will be used', + optional: true, + acceptVariable: true + }, + { + label: 'Top K', + name: 'topK', + description: 'Number of top results to fetch. Default to the TopK of the Base Retriever', + placeholder: '4', + type: 'number', + additionalParams: true, + optional: true + }, + { + label: 'Max Chunks Per Doc', + name: 'maxChunksPerDoc', + description: 'The maximum number of chunks to produce internally from a document. Default to 10', + placeholder: '10', + type: 'number', + additionalParams: true, + optional: true + } + ] + this.outputs = [ + { + label: 'Azure Rerank Retriever', + name: 'retriever', + baseClasses: this.baseClasses + }, + { + label: 'Document', + name: 'document', + description: 'Array of document objects containing metadata and pageContent', + baseClasses: ['Document', 'json'] + }, + { + label: 'Text', + name: 'text', + description: 'Concatenated string from pageContent of documents', + baseClasses: ['string', 'json'] + } + ] + } + + async init(nodeData: INodeData, input: string, options: ICommonObject): Promise { + const baseRetriever = nodeData.inputs?.baseRetriever as BaseRetriever + const model = nodeData.inputs?.model as string + const query = nodeData.inputs?.query as string + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const azureApiKey = getCredentialParam('azureFoundryApiKey', credentialData, nodeData) + const azureEndpoint = getCredentialParam('azureFoundryEndpoint', credentialData, nodeData) + const topK = nodeData.inputs?.topK as string + const k = topK ? parseFloat(topK) : (baseRetriever as VectorStoreRetriever).k ?? 4 + const maxChunksPerDoc = nodeData.inputs?.maxChunksPerDoc as string + const max_chunks_per_doc = maxChunksPerDoc ? parseFloat(maxChunksPerDoc) : 10 + const output = nodeData.outputs?.output as string + + const azureCompressor = new AzureRerank(azureApiKey, azureEndpoint, model, k, max_chunks_per_doc) + + const retriever = new ContextualCompressionRetriever({ + baseCompressor: azureCompressor, + baseRetriever: baseRetriever + }) + + if (output === 'retriever') return retriever + else if (output === 'document') return await retriever.getRelevantDocuments(query ? query : input) + else if (output === 'text') { + let finaltext = '' + + const docs = await retriever.getRelevantDocuments(query ? query : input) + + for (const doc of docs) finaltext += `${doc.pageContent}\n` + + return handleEscapeCharacters(finaltext, false) + } + + return retriever + } +} + +module.exports = { nodeClass: AzureRerankRetriever_Retrievers } From d7994208f269d241dcf21ea76a9b6a4a270804fc Mon Sep 17 00:00:00 2001 From: Mateusz Wyrembek Date: Fri, 12 Dec 2025 21:50:59 +0100 Subject: [PATCH 09/13] feat: Add Azure Reranker integration --- .../retrievers/AzureRerankRetriever/AzureRerankRetriever.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts index 5b3577b8212..7f61b3ceea0 100644 --- a/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts +++ b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts @@ -56,7 +56,7 @@ class AzureRerankRetriever_Retrievers implements INode { { label: 'rerank-multilingual-v3.0', name: 'rerank-multilingual-v3.0' - }, + }, { label: 'Cohere-rerank-v4.0-fast', name: 'Cohere-rerank-v4.0-fast' @@ -65,7 +65,6 @@ class AzureRerankRetriever_Retrievers implements INode { label: 'Cohere-rerank-v4.0-pro', name: 'Cohere-rerank-v4.0-pro' } - ], default: 'Cohere-rerank-v4.0-fast', optional: true From 14313ded94916f2149be99274a538e1e5990d519 Mon Sep 17 00:00:00 2001 From: Mateusz Wyrembek Date: Fri, 12 Dec 2025 21:56:07 +0100 Subject: [PATCH 10/13] feat: Add Azure Reranker integration --- packages/components/credentials/AzureRerankerApi.credential.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/components/credentials/AzureRerankerApi.credential.ts b/packages/components/credentials/AzureRerankerApi.credential.ts index 67bbc1c513a..db165a9f24b 100644 --- a/packages/components/credentials/AzureRerankerApi.credential.ts +++ b/packages/components/credentials/AzureRerankerApi.credential.ts @@ -11,7 +11,8 @@ class AzureRerankerApi implements INodeCredential { this.label = 'Azure Foundry API' this.name = 'azureFoundryApi' this.version = 1.0 - this.description = 'Refer to Azure AI Foundry documentation for setup instructions' + this.description = + 'Refer to Azure AI Foundry documentation for setup instructions' this.inputs = [ { label: 'Azure Foundry API Key', From 1e947da04397bd81bd750f499d33bd60e75b72cd Mon Sep 17 00:00:00 2001 From: Mateusz Wyrembek Date: Fri, 12 Dec 2025 22:06:22 +0100 Subject: [PATCH 11/13] feat: Add Azure Reranker integration --- packages/components/credentials/AzureRerankerApi.credential.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/credentials/AzureRerankerApi.credential.ts b/packages/components/credentials/AzureRerankerApi.credential.ts index db165a9f24b..73d676368e4 100644 --- a/packages/components/credentials/AzureRerankerApi.credential.ts +++ b/packages/components/credentials/AzureRerankerApi.credential.ts @@ -11,7 +11,7 @@ class AzureRerankerApi implements INodeCredential { this.label = 'Azure Foundry API' this.name = 'azureFoundryApi' this.version = 1.0 - this.description = + this.description = 'Refer to Azure AI Foundry documentation for setup instructions' this.inputs = [ { From e8ae029b03c63b41a6fdf953e9152baf4a4cb614 Mon Sep 17 00:00:00 2001 From: Mateusz Wyrembek Date: Mon, 29 Dec 2025 15:38:10 +0100 Subject: [PATCH 12/13] Update AzureRerankRetriever.ts --- .../AzureRerankRetriever/AzureRerankRetriever.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts index 7f61b3ceea0..20bbd944fc4 100644 --- a/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts +++ b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts @@ -123,14 +123,20 @@ class AzureRerankRetriever_Retrievers implements INode { const query = nodeData.inputs?.query as string const credentialData = await getCredentialData(nodeData.credential ?? '', options) const azureApiKey = getCredentialParam('azureFoundryApiKey', credentialData, nodeData) + if (!azureApiKey) { + throw new Error('Azure Foundry API Key is missing in credentials.') + } const azureEndpoint = getCredentialParam('azureFoundryEndpoint', credentialData, nodeData) + if (!azureEndpoint) { + throw new Error('Azure Foundry Endpoint is missing in credentials.') + } const topK = nodeData.inputs?.topK as string const k = topK ? parseFloat(topK) : (baseRetriever as VectorStoreRetriever).k ?? 4 const maxChunksPerDoc = nodeData.inputs?.maxChunksPerDoc as string - const max_chunks_per_doc = maxChunksPerDoc ? parseFloat(maxChunksPerDoc) : 10 + const maxChunksPerDocValue = maxChunksPerDoc ? parseFloat(maxChunksPerDoc) : 10 const output = nodeData.outputs?.output as string - const azureCompressor = new AzureRerank(azureApiKey, azureEndpoint, model, k, max_chunks_per_doc) + const azureCompressor = new AzureRerank(azureApiKey, azureEndpoint, model, k, maxChunksPerDocValue) const retriever = new ContextualCompressionRetriever({ baseCompressor: azureCompressor, From 0914b4f9cca00b6411c4b73759ac80b1a7d1d053 Mon Sep 17 00:00:00 2001 From: Mateusz Wyrembek Date: Mon, 29 Dec 2025 15:38:36 +0100 Subject: [PATCH 13/13] Update AzureRerank.ts --- .../AzureRerankRetriever/AzureRerank.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts index 31f45520525..91c6bf317e9 100644 --- a/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts +++ b/packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts @@ -4,15 +4,15 @@ import { Document } from '@langchain/core/documents' import { BaseDocumentCompressor } from 'langchain/retrievers/document_compressors' export class AzureRerank extends BaseDocumentCompressor { - private AzureAPIKey: any - private AZURE_API_URL: string + private readonly azureApiKey: string + private readonly azureApiUrl: string private readonly model: string private readonly k: number private readonly maxChunksPerDoc: number - constructor(AzureAPIKey: string, AZURE_API_URL: string, model: string, k: number, maxChunksPerDoc: number) { + constructor(azureApiKey: string, azureApiUrl: string, model: string, k: number, maxChunksPerDoc: number) { super() - this.AzureAPIKey = AzureAPIKey - this.AZURE_API_URL = AZURE_API_URL + this.azureApiKey = azureApiKey + this.azureApiUrl = azureApiUrl this.model = model this.k = k this.maxChunksPerDoc = maxChunksPerDoc @@ -28,7 +28,7 @@ export class AzureRerank extends BaseDocumentCompressor { } const config = { headers: { - 'api-key': `${this.AzureAPIKey}`, + 'api-key': `${this.azureApiKey}`, 'Content-Type': 'application/json', Accept: 'application/json' } @@ -42,7 +42,7 @@ export class AzureRerank extends BaseDocumentCompressor { documents: documents.map((doc) => doc.pageContent) } try { - let returnedDocs = await axios.post(this.AZURE_API_URL, data, config) + let returnedDocs = await axios.post(this.azureApiUrl, data, config) const finalResults: Document>[] = [] returnedDocs.data.results.forEach((result: any) => { const doc = documents[result.index] @@ -51,7 +51,7 @@ export class AzureRerank extends BaseDocumentCompressor { }) return finalResults.splice(0, this.k) } catch (error) { - return documents + throw new Error(`Azure Rerank API call failed: ${error.message}`) } } }