fix: support quantization ranges for int8 single-text embeddings - #11854
Closed
DebadityaHait wants to merge 1 commit into
Closed
DebadityaHait wants to merge 1 commit into
DebadityaHait wants to merge 1 commit into
Conversation
Contributor
|
@DebadityaHait is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Hey @DebadityaHait thanks for opening the PR! The sentence transformer components have been moved to our core integrations repo here https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/sentence_transformers so please close this PR and open the fix our core integrations repo. The sentence transformer components in this repo are deprecated and will soon be removed in Haystack v3. |
Author
|
Thanks for clarifying. I’ll close this PR and port the fix to haystack-core-integrations. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Proposed Changes:
SentenceTransformersTextEmbedderwithprecision="int8"/"uint8"returns meaningless embeddings (all zeros or all equal values) and a downstream cosine division-by-zero in retrievers. Root cause:SentenceTransformer.encodecallsquantize_embeddings(embeddings, precision)withoutranges, so the min/max calibration is computed from the batch itself — degenerate for a single query text (min == max → step 0 → NaN → cast to int8).SentenceTransformersTextEmbeddergains aquantization_rangesinit parameter (shape(2, embedding_dim): min values in the first row, max in the second), serialized into_dict/from_dict._SentenceTransformersEmbeddingBackend.embedhandles aquantization_rangeskwarg: forint8/uint8it encodes atfloat32and quantizes viasentence_transformers.util.quantize_embeddings(..., ranges=...). Behavior without ranges is unchanged.How did you test it?
precision="int8"yields a degenerate embedding without ranges, correct distinct values with ranges.test_run_quantization_with_rangeswithsentence-transformers-testing/stsb-bert-tiny-safetensorsasserting the embedding contains distinct int values.hatch run test:unit test/components/embedders/→ 167 passed;hatch run test:types→ clean;hatch run fmt→ clean; pre-commit hooks pass.Notes for the reviewer
rangesis exposed;quantize_embeddingsalso acceptscalibration_embeddings, which could be added later if users prefer passing raw embeddings from their Document Store.SentenceTransformersDocumentEmbedderbehavior is unchanged, though the backend support would allow extending it there too.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.