feat: adapt dify new retrieval_model schema#1745
Conversation
📝 WalkthroughWalkthroughThe PR updates the Dify API request payload in ChangesDify Retrieval Model Adaptation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/presenter/mcpPresenter/inMemoryServers/difyKnowledgeServer.ts`:
- Around line 225-236: The code in performDifyKnowledgeSearch currently
hard-disables thresholding (retrieval_model.score_threshold_enabled=false and
score_threshold=null) while DifyKnowledgeSearchArgsSchema and the function
destructuring still accept scoreThreshold, causing a no-op public input and
misleading logs; either (A) wire the parsed scoreThreshold into retrievalModel
by setting retrieval_model.score_threshold_enabled = scoreThreshold != null and
retrieval_model.score_threshold = scoreThreshold (and update the console.log to
reflect the actual retrieval_model), or (B) if thresholding is intentionally
removed, delete scoreThreshold from DifyKnowledgeSearchArgsSchema and from the
destructuring in performDifyKnowledgeSearch and remove it from the console.log
so callers are not exposed to a dead parameter.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dd28b5cd-0fb7-4ba8-a634-6f6387c07056
📒 Files selected for processing (1)
src/main/presenter/mcpPresenter/inMemoryServers/difyKnowledgeServer.ts
背景 / Background
Closes #1744
Dify 新版检索 API 把检索配置统一收进了
retrieval_model对象,并对其字段做了校验收紧:search_method变为必填(缺失会导致参数校验失败);reranking_enable/score_threshold_enabled必须是布尔值,旧版传null已不再被接受。dify_knowledge_search工具当前发出的请求体仍缺少search_method、且这两个开关传的是null,因此在新版 Dify 上检索直接报错。改动 / Changes
仅修改
difyKnowledgeServer.ts中performDifyKnowledgeSearch构造请求体的部分(私有方法,无外部调用方):search_method: 'semantic_search'—— 语义检索不依赖数据集是否配置 Rerank 模型,对任意数据集都可用;reranking_enable/score_threshold_enabled改为布尔值,避免null被新版接口拒绝。请求体由:
{ "query": "...", "retrieval_model": { "top_k": 5, "score_threshold": 0.2, "reranking_enable": null, "score_threshold_enabled": null } }改为:
{ "query": "...", "retrieval_model": { "search_method": "semantic_search", "reranking_enable": false, "top_k": 5, "score_threshold_enabled": false, "score_threshold": null } }兼容性 / Compatibility
query/topK/scoreThreshold)、schema、工具注册逻辑均未改动,对调用方零侵入。score_threshold_enabled为null,Dify 本就未启用阈值),因此检索结果集与改动前一致,唯一区别是新版 Dify 上由 400 报错变为正常返回。hybrid_search+reranking_enable: true,因其要求数据集已配置 Rerank 模型,否则反而会让部分用户报错。如需混合检索,可作为后续「每知识库可配置检索方式」的增强项。测试 / Test
pnpm run format、pnpm run lint:通过(0 warning / 0 error)pnpm run typecheck:node/typecheck:web:通过(pre-commit 钩子自动执行)Summary by CodeRabbit