Back to Nodes

Reranker OpenAI

Last updated Aug 5, 2025

n8n community node for OpenAI-compatible reranking services - Currently requires HTTP+Code workaround

13 Weekly Downloads
129 Monthly Downloads

Included Nodes

Reranker OpenAI

Description

n8n-nodes-reranker-openai

โš ๏ธ IMPORTANT NOTICE: This node is currently NOT FUNCTIONAL

This community node cannot be used as a reranker because n8n does not support community nodes with AiReranker connection type.

Please use the HTTP Request + Code Node Workaround instead.

This node will become functional when n8n officially supports community nodes with AiReranker connection type.

This is an n8n community node that provides OpenAI-compatible reranking functionality for your n8n AI workflows.

The Reranker OpenAI node allows you to reorder documents by relevance to a given query using OpenAI's reranking API or any compatible service. It implements the LangChain BaseDocumentCompressor interface for seamless integration with AI workflows.

n8n is a fair-code licensed workflow automation platform.

๐Ÿš€ Features

  • True AI Sub-node: Implements LangChain BaseDocumentCompressor interface
  • OpenAI Compatible: Works with OpenAI and other compatible reranking APIs
  • Seamless Integration: Designed to work with Vector Stores and AI Agents
  • Configurable: Support for different models and top-N results
  • Error Handling: Graceful fallbacks and comprehensive error handling

๐Ÿ“ฆ Installation

Follow the installation guide in the n8n community nodes documentation.

Quick Install

  1. Go to Settings > Community Nodes in your n8n instance
  2. Select Install
  3. Enter n8n-nodes-reranker-openai as the npm package name
  4. Agree to the risks of using community nodes
  5. Select Install

After installation restart n8n to register the new nodes.

๐Ÿ”ง Configuration

Credentials

