Skip to content

fix: resolve custom embedding postprocessing by canonical model name - #668

Open
serhiizghama wants to merge 2 commits into
qdrant:mainfrom
serhiizghama:fix/custom-embedding-case-insensitive-lookup
Open

fix: resolve custom embedding postprocessing by canonical model name#668
serhiizghama wants to merge 2 commits into
qdrant:mainfrom
serhiizghama:fix/custom-embedding-case-insensitive-lookup

Conversation

@serhiizghama

Copy link
Copy Markdown

Fixes #650. TextEmbedding resolves model names case-insensitively, but CustomTextEmbedding.__init__ then looked up the postprocessing config with the raw user-provided model_name. So registering a model as Org/Model and instantiating it as org/model blew up with KeyError: '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 KeyError before the change and passes now. It uses the existing lazy_load=True / specific_model_path="./" trick so nothing gets downloaded. ruff format, mypy and the offline custom-model tests are clean.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

CustomTextEmbedding.__init__ now uses the canonical model name from self.model_description.model to resolve pooling and normalization settings. A regression test covers mixed-case custom model registration and lowercase instantiation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 650 — Addresses the same case-sensitive custom model postprocessing lookup.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: resolving custom embedding postprocessing by canonical model name.
Description check ✅ Passed The description accurately explains the case-insensitive model lookup fix, regression test, and validation performed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between f613647 and e0e78a7.

📒 Files selected for processing (2)
  • fastembed/text/custom_text_embedding.py
  • tests/test_custom_models.py

Comment on lines +206 to +207
CustomTextEmbedding.SUPPORTED_MODELS.clear()
CustomTextEmbedding.POSTPROCESSING_MAPPING.clear()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 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.

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.

[Bug]: CustomTextEmbedding lookup is case-sensitive after canonical model resolution

1 participant