Cohere in Langchain Code Node to Improve RAG with Reranker

I am tryingt to improve my RAG results with a reranker. I do not think there is an appropriate node yet. Therefore I would like to implement it with a Langchain code node. I would want to do so using a Cohere reranker.
My question is regarding the correct steps to import the packages needed and if someone possibly has done this before?
Thanks in Advance

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey Paul,

Great question. I’m pleased to say that the cohere libraries are available in n8n and you can use it the langchain code node like so:

(Example taken from: Cohere Rerank | 🦜️🔗 Langchain)

const { CohereRerank } = require("@langchain/cohere");

const cohereRerank = new CohereRerank({
  apiKey: '...', // You'll have to hardcode your key here
  model: "rerank-english-v2.0", // Default
});

To use it in the example from my other post on using Langchain code node, we can do:

[Deleted]

Hope this helps!

Edit: Sorry, that was a bad example!

3 Likes

@Paul_Bogemann I’ve created a new Tutorial here which I think will help - Build A Custom Q&A Chain using Cohere Rerank (Using Langchain Code Node)

2 Likes

Hi Jim!
Thank you very much for the elaborated answer! This is a great Tutorial with strong level of detail!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.