Create OpenAI API credentials:

  1. Create an OpenAI API account at platform.openai.com
  2. Generate an API key from your OpenAI dashboard
  3. In n8n, create new credentials of type "OpenAI API"
  4. Enter your API key and base URL (default: https://api.openai.com)

Node Parameters

  • Model: The reranking model to use (default: "rerank-1")
  • Top N: Maximum number of documents to return after reranking (default: 10)

๐Ÿ”„ Usage

AI Workflow Integration

The Reranker OpenAI node is designed to work as an AI sub-node in LangChain workflows:

Vector Store โ†’ Reranker OpenAI โ†’ AI Agent

Example Workflow

  1. Vector Store: Retrieves relevant documents
  2. Reranker OpenAI: Reorders documents by relevance
  3. AI Agent: Uses the reranked documents for better responses

Supported Services

  • OpenAI: When reranking APIs become available
  • SiliconFlow: Use models like Qwen/Qwen3-Reranker-8B
  • Custom APIs: Any service implementing the OpenAI reranking API format

๐Ÿ”ง Workaround: HTTP Request + Code Nodes

Since the dedicated reranker node cannot be used, here's a working implementation using HTTP Request and Code nodes:

Workflow Structure

Chat Trigger โ†’ MongoDB Vector Store โ†’ Document Processor (Code) โ†’ HTTP Request (Rerank API) โ†’ Result Processor (Code) โ†’ AI Agent
                        โ†‘                                                                                                    โ†‘
Qwen3-Embedding โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                                                                                    โ”‚
DeepSeek Chat Model โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

1. Document Processor (Code Node)

// Process MongoDB Vector Store output and prepare for rerank API
const inputItems = $input.all();
const userQuery = $('When chat message received').first().json.chatInput;

const processedDocuments = [];
for (const item of inputItems) {
  if (item.json && item.json.document) {
    const doc = item.json.document;
    let pageContent = '';

    // Extract content from metadata if needed
    if (doc.metadata && doc.metadata.embedding_text) {
      pageContent = doc.metadata.embedding_text;
    } else if (doc.pageContent) {
      pageContent = doc.pageContent;
    }

    if (pageContent && pageContent.trim() !== '') {
      processedDocuments.push({
        pageContent: pageContent,
        metadata: {
          ...doc.metadata,
          similarity_score: item.json.score || 0
        }
      });
    }
  }
}

return [{
  json: {
    query: userQuery,
    documents: processedDocuments,
    chatInput: userQuery
  }
}];

2. HTTP Request Node Configuration

  • Method: POST
  • URL: https://api.siliconflow.cn/v1/rerank
  • Authentication: Bearer Token
  • Headers: Content-Type: application/json
  • Body (JSON):
{
  "model": "Qwen/Qwen3-Reranker-8B",
  "query": "{{ $json.query }}",
  "documents": {{ JSON.stringify($json.documents.map(doc => doc.pageContent)) }},
  "top_n": 3
}

3. Result Processor (Code Node)

// Process rerank API response and format for AI Agent
const rerankResponse = $input.first().json;
const originalDocuments = $('Document Processor').first().json.documents;
const userQuery = $('Document Processor').first().json.query;

let rerankedDocuments = [];
if (rerankResponse.results && Array.isArray(rerankResponse.results)) {
  rerankedDocuments = rerankResponse.results
    .filter(item => item.index >= 0 && item.index < originalDocuments.length)
    .sort((a, b) => b.relevance_score - a.relevance_score)
    .map(item => {
      const originalDoc = originalDocuments[item.index];
      return {
        pageContent: originalDoc.pageContent,
        metadata: {
          ...originalDoc.metadata,
          relevance_score: item.relevance_score
        }
      };
    });
}

const contextText = rerankedDocuments.map((doc, index) => {
  const metadata = doc.metadata;
  let docInfo = `ใ€ๆ–‡ๆกฃ${index + 1}ใ€‘`;
  if (metadata.id) docInfo += ` ๆกๆฌพ${metadata.id}`;
  if (metadata.standard_name) docInfo += ` - ${metadata.standard_name}`;
  if (metadata.relevance_score) docInfo += ` [็›ธๅ…ณๅบฆ: ${(metadata.relevance_score * 100).toFixed(1)}%]`;
  return `${docInfo}\nๅ†…ๅฎน๏ผš${doc.pageContent}\n`;
}).join('\n---\n');

return [{
  json: {
    chatInput: userQuery,
    query: userQuery,
    reranked_documents: rerankedDocuments,
    context: contextText,
    systemContext: `็”จๆˆท้—ฎ้ข˜๏ผš${userQuery}\n\n็›ธๅ…ณ่ง„่Œƒๆ–‡ๆกฃ๏ผš\n${contextText}`
  }
}];

4. AI Agent System Message

ไฝ ๆ˜ฏไธ€ไธช่ง„่ŒƒๆŸฅ่ฏขๅŠฉๆ‰‹ใ€‚

{{ $json.systemContext }}

่ฏทๅŸบไบŽไปฅไธŠๆ–‡ๆกฃๅ›ž็ญ”็”จๆˆท้—ฎ้ข˜๏ผŒ่ฆๆฑ‚๏ผš
1. ๆไพ›ๅ‡†็กฎใ€่ฏฆ็ป†็š„ๅ›ž็ญ”
2. ๆ ‡ๆ˜Žไฟกๆฏๆฅๆบ็š„ๅ…ทไฝ“ๆกๆฌพ็ผ–ๅท
3. ๅฆ‚ๆžœๆ–‡ๆกฃไธญๆฒกๆœ‰็›ดๆŽฅ็›ธๅ…ณไฟกๆฏ๏ผŒ่ฏทๆ˜Ž็กฎ่ฏดๆ˜Ž
4. ๆŒ‰็›ธๅ…ณๅบฆไผ˜ๅ…ˆไฝฟ็”จๆŽ’ๅบ้ ๅ‰็š„ๆ–‡ๆกฃ

โš ๏ธ Current Limitations

This community node is currently NOT FUNCTIONAL due to n8n's architecture limitations:

  • โŒ Cannot be used: n8n doesn't support community nodes with AiReranker connection type
  • โŒ No direct connection: Cannot connect to Vector Store's reranker input
  • โœ… Workaround available: Use HTTP Request + Code nodes (see above)
  • โœ… Future ready: Will work when n8n adds official support

We are waiting for n8n to add AiReranker support for community nodes.

๐Ÿ› ๏ธ Development

Building

npm install
npm run build

Testing

npm run lint
npm test

๐Ÿ“‹ Compatibility

  • Minimum n8n version: 0.198.0
  • Tested with n8n versions: 0.198.0+
  • Node.js: >=18.10
  • LangChain: Compatible with @langchain/core

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“„ License

MIT

๐Ÿ”— Links

๐Ÿ› Issues & Feature Requests

If you encounter any issues or have feature requests, please open an issue on GitHub.


Note: This is a community-maintained node and is not officially supported by n8n or OpenAI.