refactor: use MetadataFilteringCondition BaseModel in RetrievalService.external_retrieve#35869
Draft
gaurav0107 wants to merge 1 commit intolanggenius:mainfrom
Draft
Conversation
…e.external_retrieve Follow the dict -> Pydantic BaseModel pattern established by langgenius#31514, langgenius#34080 and langgenius#34422: RetrievalService.external_retrieve now accepts metadata_filtering_conditions: MetadataFilteringCondition | None directly instead of dict[str, Any] | None. The redundant internal MetadataFilteringCondition.model_validate(...) call is removed; validation now happens at the call site in HitTestingService.external_retrieve, following the "validate at the boundary" principle cited in the issue. Unit tests are updated to pass typed instances where appropriate and a regression test is added for the None path. Behavior is otherwise preserved. external_retrieval_model is left as dict[str, Any] because it is an opaque payload forwarded to external retrieval providers. Fixes part of langgenius#31497.
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-05-07 06:31:55.825147961 +0000
+++ /tmp/pyrefly_pr.txt 2026-05-07 06:31:46.255042949 +0000
@@ -5875,15 +5875,15 @@
ERROR Cannot index into `object` [bad-index]
--> tests/unit_tests/services/hit_service.py:462:16
ERROR Cannot index into `list[Unknown]` [bad-index]
- --> tests/unit_tests/services/hit_service.py:497:20
+ --> tests/unit_tests/services/hit_service.py:503:20
ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/services/hit_service.py:497:20
+ --> tests/unit_tests/services/hit_service.py:503:20
ERROR Argument `dict[str, str] | list[Unknown] | object` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/unit_tests/services/hit_service.py:498:24
+ --> tests/unit_tests/services/hit_service.py:504:24
ERROR Cannot index into `list[Unknown]` [bad-index]
- --> tests/unit_tests/services/hit_service.py:531:20
+ --> tests/unit_tests/services/hit_service.py:539:20
ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/services/hit_service.py:531:20
+ --> tests/unit_tests/services/hit_service.py:539:20
ERROR Object of class `Marketplace` has no attribute `repo`
ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
--> tests/unit_tests/services/plugin/test_oauth_service.py:50:34
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes part of #31497.
Summary
Follow the dict -> Pydantic BaseModel pattern established by #31514, #34080, and #34422:
RetrievalService.external_retrievenow acceptsmetadata_filtering_conditions: MetadataFilteringCondition | Nonedirectly instead ofdict[str, Any] | None.The redundant internal
MetadataFilteringCondition.model_validate(...)call is removed; validation now happens at the call site (HitTestingService.external_retrieve), following the "validate at the boundary" principle cited in the issue.Unit tests are updated to pass typed instances where appropriate, and a regression test is added for the
Nonepath. Behavior is otherwise preserved.external_retrieval_modelis left asdict[str, Any]because it is an opaque payload forwarded to external retrieval providers (no single BaseModel describes the union of provider-specific options).Screenshots
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods