Skip to content

feat: Sentence Transformers - allow setting ONNX Runtime session options from YAML - #4211

Merged
sjrl merged 3 commits into
mainfrom
feat/sentence-transformers-onnx-session-options
Nov 6, 2026
Merged

sjrl merged 3 commits into
mainfrom
feat/sentence-transformers-onnx-session-options

Conversation

@sjrl

@sjrl sjrl commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Related Issues

  • PIP-923 (CPU embedders in query pods: make native thread count configurable)

Proposed Changes:

With backend="onnx", model_kwargs["session_options"] can now be a plain dict. When the model is loaded it is turned into an onnxruntime.SessionOptions with those attributes set, so ONNX Runtime threading can be configured from YAML:

backend: onnx
model_kwargs:
  file_name: onnx/model.onnx
  session_options:
    intra_op_num_threads: 1
  • Applies to all dense and sparse embedders (via the embedding backends) and to SentenceTransformersSimilarityRanker and SentenceTransformersDiversityRanker.
  • The component keeps the dict, so to_dict()/YAML round-trips and the backend cache key are unchanged.
  • onnxruntime is imported lazily, since it is only installed for the ONNX backend.

How did you test it?

  • New unit tests for the helper, both embedding backends and both rankers (onnxruntime added to the test env).
  • Manual: loaded SentenceTransformersTextEmbedder (all-MiniLM-L6-v2) from YAML and SentenceTransformersSimilarityRanker (cross-encoder/ms-marco-MiniLM-L6-v2) with backend: onnx; the live ORT sessions report intra_op_num_threads == 1 and run correctly.

Notes for the reviewer

Only plain-valued SessionOptions attributes (thread counts, booleans) can be set this way; enum-valued ones like graph_optimization_level still need Python.

Checklist

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

socket-security Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedpypi/​onnxruntime@​1.31.174100100100100

View full report

@github-actions

github-actions Bot commented Nov 6, 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/embedding_backend
  backend.py
  sparse_backend.py
  integrations/sentence_transformers/src/haystack_integrations/components/rankers/sentence_transformers
  sentence_transformers_diversity.py
  sentence_transformers_similarity.py
Project Total  

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

@sjrl sjrl self-assigned this Nov 6, 2026
@sjrl
sjrl marked this pull request as ready for review November 6, 2026 09:22
@sjrl
sjrl requested a review from a team as a code owner November 6, 2026 09:22
@sjrl
sjrl requested review from bogdankostic and removed request for a team November 6, 2026 09:22

@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

@sjrl
sjrl merged commit 247dbc3 into main Nov 6, 2026
21 checks passed
@sjrl
sjrl deleted the feat/sentence-transformers-onnx-session-options branch November 6, 2026 11:13
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