Llama2Vec: Unsupervised Adaptation of Large Language Models for Dense Retrieval

Zheng Liu, Chaofan Li, Shitao Xiao, Yingxia Shao, Defu Lian
12/24/2023
cs.CL

Official code: FlagOpen/FlagEmbedding (11,860 stars, MIT, last commit 2026-04-22).

Abstract

Dense retrieval calls for discriminative embeddings to represent the semantic relationship between query and document. It may benefit from the using of large language models (LLMs), given LLMs' strong capability on semantic understanding. However, the LLMs are learned by auto-regression, whose working mechanism is completely different from representing whole text as one discriminative embedding. Thus, it is imperative to study how to adapt LLMs properly so that they can be effectively initialized as the backbone encoder for dense retrieval. In this paper, we propose a novel approach, called Llama2Vec, which performs unsupervised adaptation of LLM for its dense retrieval application. Llama2Vec consists of two pretext tasks: EBAE (Embedding-Based Auto-Encoding) and EBAR (Embedding-Based Auto-Regression), where the LLM is prompted to reconstruct the input sentence and predict the next sentence based on its text embeddings. Llama2Vec is simple, lightweight, but highly effective. It is used to adapt LLaMA-2-7B on the Wikipedia corpus. With a moderate steps of adaptation, it substantially improves the model's fine-tuned performances on a variety of dense retrieval benchmarks. Notably, it results in the new state-of-the-art performances on popular benchmarks, such as passage and document retrieval on MSMARCO, and zero-shot retrieval on BEIR. The model and source code will be made publicly available to facilitate the future research. Our model is available at https://github.com/FlagOpen/FlagEmbedding.

View on arXivView PDF

Code Implementations(1)

MIT

Retrieval and Retrieval-augmented LLMs

11,860891Shell, PythonAug 2, 20236 months agoMIT
embeddingsinformation-retrievalllmretrieval-augmented-generationsentence-embeddings+1 more

Similar Papers

Cite this paper

@article{liu2023llamavec,
  title  = {Llama2Vec: Unsupervised Adaptation of Large Language Models for Dense Retrieval},
  author = {Zheng Liu and Chaofan Li and Shitao Xiao and Yingxia Shao and Defu Lian},
  year   = {2023},
  eprint = {2312.15503},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2312.15503v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2312.15503.svg)](https://codeofpaper.com/paper/2312.15503)

Discussion