Skip to content

feat(cohere-rerank): add custom API endpoint and model name support#5799

Open
hztBUAA wants to merge 2 commits intoFlowiseAI:mainfrom
hztBUAA:feat/cohere-rerank-custom-endpoint
Open

feat(cohere-rerank): add custom API endpoint and model name support#5799
hztBUAA wants to merge 2 commits intoFlowiseAI:mainfrom
hztBUAA:feat/cohere-rerank-custom-endpoint

Conversation

@hztBUAA
Copy link

@hztBUAA hztBUAA commented Feb 20, 2026

Summary

  • Adds Base URL input to the Cohere Rerank Retriever node, allowing users to configure custom API endpoints (e.g., for proxied or self-hosted Cohere-compatible services)
  • Adds Custom Model Name input for fine-tuned rerank models, which overrides the dropdown selection when provided
  • Both new inputs appear in the "Additional Parameters" section to keep the default experience clean
  • Bumps node version to 2.0

Closes #4086

Changes

CohereRerank.ts (compressor class)

  • Added optional baseURL constructor parameter
  • Uses custom URL when provided, falls back to default https://api.cohere.ai/v1/rerank
  • Strips trailing slashes from custom URLs

CohereRerankRetriever.ts (node definition)

  • Added Custom Model Name (customModel) string input in Additional Parameters
  • Added Base URL (baseURL) string input in Additional Parameters
  • customModel overrides dropdown model selection when provided
  • Passes baseURL to CohereRerank constructor

CohereRerank.test.ts (new test file)

  • 11 unit tests covering:
    • Default URL behavior
    • Custom URL usage
    • Trailing slash stripping
    • Custom model name support
    • Request payload structure
    • Error handling fallback
    • Authorization headers

Test plan

  • All 11 unit tests pass (npx jest CohereRerank.test.ts)
  • Manual test: verify node loads correctly in Flowise UI with new Additional Parameters fields
  • Manual test: verify custom model name overrides dropdown selection
  • Manual test: verify custom Base URL is used for API calls

Add Base URL and Custom Model Name inputs to the Cohere Rerank
Retriever node, allowing users to configure custom API endpoints
and use fine-tuned rerank models. The Base URL defaults to the
standard Cohere API when not specified. Custom Model Name overrides
the dropdown selection when provided. Closes FlowiseAI#4086
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hztBUAA, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the flexibility and configurability of the Cohere Rerank Retriever. It introduces options for users to specify custom API endpoints and utilize fine-tuned rerank models, catering to advanced use cases such as private deployments or specialized model applications. These additions empower users with greater control over their reranking infrastructure without cluttering the primary interface.

Highlights

  • Custom API Endpoint: Users can now configure a custom API endpoint for the Cohere Rerank Retriever, enabling use with proxied or self-hosted Cohere-compatible services.
  • Custom Model Name: Support for custom model names has been added, allowing the use of fine-tuned rerank models which override the default dropdown selection.
  • User Interface: Both new inputs, "Base URL" and "Custom Model Name", are placed in the "Additional Parameters" section to maintain a clean default user experience.
  • Version Update: The node version for the Cohere Rerank Retriever has been bumped to 2.0.
Changelog
  • packages/components/nodes/retrievers/CohereRerankRetriever/CohereRerank.test.ts
    • Added a new test file with 11 unit tests covering custom baseURL, model name, request payload, error handling, and authorization headers.
  • packages/components/nodes/retrievers/CohereRerankRetriever/CohereRerank.ts
    • Modified the CohereRerank class constructor to accept an optional baseURL parameter.
    • Updated the API call to use the provided baseURL or fall back to the default Cohere API URL.
    • Implemented logic to strip trailing slashes from the custom baseURL.
  • packages/components/nodes/retrievers/CohereRerankRetriever/CohereRerankRetriever.ts
    • Updated the node version from 1.0 to 2.0.
    • Added new input fields for "Custom Model Name" and "Base URL" to the "Additional Parameters" section.
    • Modified the init method to pass the new customModel and baseURL parameters to the CohereRerank compressor, with customModel overriding the default model selection.
Activity
  • All 11 unit tests for CohereRerank.test.ts have passed.
  • Manual tests for verifying node loading, custom model name override, and custom Base URL usage are pending.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request successfully introduces support for custom API endpoints and model names for the Cohere Rerank Retriever node. The implementation is clean, follows existing patterns, and includes a comprehensive set of unit tests. I have suggested a few minor improvements to enhance robustness and clarity, such as trimming user inputs to handle accidental whitespace and renaming the 'Base URL' label to 'Endpoint URL' to more accurately reflect its function as a full API endpoint.

this.model = model
this.k = k
this.maxChunksPerDoc = maxChunksPerDoc
this.cohereApiUrl = baseURL ? baseURL.replace(/\/+$/, '') : 'https://api.cohere.ai/v1/rerank'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is a good practice to trim the baseURL to handle any accidental leading or trailing whitespace that might be pasted into the UI field.

Suggested change
this.cohereApiUrl = baseURL ? baseURL.replace(/\/+$/, '') : 'https://api.cohere.ai/v1/rerank'
this.cohereApiUrl = baseURL ? baseURL.trim().replace(/\/+$/, '') : 'https://api.cohere.ai/v1/rerank'

optional: true
},
{
label: 'Base URL',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The label 'Base URL' can be slightly misleading since the implementation expects the full endpoint URL (as shown in the placeholder and description). Renaming it to 'Endpoint URL' would be more precise.

Suggested change
label: 'Base URL',
label: 'Endpoint URL',

const output = nodeData.outputs?.output as string

const cohereCompressor = new CohereRerank(cohereApiKey, model, k, max_chunks_per_doc)
const selectedModel = customModel || model
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Trimming the customModel input ensures that accidental whitespace doesn't result in an invalid model name being sent to the API.

Suggested change
const selectedModel = customModel || model
const selectedModel = customModel?.trim() || model

… label

- Trim baseURL to handle accidental leading/trailing whitespace from UI
- Rename label from 'Base URL' to 'API Endpoint URL' for clarity
- Trim customModel input to prevent invalid model names from whitespace
- Add test for baseURL whitespace trimming
@hztBUAA
Copy link
Author

hztBUAA commented Feb 25, 2026

Thanks for the review and feedback. I am following up on this PR now and will either push the requested changes or reply point-by-point shortly.

@hztBUAA
Copy link
Author

hztBUAA commented Feb 25, 2026

Quick follow-up: I am reviewing the feedback and will update this PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Custom Cohere ReRank API endpoints

1 participant