Skip to content

feat: make setters for max_length - #356

Merged
stephantul merged 6 commits into
mainfrom
allow-setters
Aug 31, 2026
Merged

feat: make setters for max_length#356
stephantul merged 6 commits into
mainfrom
allow-setters

Conversation

@stephantul

@stephantul stephantul commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

This PR allows users to set max_length on the model2vec model object itself. When set to None, truncation is disabled as before. This setting is correctly stored on the model, like normalize. As before, it is still possible to override max_length from encode. When max_length is not specified, we set it to a default of 512. This ensures that old models still have the same behavior.

One new feature is that max_length is propagated to the pipeline and the training. These previously both used hardcoded constants of 512 (training) and a similar construct to the main StaticModel (pipeline). The end result is that users now have a central way to set max_length on their models, and that this setting is respected by all consumers.

I also turned the config we load into a TypedDict, and had to create a sentinel type to distinguish between max_length not being set and the user disabling max_length (None)

@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
model2vec/distill/distillation.py 94.52% <100.00%> (+0.07%) ⬆️
model2vec/inference/model.py 100.00% <100.00%> (ø)
model2vec/model.py 97.39% <100.00%> (+1.74%) ⬆️
model2vec/onnx.py 99.25% <100.00%> (+0.77%) ⬆️
model2vec/persistence/persistence.py 98.73% <100.00%> (+0.01%) ⬆️
model2vec/train/base.py 97.97% <100.00%> (+0.06%) ⬆️
model2vec/train/classifier.py 98.33% <100.00%> (+0.01%) ⬆️
model2vec/train/similarity.py 100.00% <100.00%> (ø)
model2vec/types.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stephantul
stephantul requested a review from Pringled August 30, 2026 05:26

@Pringled Pringled left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Comment thread model2vec/types.py
_UNSET = _UnsetType()


class StaticModelConfig(TypedDict, total=False):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ohhh this is nice

@stephantul
stephantul merged commit 26373f1 into main Aug 31, 2026
11 checks passed
@stephantul
stephantul deleted the allow-setters branch August 31, 2026 16:46
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.

2 participants