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
AiRerankerconnection type.Please use the HTTP Request + Code Node Workaround instead.
This node will become functional when n8n officially supports community nodes with
AiRerankerconnection 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
BaseDocumentCompressorinterface - 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
- Go to Settings > Community Nodes in your n8n instance
- Select Install
- Enter
n8n-nodes-reranker-openaias the npm package name - Agree to the risks of using community nodes
- Select Install
After installation restart n8n to register the new nodes.
๐ง Configuration
Credentials
Create OpenAI API credentials:
- Create an OpenAI API account at platform.openai.com
- Generate an API key from your OpenAI dashboard
- In n8n, create new credentials of type "OpenAI API"
- 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
- Vector Store: Retrieves relevant documents
- Reranker OpenAI: Reorders documents by relevance
- 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
AiRerankerconnection 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
๐ 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.