Skip to content

feat: add Sentence Transformers multivector embedders - #4208

Merged
anakin87 merged 8 commits into
mainfrom
sentence-transformers-multivector
Nov 10, 2026
Merged

anakin87 merged 8 commits into
mainfrom
sentence-transformers-multivector

Conversation

@anakin87

@anakin87 anakin87 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Related Issues

Proposed Changes:

  • add 2 new Multivector embedders: one for text/query and one for Documents
    • very similar to the existing components, including a backend
    • see the POC for a better usage example

How did you test it?

CI, new tests

Checklist

@github-actions github-actions Bot added integration:sentence-transformers type:documentation Improvements or additions to documentation labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report (sentence_transformers)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/sentence_transformers/src/haystack_integrations/components/embedders/sentence_transformers
  sentence_transformers_multivector_document_embedder.py 151, 240
  sentence_transformers_multivector_text_embedder.py 126, 210
  integrations/sentence_transformers/src/haystack_integrations/components/embedders/sentence_transformers/embedding_backend
  multivector_backend.py
Project Total  

This report was generated by python-coverage-comment-action

@anakin87
anakin87 marked this pull request as ready for review November 5, 2026 17:08
@anakin87
anakin87 requested a review from a team as a code owner November 5, 2026 17:08
@anakin87
anakin87 requested review from bogdankostic and removed request for a team November 5, 2026 17:08

@bogdankostic bogdankostic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good overall, just minor comments.

The main thing left is reusing the ONNX session options handling from #4211 in the new backend.

trust_remote_code=trust_remote_code,
revision=revision,
local_files_only=local_files_only,
model_kwargs=model_kwargs,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The dense and sparse backends turn a session_options dict in model_kwargs into an onnxruntime.SessionOptions object (added in #4211).

Let's import _resolve_onnx_session_options from backend.py and reuse it:

Suggested change
model_kwargs=model_kwargs,
model_kwargs=_resolve_onnx_session_options(model_kwargs=model_kwargs)
if backend == "onnx"
else model_kwargs,

Let's also copy the session_options sentence from the sparse embedders into the model_kwargs docstrings of both components.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added in d3329a5

texts_to_embed.append(text_to_embed)

# mypy doesn't know this is set in warm_up
embeddings = self.embedding_backend.embed( # type: ignore[union-attr]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think about adding encode_kwargs like SentenceTransformersDocumentEmbedder has?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added in 38a1f31

"haystack_integrations.components.embedders.sentence_transformers.embedding_backend.multivector_backend.MultiVectorEncoder"
)
@pytest.mark.parametrize("is_query", [True, False])
def test_embedding_function_with_kwargs(mock_multivector_encoder, is_query):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the name is a bit misleading, as we're not really testing kwargs that are further passed on to encode_query (like normalize_embeddings) here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

now that we have encode_kwargs, the name is more appropriate

@bogdankostic bogdankostic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@anakin87
anakin87 merged commit 20582f9 into main Nov 10, 2026
19 checks passed
@anakin87
anakin87 deleted the sentence-transformers-multivector branch November 10, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:sentence-transformers type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants