encode_document() never uses a "passage" or "corpus" prompt

Author: LindseyZ1205Created Sep 26, 2026Updated Sep 29, 2026

encode_document() looks for a prompt named "document", then "passage", then "corpus", and uses the first one that exists in model.prompts. But SentenceTransformer, SparseEncoder and MultiVectorEncoder inject _default_prompts = {"query": None, "document": None} into model.prompts at init, and _validate_prompts turns the None into "". So "document" always exists (as an empty prompt), and "passage" / "corpus" are never used.

This is exactly the example the prompts docstring gives (the E5 convention), so documents are silently encoded without their prompt:

python
import numpy as np
from sentence_transformers import SentenceTransformer

model = SentenceTransformer(
    "sentence-transformers-testing/stsb-bert-tiny-safetensors",
    prompts={"query": "query: ", "passage": "passage: "},
)
print(model.prompts)  # {'query': 'query: ', 'document': '', 'passage': 'passage: '}

docs = ["Paris is the capital of France."]
print(np.allclose(model.encode_document(docs), model.encode(docs, prompt_name="passage")))  # False, expected True
print(np.allclose(model.encode_document(docs), model.encode(docs)))                          # True: no prompt used

Code (main @ 4a3b5cd6):

The same happens when the prompts come from a saved config_sentence_transformers.json. Since the evaluators and mine_hard_negatives call encode_document, they are affected too. The existing prompt-priority tests set model.prompts = {...} directly, which bypasses the injected default, so they don't catch it.

A possible fix is to prefer the first candidate with a non-empty prompt and otherwise keep the current choice, in the three encode_document methods (or a shared helper). I'd be happy to open a PR if that approach works for you, or a different one if you'd rather not inject the empty "document" prompt at all.

Source: huggingface/sentence-transformers