fix: resolve custom embedding postprocessing by canonical model name - #668
fix: resolve custom embedding postprocessing by canonical model name#668serhiizghama wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthrough
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 `@tests/test_custom_models.py`:
- Around line 206-207: Update the restore_custom_models_fixture to clear both
CustomTextEmbedding.SUPPORTED_MODELS and
CustomTextEmbedding.POSTPROCESSING_MAPPING during fixture setup and teardown,
ensuring cleanup also runs when construction or assertions fail and preventing
stale configuration across tests.
🪄 Autofix
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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a95557db-2f8c-47b4-9e80-c8eb052d9a57
📒 Files selected for processing (2)
fastembed/text/custom_text_embedding.pytests/test_custom_models.py
| CustomTextEmbedding.SUPPORTED_MODELS.clear() | ||
| CustomTextEmbedding.POSTPROCESSING_MAPPING.clear() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Make custom-model cleanup exception-safe.
If construction or an assertion fails before these lines, CustomTextEmbedding.POSTPROCESSING_MAPPING retains the registered entry. The shown restore_custom_models_fixture resets SUPPORTED_MODELS but not POSTPROCESSING_MAPPING. A later test can observe stale configuration. Clear both registries in the fixture setup and teardown.
Suggested fixture fix
def restore_custom_models_fixture():
CustomTextEmbedding.SUPPORTED_MODELS = []
+ CustomTextEmbedding.POSTPROCESSING_MAPPING.clear()
CustomTextCrossEncoder.SUPPORTED_MODELS = []
yield
CustomTextEmbedding.SUPPORTED_MODELS = []
+ CustomTextEmbedding.POSTPROCESSING_MAPPING.clear()
CustomTextCrossEncoder.SUPPORTED_MODELS = []🤖 Prompt for 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.
In `@tests/test_custom_models.py` around lines 206 - 207, Update the
restore_custom_models_fixture to clear both CustomTextEmbedding.SUPPORTED_MODELS
and CustomTextEmbedding.POSTPROCESSING_MAPPING during fixture setup and
teardown, ensuring cleanup also runs when construction or assertions fail and
preventing stale configuration across tests.
Fixes #650.
TextEmbeddingresolves model names case-insensitively, butCustomTextEmbedding.__init__then looked up the postprocessing config with the raw user-providedmodel_name. So registering a model asOrg/Modeland instantiating it asorg/modelblew up withKeyError: 'org/model'even though the parent had already resolved the name fine.Switched the lookup to
self.model_description.model— the canonical name the parent resolves to — so registration and instantiation stay case-insensitive.Added a test that registers under one casing and instantiates under another; it reproduced the
KeyErrorbefore the change and passes now. It uses the existinglazy_load=True/specific_model_path="./"trick so nothing gets downloaded.ruff format,mypyand the offline custom-model tests are clean.