Skip to content

Conversation

@lifl00001
Copy link
Contributor

📝 变更说明

修复了 DifyRAGClient 中检索请求的 JSON key 错误。

🎯 主要变更

  • 修正了 retrievalModel.put("reranking_mode", rerankingMode)retrievalModel.put("reranking_model", rerankingModel)
  • 将变量名从 rerankingMode 重命名为 rerankingModel 以保持一致性
  • 同步更新了测试文件中的相关代码

🐛 问题描述

Dify API 期望使用 reranking_model 作为 reranking 配置的 JSON key,但代码中错误地使用了 reranking_mode

✅ 测试

  • 所有单元测试通过 (24 tests, 0 failures)
  • 代码通过 Spotless 检查
  • 本地构建成功
  • 已添加/更新测试用例

📋 修改文件

  • agentscope-extensions/agentscope-extensions-rag-dify/src/main/java/io/agentscope/core/rag/integration/dify/DifyRAGClient.java
  • agentscope-extensions/agentscope-extensions-rag-dify/src/test/java/io/agentscope/core/rag/integration/dify/DifyRAGClientTest.java

🔗 相关信息

API 参考示例:

{
  "retrieval_model": {
    "reranking_enable": true,
    "reranking_model": {
      "reranking_provider_name": "langgenius/siliconflow/siliconflow",
      "reranking_model_name": "netease-youdao/bce-reranker-base_v1"
    }
  }
}

🤖 Generated with Claude Code

Fixed incorrect JSON key 'reranking_mode' to 'reranking_model' in DifyRAG retrieval request payload.
Also renamed variable from 'rerankingMode' to 'rerankingModel' for consistency.

Changes:
- DifyRAGClient.java: Changed 'reranking_mode' to 'reranking_model'
- DifyRAGClientTest.java: Updated test to use correct key name

Reference: Dify API expects 'reranking_model' for reranking configuration

Co-Authored-By: Claude Code <noreply@anthropic.com>
@lifl00001 lifl00001 requested a review from a team February 9, 2026 11:57
@gemini-code-assist
Copy link

Summary of Changes

Hello @lifl00001, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决 DifyRAGClient 中一个关键的 JSON 键错误,该错误导致 Dify API 无法正确识别和应用 reranking 配置。通过将错误的键名 reranking_mode 更正为 reranking_model,并相应地更新了变量名和测试,确保了与 Dify API 的正确交互,从而使 RAG 检索的 reranking 功能能够按预期工作。

Highlights

  • 修复 DifyRAG 检索请求中的 JSON 键: 将 DifyRAGClient 中用于 reranking 配置的 JSON 键从 reranking_mode 更正为 reranking_model,以符合 Dify API 的预期。
  • 变量名重构: 将内部变量 rerankingMode 重命名为 rerankingModel,以提高代码一致性和可读性。
  • 更新测试文件: 同步更新了测试文件 DifyRAGClientTest.java,以反映 JSON 键和变量名的更改,确保测试覆盖率和准确性。
Changelog
  • agentscope-extensions/agentscope-extensions-rag-dify/src/main/java/io/agentscope/core/rag/integration/dify/DifyRAGClient.java
    • retrievalModel.put("reranking_mode", rerankingMode) 修改为 retrievalModel.put("reranking_model", rerankingModel)
    • 将局部变量 rerankingMode 重命名为 rerankingModel
  • agentscope-extensions/agentscope-extensions-rag-dify/src/test/java/io/agentscope/core/rag/integration/dify/DifyRAGClientTest.java
    • 更新测试断言,将 rerankingMode 变量和 reranking_mode JSON 键替换为 rerankingModelreranking_model
Activity
  • 所有单元测试通过 (24 tests, 0 failures)。
  • 代码通过 Spotless 检查。
  • 本地构建成功。
  • 已添加/更新测试用例。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次变更修复了 Dify RAG 检索请求中错误的 JSON 键 reranking_mode,并将其更正为 reranking_model,同时统一了相关变量名。代码修改清晰,目标明确。

我发现一处可以改进的地方,主要是关于 rerankConfig 的处理逻辑,这可以使代码更健壮,并修正一个潜在的逻辑问题。具体请看我的评论。

Comment on lines 160 to 175
if (config.getRerankConfig() != null) {
Map<String, Object> rerankingMode = new HashMap<>();
Map<String, Object> rerankingModel = new HashMap<>();
if (config.getRerankConfig().getProviderName() != null) {
rerankingMode.put(
rerankingModel.put(
"reranking_provider_name",
config.getRerankConfig().getProviderName());
}
if (config.getRerankConfig().getModelName() != null) {
rerankingMode.put(
rerankingModel.put(
"reranking_model_name",
config.getRerankConfig().getModelName());
}
if (!rerankingMode.isEmpty()) {
retrievalModel.put("reranking_mode", rerankingMode);
if (!rerankingModel.isEmpty()) {
retrievalModel.put("reranking_model", rerankingModel);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这部分代码的逻辑可以优化,并且存在一个潜在问题。

  1. 可读性: config.getRerankConfig() 被多次调用。可以将其结果存储在一个局部变量中,以提高代码的可读性和效率。
  2. 潜在错误: if (!rerankingModel.isEmpty()) 这个判断条件可能会导致一个问题。如果用户设置了 enableRerank(true) 并提供了一个空的 rerankConfig(例如 RerankConfig.builder().build()),其意图很可能是使用 Dify 的默认重排模型。但当前代码会因为 rerankingModel 为空而不会将 reranking_model 字段加入到请求中,这可能与预期行为不符。移除这个判断可以确保即使 reranking_model 为空对象 {} 也会被发送,从而让 Dify 服务端来决定如何处理(通常是使用默认值)。

建议进行如下修改,以提高代码的健壮性和可读性。

                        if (config.getRerankConfig() != null) {
                            RerankConfig rerankConfig = config.getRerankConfig();
                            Map<String, Object> rerankingModel = new HashMap<>();
                            if (rerankConfig.getProviderName() != null) {
                                rerankingModel.put(
                                        "reranking_provider_name",
                                        rerankConfig.getProviderName());
                            }
                            if (rerankConfig.getModelName() != null) {
                                rerankingModel.put(
                                        "reranking_model_name",
                                        rerankConfig.getModelName());
                            }
                            retrievalModel.put("reranking_model", rerankingModel);
                        }

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...scope/core/rag/integration/dify/DifyRAGClient.java 80.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@AlbumenJ AlbumenJ merged commit 48fca12 into agentscope-ai:main Feb 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants