TL;DR
The paper introduces EPIC (Embedding-based Prompt training with In-Context demonstrations), a method that replaces long text examples in few-shot embedding prompts with compact, continuous vector embeddings. This approach delivers the performance boosts of in-context learning for Large Language Models (LLMs) acting as text encoders, while slashing inference latency by up to 70% and significantly reducing token overhead.
What Problem Does This Paper Address?
Adapting Large Language Models (LLMs) into text encoders via contrastive learning has become a dominant approach for generating high-quality text embeddings. Recently, researchers found that In-Context Learning (ICL)—prepending a few task-related examples (e.g., query-passage pairs) to the input—significantly boosts embedding quality.
However, this text-based ICL comes with a massive catch: token overhead. Prepending multiple text examples drastically increases the sequence length. In latency-sensitive applications like Retrieval-Augmented Generation (RAG) or real-time information retrieval, this extra computational burden during both training and inference makes textual ICL highly impractical.
Methods
To eliminate the token tax of textual ICL, the authors propose EPIC. Instead of feeding discrete text demonstrations into the LLM prompt, EPIC compresses each demonstration query-passage pair into continuous vector representations (embeddings) generated by the model itself.
Here is how the workflow operates:
- Embedding Generation: For a given demonstration pair $(Q_i, P_i)$, the LLM generates their standard embeddings via the
[EOS]token. - Lightweight Projection: These embeddings are passed through a lightweight Multi-Layer Perceptron ($g(\cdot)$) with a GELU activation to align them into a shared latent space, yielding continuous vectors $q_i$ and $p_i$.
- Prompt Construction: These continuous vectors are directly concatenated with the task instruction and the target query text, forming an embedding-based in-context prompt.
- Training Strategy: The model is fine-tuned using supervised contrastive learning (InfoNCE loss). During training, the number of demonstration pairs is randomly varied from 0 to 5, forcing the model to perform well both with and without in-context prompts.
At inference time, these demonstration embeddings only need to be computed once, stored, and reused across various user inputs.
Datasets
- Training: The public portion of the E5 dataset, curated by Springer et al. (2025). This corpus contains roughly 1.5 million samples across various open-source retrieval datasets (including MS-MARCO, HotpotQA, NQ, SQuAD, and TriviaQA).
- Evaluation: The full Massive Text Embeddings Benchmark (MTEB), consisting of 56 datasets spanning 7 core tasks (Retrieval, Reranking, Clustering, Pair Classification, Classification, STS, and Summarization). A smaller 26-dataset subset of MTEB was utilized for rapid ablation testing.
Key Insights and Ideas
- Models as Self-Interpreters: EPIC forces the LLM to not only generate high-quality embeddings but also interpret its own past embeddings when they are fed back into the prompt.
- The "Zero-Shot" Bonus: Surprisingly, even when in-context prompts are completely removed at inference time, EPIC-trained models still outperform standard contrastive baselines. The authors discovered that EPIC training mitigates the "attention sink" phenomenon (where causal LLMs over-attend to the very first token), allowing the model to aggregate semantic information more effectively across the entire sequence.
- Information Density: Ablation studies revealed that compressing an entire text example into a single vector is entirely sufficient; increasing the number of continuous tokens per demonstration (e.g., sampling multiple tokens from the sequence) did not yield better performance.
Key Results
The authors evaluated EPIC across three popular open-weight architectures: Qwen2.5-7B, Mistral-7B, and LLaMA-3.1-8B.
- State-of-the-Art Performance: EPIC established new SOTA results on the MTEB benchmark among models trained exclusively on public retrieval data. For instance, EPIC-Mistral-7B achieved an average score of 66.37, outperforming its textual ICL counterpart,
bge-en-icl(66.18), and standard E5 (64.56). - Massive Speedups: EPIC reduced inference latency by up to 70% compared to conventional textual ICL on long-context datasets like STS22.
- Lower Training Overhead: Implementing conventional textual ICL increases training time by over 60% compared to a standard baseline. EPIC, by contrast, only incurs a modest 19% training time overhead.
Limitations and Future Work
- Data Constraints: The model was only trained on publicly available retrieval data. The authors note that incorporating massive, proprietary synthetic datasets (similar to frontier commercial models) could further push performance boundaries.
- Scale Limitations: Due to hardware constraints, the method was only validated on models up to 8B parameters. Testing on 30B+ or 70B+ models remains future work.
- Mechanistic Mystery: While the empirical results are strong, a deep, mechanistic explanation of exactly how vector-based ICL guides the internal attention layers of text encoders remains an open research question.
Summary updated