Skip to content

feat: Add model2vec rs - #415

Open
stephantul wants to merge 3 commits into
mainfrom
add-model2vec-rs
Open

stephantul wants to merge 3 commits into
mainfrom
add-model2vec-rs

Conversation

@stephantul

Copy link
Copy Markdown
Contributor

This PR adds model2vec-rs as the default encoding backend for model2vec. Everything will be very fast 🫡

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[High impact] The PR changes the default sentence-encoding path used across Model2Vec.

Fix the stale embedding cache before merging.

Reviews (1) · Last reviewed commit: "pin" · Reviewed by Greptile

Comment thread model2vec/model.py
Comment on lines +100 to +103
key = (self.embedding, self.weights, self.token_mapping, self.tokenizer)
cached = self.__dict__.get("_rust_backend")
if cached is not None and all(old is new for old, new in zip(cached[0], key)):
return cached[1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Embedding updates leave stale results

After a float16 model's first encode, model.embedding *= 2 keeps the same array object, so this check reuses the old backend. That backend received a separate float32 copy and still returns the old values. Meanwhile, encode_as_sequence and saved models use the updated embeddings.

Track in-place changes or provide a supported way to invalidate the cache.

Comment thread model2vec/model.py Resolved
@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
model2vec/inference/model.py 100.00% <100.00%> (ø)
model2vec/model.py 97.04% <100.00%> (-0.57%) ⬇️
model2vec/utils.py 93.75% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant