LEANN icon indicating copy to clipboard operation
LEANN copied to clipboard

Add support for task-specific prompt templates for embedding models

Open ww2283 opened this issue 2 months ago • 1 comments

What problem does this solve?

Please check the following description and let me know if this is feasible, then I can help to implement this feature to support template prepending embedding models.

Context

Google's new https://huggingface.co/blog/embeddinggemma model introduces task-specific prompts that significantly improve embedding quality. The model requires different prompts prepended to text based on the use case:

  • Queries: "task: search result | query: "
  • Documents: "title: none | text: "
  • Other tasks: Classification, clustering, reranking each have specific prompts

Problem

When using EmbeddingGemma via LM Studio's OpenAI-compatible endpoint (or similar servers), LEANN currently sends raw text without task-specific prompts. This prevents leveraging EmbeddingGemma's full capabilities.

Proposed Solution

Add a prompt_template parameter to provider_options in the OpenAI embedding mode:

Query time (search)

provider_options={ "prompt_template": "task: search result | query: " }

Build time (indexing documents)

provider_options={ "prompt_template": "title: none | text: " }

Implementation would prepend the template to all texts before sending to the API: prompt_template = provider_options.get("prompt_template") if prompt_template: texts = [f"{prompt_template}{text}" for text in texts]

Why LEANN Should Handle This

  • Context awareness: LEANN knows whether text is a query or document
  • Server agnostic: Works with any OpenAI-compatible endpoint (LM Studio, vLLM, TEI)
  • Future-proof: Other embedding models may adopt similar prompt-based approaches

Benefits

  • Unlock EmbeddingGemma's performance gains
  • Support emerging prompt-based embedding models
  • Minimal implementation complexity

Proposed solution

NA

Example usage


ww2283 avatar Oct 27 '25 18:10 ww2283

Wow, that is amazing!

yichuan-w avatar Oct 28 '25 05:10 yichuan-w