Skip to content

fix(embeddings): honor query and document prompts locally - #3032

Merged
nicoloboschi merged 2 commits into
vectorize-io:mainfrom
jpmf33:fix/local-st-asymmetric-encoding
Aug 5, 2026
Merged

fix(embeddings): honor query and document prompts locally#3032
nicoloboschi merged 2 commits into
vectorize-io:mainfrom
jpmf33:fix/local-st-asymmetric-encoding

Conversation

@jpmf33

@jpmf33 jpmf33 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • route local query embeddings through SentenceTransformer.encode_query()
  • route local stored content through SentenceTransformer.encode_document()
  • preserve the existing generic encode() behavior
  • preserve post-inference memory release for every path

Why

Hindsight already distinguishes query and document inputs in embedding_utils, but LocalSTEmbeddings inherited the base implementations that collapse both paths into generic encode(). 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
  • focused review: branch contains one relevant commit and two changed files; no findings

jpmf33 and others added 2 commits August 5, 2026 11:37
…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
nicoloboschi force-pushed the fix/local-st-asymmetric-encoding branch from 8bd4102 to 98ad27f Compare August 5, 2026 09:39
@nicoloboschi
nicoloboschi merged commit 468cc4b into vectorize-io:main Aug 5, 2026
194 of 281 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants