Manuscript Offprint

arXiv:2609.38099

Effective Dense Retrieval using Only In-Context Examples

Nour Jedidi, Abdul Basit Ali, Hang Li, Jimmy Lin

Abstract

Turning decoder-only large language models (LLMs) into strong dense retrievers typically requires some form of retriever training. In this paper, we ask whether LLMs can instead be prompted to produce effective representations for dense retrieval given only a few in-context examples. To answer this, we introduce RICE (Representations from In-Context Examples), a simple “training-free” approach that extracts high-quality dense representations from LLMs. To do so, RICE conditions the LLM on examples that provide a shared context for query and document encoding. Our results demonstrate that RICE embeddings can substantially improve the accuracy of prompt-based LLM embeddings, establishing it as a simple method to build LLM-based dense retrievers that do not require training. We release our code at https://github.com/nourj98/RICE.

1 Introduction

Large language models (LLMs) have emerged as powerful backbones for modern dense retrieval systems thanks to their rich world knowledge and text understanding capabilities (Zhang et al., 2025). But “out-of-the-box”, their hidden states do not automatically yield effective embedding representations for dense retrieval. As a result, strong LLM-based dense retrieval systems typically rely on additional retriever training, often through supervised (Ma et al., 2024; Thakur et al., 2025) or unsupervised (BehnamGhader et al., 2024, 2026) objectives. Building strong LLM-based embeddings that require no training remains an open challenge.

In this paper, we seek to address this challenge by drawing on two insights from the broader literature on zero- and few-shot dense retrieval. The first is that, given only a few human-labeled in-context examples, LLMs can be prompted to produce effective task-specific synthetic data for training downstream dense retrievers (Dai et al., 2023; Gwon et al., 2025). But as we aim to build LLM dense retrievers that do not require training, we draw on a second insight from PromptReps (Zhuang et al., 2024), which demonstrated that LLMs can be directly prompted to generate query and document representations for retrieval. However, one limitation of PromptReps is that query and document representations are derived independently via separate prompts, without any shared context connecting the two encoding tasks.

Inspired by these insights, we ask: Can LLMs be prompted, using only a few in-context examples, to produce effective representations for dense retrieval? To answer this, we introduce RICE (Representations from In-Context Examples), an approach for prompting LLMs to produce high-quality dense representations without requiring any form of retrieval-specific training. To do so, RICE combines the ease and simplicity of directly prompting LLMs for representations with the ability of LLMs to infer task-specific retrieval cues from only a few in-context examples.

Like PromptReps, RICE derives embeddings by prompting an LLM to generate a representative word for a query or document and extracting its final hidden state. Unlike PromptReps, which relies on an instruction alone, RICE primes this word generation process using query–document pairs that illustrate how the LLM itself represents the given document through PromptReps-generated words. These demonstrations provide a shared context for query and document encoding with the aim of producing representations whose inner products better reflect relevance.

In summary, our contributions are twofold. First, we propose RICE, a simple approach for extracting – via prompts – dense retrieval representations from LLMs using only in-context examples. Second, we comprehensively evaluate RICE on various retrieval datasets from BEIR (Thakur et al., 2021), and show that with only a few in-context examples, LLMs can produce strong representations for dense retrieval without requiring retrieval-specific training. In particular, we demonstrate that RICE improves the effectiveness of prompt-based LLM representations. When compared against other dense retrieval approaches that also work directly “out-of-the-box”, like HyDE (Gao et al., 2023), RICE achieves the highest average accuracy among these evaluated approaches. When compared against LLM2Vec-Gen (BehnamGhader et al., 2026), a highly effective self-supervised dense retriever, RICE is competitive. While RICE is less effective than dense retrievers trained on large collections of high-quality data, our findings show that in-context examples can offer a promising approach for narrowing the effectiveness gap between training-free, prompt-based retrieval and supervised dense retrievers.