Abstract
GRACE (Generative Representation Learning via Contrastive Policy Optimization) introduces a novel framework that transforms Large Language Models (LLMs) from opaque text encoders into interpretable agents. By reframing contrastive signals as rewards within a Reinforcement Learning (RL) framework, GRACE trains models to generate human-readable rationales. These rationales serve as the basis for high-quality embeddings, significantly enhancing retrieval performance on benchmarks like MTEB while strictly preserving the model's original generative and reasoning capabilities, avoiding the "catastrophic forgetting" typical of standard fine-tuning.
Introduction
The prevailing approach to utilizing Large Language Models (LLMs) for text embeddings involves treating the model as a "black box." Practitioners typically extract hidden states from the final layer and apply a contrastive loss (e.g., InfoNCE) to align semantically similar items. However, this methodology suffers from two critical drawbacks. First, there is an Interpretability Gap: the reasoning behind a model's similarity assessment remains hidden within an opaque latent space. Second, the "Lobotomy" Effect: standard contrastive fine-tuning often degrades the model's general-purpose intelligence, leading to catastrophic forgetting in tasks like mathematical reasoning or code generation.
Methods: Contrastive Policy Optimization
GRACE addresses these issues through Contrastive Policy Optimization. Instead of minimizing a traditional loss function, the LLM is treated as a generative policy ($\pi_\theta$) tasked with producing an explicit rationale—a natural language explanation of the input's semantic essence.
The framework operates in four stages:
- Rationale Generation: The model generates a structured explanation for a given query or document.
- Embedding Extraction: Final embeddings are derived via mean pooling over the hidden states of these generated rationales.
- RL Optimization: The model is optimized using Group Relative Policy Optimization (GRPO), an efficient RL algorithm that eliminates the need for a separate critic model.
- Reward Design: The RL agent is guided by a composite reward signal including a Contrastive Reward ($R_{CL}$) to maximize similarity for positive pairs, a Consistency Reward ($R_{consist}$) to ensure stable embeddings across different rationales, and a Hard Negative Reward ($R_{hard}$) to penalize confusion with difficult distractors.
Key Results and Insights
The authors evaluated GRACE across multiple backbones, including Qwen and LLaMA, using the Massive Text Embedding Benchmark (MTEB).
Performance and Generalization
GRACE achieved an average MTEB score improvement of 11.5% in supervised settings and 6.9% in unsupervised settings compared to base models. Crucially, while standard contrastive learning often causes a total collapse in general reasoning (e.g., a Qwen-2.5-3B model's logic score dropping from 51.4 to 8.35), GRACE maintained near-original performance levels.
Interpretability as a Trace of Reasoning
By anchoring embeddings to generated rationales, the vector representation becomes a transparent "trace" of the model's internal logic. For instance, when processing a query like "Where is Machu Picchu?", the model generates a rationale identifying it as an Incan city in Peru. This explicit identification directly informs the resulting embedding, making the process inspectable by humans. As training progresses, these rationales grow more detailed, integrating historical context and complex concepts into the embedding space.
Discussion and Future Work
While GRACE offers a significant leap in interpretability and performance preservation, it introduces higher inference latency because the model must generate text before producing an embedding. Future research will focus on optimizing this process through techniques like KV-cache acceleration, speculative decoding, or low-precision execution. Additionally, scaling these findings to models exceeding 70B parameters remains a key area for exploration.
Summary updated