LLM-based RankGPT reranker plugin for Dify, supporting OpenAI, Google Gemini, and Anthropic.
Author: ki3nd
Type: model
Github Repo: https://github.com/ki3nd/rankgpt-dify-plugin
Github Issues: issues
This plugin adds a rerank model provider to Dify and uses an LLM to reorder retrieved documents by query relevance.
- Supports OpenAI, Google Gemini, and Anthropic providers
- RankGPT-style permutation reranking
- Sliding-window reranking for longer document lists
- Rank-based pseudo-score output (
1/(rank+1))
When configuring the rankgpt provider in Dify:
| Field | Description |
|---|---|
provider |
openai, gemini, or anthropic |
model |
e.g. gpt-4o-mini, gemini-2.0-flash, or claude-sonnet-4-20250514 |
openai_api_key |
OpenAI API key (OpenAI only) |
openai_base_url |
Optional, for OpenAI-compatible endpoints (OpenAI only) |
gemini_api_key |
Google AI Studio API key (Gemini only) |
anthropic_api_key |
Anthropic API key (Anthropic only) |
window_size |
Sliding window size (default 20) |
step_size |
Sliding step size (default 10) |
max_doc_words |
Max words per passage before truncation (default 300) |
- The plugin builds a RankGPT-style prompt with the query and indexed passages.
- The LLM returns a ranking order (e.g.
[3] > [1] > [2]). - The plugin parses the order, removes duplicates and invalid indices, and applies a safe fallback for missing ones.
- Results are returned to Dify as
RerankResult.
- LLM-based reranking — latency and cost depend on model choice and document count.
- For large document sets, tune
window_sizeandstep_sizeto avoid oversized prompts. score_thresholdapplies to a rank-based pseudo-score, not a true relevance probability.
