feat: Add support for SparseEncoder
and sparse embedding models in Sentence Transformers
#9588
+1,239
−13
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.
Related Issues
SentenceTransformers introduced support for sparse embedding models via the SparseEncoder class in v5.0.0. I thought it would be cool to support these in Haystack as well, since sparse models were previously only available through the FastEmbed integration (e.g. FastembedSparseTextEmbedder)
Proposed Changes:
Introduced two new embedder classes and also a class to manage these embedding classes:
SentenceTransformersSparseTextEmbedder
SentenceTransformersSparseDocumentEmbedder
SentenceTransformersSparseEncoderEmbeddingBackend
How did you test it?
I added unit tests for both embedders
Notes for the reviewer
Some tests are currently failing — I’d appreciate your support in resolving them.
And we’ll likely need to add documentation as well.
Checklist
fix:
,feat:
,build:
,chore:
,ci:
,docs:
,style:
,refactor:
,perf:
,test:
and added!
in case the PR includes breaking changes.