Skip to content

refactor(api): consolidate duplicate RerankingModelConfig and WeightedScoreConfig definitions#34747

Merged
asukaminato0721 merged 4 commits intolanggenius:mainfrom
corevibe555:refactor/consolidate-duplicate-pydantic-models
Apr 13, 2026
Merged

refactor(api): consolidate duplicate RerankingModelConfig and WeightedScoreConfig definitions#34747
asukaminato0721 merged 4 commits intolanggenius:mainfrom
corevibe555:refactor/consolidate-duplicate-pydantic-models

Conversation

@corevibe555
Copy link
Copy Markdown
Contributor

Part of #32385

Summary

  • Add canonical RerankingModelConfig in core/rag/entities/retrieval_settings.py with optional fields, validation_alias for provider/model, and backward-compatible properties
  • Remove duplicate RerankingModelConfig from knowledge_index/entities.py, knowledge_retrieval/entities.py, and rag_pipeline_entities.py
  • Replace RerankingModel class in knowledge_entities.py with alias to canonical RerankingModelConfig
  • Make WeightedScoreConfig.vector_setting and keyword_setting optional (None default) to match services-layer usage
  • Remove duplicate WeightedScoreConfig from rag_pipeline_entities.py

Why this change

RerankingModelConfig had 3 conflicting definitions with incompatible field names (provider/model vs reranking_provider_name/reranking_model_name) and different optionality (required vs optional). A 4th variant RerankingModel added naming confusion. The canonical definition now accepts both conventions and coerces None to "".

WeightedScoreConfig had 2 definitions — core required both fields while services allowed None. The core version now matches the superset.

Changes

  • core/rag/entities/retrieval_settings.py: Add canonical RerankingModelConfig with validators, aliases, compat properties; make WeightedScoreConfig fields optional
  • core/rag/entities/__init__.py: Export RerankingModelConfig
  • core/workflow/nodes/knowledge_index/entities.py: Remove local RerankingModelConfig, import from core
  • core/workflow/nodes/knowledge_retrieval/entities.py: Remove local RerankingModelConfig, import from core
  • services/entities/knowledge_entities/rag_pipeline_entities.py: Remove local RerankingModelConfig and WeightedScoreConfig, import from core
  • services/entities/knowledge_entities/knowledge_entities.py: Replace RerankingModel class with RerankingModel = RerankingModelConfig alias

Test plan

  • 2482 unit tests pass (api/tests/unit_tests/services/)
  • Knowledge retrieval node tests pass (validates provider/model alias support)
  • Both naming conventions verified: RerankingModelConfig(provider=..., model=...) and RerankingModelConfig(reranking_provider_name=..., reranking_model_name=...)
  • ruff check passes

…eConfig

Eliminate duplicate Pydantic model definitions that had diverged across
modules, causing field incompatibilities and maintenance burden.

RerankingModelConfig:
- Canonical definition now in core/rag/entities/retrieval_settings.py
- Supports both naming conventions via validation_alias (provider/model
  and reranking_provider_name/reranking_model_name)
- Fields are optional with coercion validators (None -> "")
- Backward-compatible .provider/.model properties for existing consumers
- Removed duplicate definitions from knowledge_index, knowledge_retrieval,
  and rag_pipeline_entities modules
- RerankingModel alias preserved in knowledge_entities.py

WeightedScoreConfig:
- Made vector_setting/keyword_setting optional (None default) in the
  canonical core definition to match the services layer superset
- Removed duplicate definition from rag_pipeline_entities.py

fix
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. refactor labels Apr 8, 2026
@corevibe555
Copy link
Copy Markdown
Contributor Author

Resolved conflict. thanks

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-09 00:15:55.798712548 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-09 00:15:46.865627553 +0000
@@ -297,6 +297,14 @@
    --> core/tools/workflow_as_tool/provider.py:237:26
 ERROR Returned type `dict[object, str]` is not assignable to declared return type `dict[str, Any] | None` [bad-return]
    --> core/workflow/human_input_compat.py:183:16
+ERROR Object of class `NoneType` has no attribute `vector_weight` [missing-attribute]
+   --> core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py:227:46
+ERROR Object of class `NoneType` has no attribute `embedding_provider_name` [missing-attribute]
+   --> core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py:228:56
+ERROR Object of class `NoneType` has no attribute `embedding_model_name` [missing-attribute]
+   --> core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py:229:53
+ERROR Object of class `NoneType` has no attribute `keyword_weight` [missing-attribute]
+   --> core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py:232:47
 ERROR No matching overload found for function `redis.client.Redis.__init__` called with arguments: (connection_pool=ConnectionPool) [no-matching-overload]
    --> extensions/ext_redis.py:244:38
 ERROR Cannot index into `Literal['']` [bad-index]
@@ -309,6 +317,8 @@
   --> schedule/queue_monitor_task.py:14:21
 ERROR Object of class `Tenant` has no attribute `role` [missing-attribute]
     --> services/account_service.py:1153:13
+ERROR Object of class `NoneType` has no attribute `embedding_provider_name` [missing-attribute]
+   --> services/app_dsl_service.py:731:49
 ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `Iterable[bytes]` [unsafe-overlap]
    --> services/audio_service.py:143:41
 ERROR No matching overload found for function `flask.helpers.stream_with_context` called with arguments: (Generator[bytes]) [no-matching-overload]
@@ -345,6 +355,8 @@
   --> services/hit_testing_service.py:94:21
 ERROR `handled_tenant_count` was assigned in the current scope before the nonlocal declaration [unknown-name]
   --> services/plugin/plugin_migration.py:91:34
+ERROR Object of class `NoneType` has no attribute `embedding_provider_name` [missing-attribute]
+   --> services/rag_pipeline/rag_pipeline_dsl_service.py:807:49
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Returned type `EndUser | Unknown | None` is not assignable to declared return type `Account | EndUser` [bad-return]

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Pyrefly Diff

No changes detected.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Pyrefly Diff

No changes detected.

@corevibe555
Copy link
Copy Markdown
Contributor Author

@asukaminato0721 Resolved conflicts on this PR. would you review again? Thanks.

@corevibe555 corevibe555 force-pushed the refactor/consolidate-duplicate-pydantic-models branch from 74f7f0c to 6e5c0b4 Compare April 9, 2026 01:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Pyrefly Diff

No changes detected.

@corevibe555 corevibe555 force-pushed the refactor/consolidate-duplicate-pydantic-models branch from 6e5c0b4 to 1ec478c Compare April 9, 2026 02:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Pyrefly Diff

No changes detected.

@corevibe555 corevibe555 force-pushed the refactor/consolidate-duplicate-pydantic-models branch from 1ec478c to 80119a9 Compare April 12, 2026 11:46
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 12, 2026
@corevibe555 corevibe555 force-pushed the refactor/consolidate-duplicate-pydantic-models branch from 9dda453 to b7d3348 Compare April 12, 2026 12:10
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Apr 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

@corevibe555 corevibe555 force-pushed the refactor/consolidate-duplicate-pydantic-models branch from b7d3348 to 188dfa2 Compare April 12, 2026 12:17
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

@corevibe555 corevibe555 force-pushed the refactor/consolidate-duplicate-pydantic-models branch from 188dfa2 to 80119a9 Compare April 12, 2026 12:19
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

auto-merge was automatically disabled April 13, 2026 05:45

Pull request was closed

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 13, 2026
Merged via the queue into langgenius:main with commit 2108c44 Apr 13, 2026
79 checks passed
HanqingZ pushed a commit to HanqingZ/dify that referenced this pull request Apr 23, 2026
…dScoreConfig definitions (langgenius#34747)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer needs-revision refactor size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants