Cohere in Langchain Code Node to Improve RAG with Reranker

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