Files
alighasami 3d5eaf9445
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

100 lines
2.4 KiB
TypeScript

import { CohereRerank } from '@langchain/cohere';
import {
NodeConnectionTypes,
type INodeType,
type INodeTypeDescription,
type ISupplyDataFunctions,
type SupplyData,
} from 'n8n-workflow';
import { logWrapper } from '@n8n/ai-utilities';
export class RerankerCohere implements INodeType {
description: INodeTypeDescription = {
displayName: 'Reranker Cohere',
name: 'rerankerCohere',
icon: { light: 'file:cohere.svg', dark: 'file:cohere.dark.svg' },
group: ['transform'],
version: 1,
description:
'Use Cohere Reranker to reorder documents after retrieval from a vector store by relevance to the given query.',
defaults: {
name: 'Reranker Cohere',
},
requestDefaults: {
ignoreHttpStatusErrors: true,
baseURL: '={{ $credentials.host }}',
},
credentials: [
{
name: 'cohereApi',
required: true,
},
],
codex: {
categories: ['AI'],
subcategories: {
AI: ['Rerankers'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.rerankercohere/',
},
],
},
},
inputs: [],
outputs: [NodeConnectionTypes.AiReranker],
outputNames: ['Reranker'],
properties: [
{
displayName: 'Model',
name: 'modelName',
type: 'options',
description:
'The model that should be used to rerank the documents. <a href="https://docs.cohere.com/docs/models">Learn more</a>.',
default: 'rerank-v3.5',
options: [
{
name: 'rerank-v3.5',
value: 'rerank-v3.5',
},
{
name: 'rerank-english-v3.0',
value: 'rerank-english-v3.0',
},
{
name: 'rerank-multilingual-v3.0',
value: 'rerank-multilingual-v3.0',
},
],
},
{
displayName: 'Top N',
name: 'topN',
type: 'number',
description: 'The maximum number of documents to return after reranking',
default: 3,
},
],
};
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {
this.logger.debug('Supply data for reranking Cohere');
const modelName = this.getNodeParameter('modelName', itemIndex, 'rerank-v3.5') as string;
const topN = this.getNodeParameter('topN', itemIndex, 3) as number;
const credentials = await this.getCredentials<{ apiKey: string }>('cohereApi');
const reranker = new CohereRerank({
apiKey: credentials.apiKey,
model: modelName,
topN,
});
return {
response: logWrapper(reranker, this),
};
}
}