fix(embeddings): honor query and document prompts locally - #3032
Merged
nicoloboschi merged 2 commits intoAug 5, 2026
Conversation
…tric encoding encode_query()/encode_document() only exist from sentence-transformers 5.0 onwards. The local-ml extra pinned >=3.3.0, so on 4.x the new code path was an AttributeError at the first encode (recall/retain), not at startup. The extra was only accidentally safe because it also pins transformers>=5.5.0, which ST <5 caps out; docker/docker-compose/custom-models/Dockerfile mirrors the pins with transformers>=4.53.0 and could genuinely resolve to ST 4.x. Also: - assert the real SentenceTransformer class exposes both entry points; the existing test drives a MagicMock, so it passes on any version - explain why the model's own entry points are used instead of prefixing here, and note that prompt-less models are unaffected - document the one case that needs a re-index: a local model that instructs the stored side as well as the search side
nicoloboschi
force-pushed
the
fix/local-st-asymmetric-encoding
branch
from
August 5, 2026 09:39
8bd4102 to
98ad27f
Compare
6 tasks
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.
Summary
SentenceTransformer.encode_query()SentenceTransformer.encode_document()encode()behaviorWhy
Hindsight already distinguishes query and document inputs in
embedding_utils, butLocalSTEmbeddingsinherited the base implementations that collapse both paths into genericencode(). SentenceTransformer models with asymmetric prompts, including Qwen3-Embedding, therefore never receive their configured query prompt.Using the native SentenceTransformer entry points also preserves task routing for models that provide a Router module, without adding model-specific configuration to Hindsight.
Validation
uv run pytest tests/test_local_embeddings.py tests/test_local_device.py -q— 23 passed./scripts/hooks/lint.sh— passed