infinity icon indicating copy to clipboard operation
infinity copied to clipboard

Allow to pass SentenceTransformers `task` and `prompt`

Open dantetemplar opened this issue 6 months ago • 9 comments

Feature request

I want to use https://huggingface.co/jinaai/jina-embeddings-v3 with via infinity server and client, but I cant find an example to run it with task as in SentenceTransformers:

from sentence_transformers import SentenceTransformer

model = SentenceTransformer("jinaai/jina-embeddings-v3", trust_remote_code=True)

task = "retrieval.query"
embeddings = model.encode(
    ["What is the weather like in Berlin today?"],
    task=task,
    prompt_name=task,
)

Motivation

It will not be practical to use infinity for jinaai embeddings (and some others) without this functionality. Actually, we can prefix our input text with relevant prompt, but we should not.

Your contribution

I may be the first who will test and give feedback. If you hint me a contribution start point, I can try to cook a PR.

dantetemplar avatar Jun 25 '25 15:06 dantetemplar

Hi,

The easiest way would be to provide the task and prompt at the startup of the model. Would this cover your use case?

Prompt could be passed in and prepended here.

For the task, you would pass it here.

This PR does similar changes for the dimensions param.

wirthual avatar Jun 30 '25 02:06 wirthual

Hi,

The easiest way would be to provide the task and prompt at the startup of the model. Would this cover your use case?

Prompt could be passed in and prepended here.

For the task, you would pass it here.

This PR does similar changes for the dimensions param.

I guess task and prompt should be passed to embedding, not in the model init stage: same model can be used for two tasks: retrieval.query and retrieval.passage.

dantetemplar avatar Jun 30 '25 10:06 dantetemplar

In this case you would want to add the task and prompt as additonal parameters to the request. You could modify _OpenAIEmbeddingInput to take task and prompt. Then pass it through to the methods as linked in my previous comment.

One challenge I can see is we need to separate the batches based on the task to pass them through the sentence transformer.

wirthual avatar Jul 11 '25 16:07 wirthual

@dantetemplar did you solve it?

pySilver avatar Sep 01 '25 23:09 pySilver

The LoRA adapters are the core of jina-embeddings-v3, without this feature, one cannot claim that the model is supported.

mhoangvslev avatar Sep 02 '25 07:09 mhoangvslev

@dantetemplar did you solve it?

Just prefix your text with correct prefix from your model's config on huggingface

dantetemplar avatar Sep 02 '25 12:09 dantetemplar

@dantetemplar this model requires task specification, not simple prefix unfortunately

pySilver avatar Sep 03 '25 09:09 pySilver

So, does your model change inference path (what head to use) depending on that parameter?

If yes, dunno what to do actually except patching this framework

dantetemplar avatar Sep 03 '25 12:09 dantetemplar

@dantetemplar looking at the code of models more closely, you are right it's just a prefix. So one can simply provide it.

pySilver avatar Sep 04 '25 10:09 pySilver