Dense passage retrieval

Also known as: DPR

On this page 7

Dense passage retrieval (DPR) is a neural retrieval method that encodes questions and text passages into dense vectors with two separately trained encoders and returns the passages whose vectors have the highest similarity to the question vector. In artificial intelligence, and especially in retrieval & knowledge systems, DPR showed that learned embeddings can outperform BM25 for open-domain question answering, and it became the template for the retriever stage in many RAG pipelines.

The method was introduced by researchers at Facebook AI in 2020. The name refers both to the general technique and to the specific DPR model and training recipe, which used BERT encoders, Wikipedia passages and in-batch negatives to learn what a relevant answer passage looks like.

How dense passage retrieval encodes and matches text

DPR uses a bi-encoder architecture: one encoder maps a question to a vector, and a second encoder maps each passage to a vector of the same size. In the original model, both encoders are BERT-base networks, and the 768-dimensional representation of the [CLS] token serves as the embedding. Relevance is scored with a simple dot product between the two vectors.

Because the encoders are independent, every passage in the corpus can be encoded once offline and stored in a vector index. At query time, only the question needs encoding, and an approximate nearest neighbor search over the index returns the top-k passages in milliseconds. This separation is what makes DPR practical at the scale of millions of passages.

The original pipeline has three distinct stages, summarized below with the components used in the reference implementation.

StageWhen it runsReference component
Passage encodingOffline, once per corpusBERT passage encoder
IndexingOffline, after encodingFAISS vector index
Question encodingOnline, per queryBERT question encoder
Similarity searchOnline, per queryMaximum inner product search
Reading or generationOnline, after retrievalExtractive reader or generator model
Stages of a dense passage retrieval pipeline

Training with in-batch and hard negatives

DPR is trained with a contrastive objective that pulls a question toward its positive passage and pushes it away from negative passages. The loss is the negative log-likelihood of the positive passage under a softmax over the scores of all candidates in the training batch.

The key efficiency trick is in-batch negatives: the positive passages of the other questions in the same batch serve as negatives, so a batch of B questions yields B × B comparisons almost for free. The authors added one hard negative per question, a passage ranked highly by BM25 that does not contain the answer, which teaches the model to reject passages that merely share keywords.

SettingTypical valueEffect on the model
Passage length100 wordsUniform units for retrieval and reading
Corpus sizeAbout 21 million passagesFull English Wikipedia coverage
Embedding size768 dimensionsExpressive vectors, large index
Batch size128 questionsMore in-batch negatives per step
Hard negativesOne BM25 passage per questionBetter rejection of lexical decoys
Main DPR training settings and their effect

Later work refined this recipe with mined hard negatives from the dense model itself, distillation from cross-encoders and large-scale pretraining on question-passage pairs, but the basic contrastive setup remains the same.

Dense passage retrieval compared with other retrievers

DPR is the best-known example of dense retrieval, which contrasts with sparse and late-interaction approaches. Each family makes a different trade-off between semantic matching, exact term matching, index size and latency.

MethodRepresentationStrengthWeakness
BM25Sparse term weightsExact names, codes and rare wordsMisses paraphrases and synonyms
DPROne dense vector per textSemantic and paraphrase matchingWeak on rare entities and new domains
ColBERTMany vectors per textFine-grained token matchingMuch larger index
SPLADELearned sparse weightsInverted index with expansionMore complex training
Cross-encoderJoint question-passage encodingHighest ranking accuracyToo slow for first-stage search
DPR and neighboring retrieval methods

On the Natural Questions benchmark, the original DPR reached about 78% top-20 accuracy, compared with about 59% for BM25, meaning the answer appeared in the top 20 passages far more often. On SQuAD, where questions were written while viewing the passage and share many words with it, BM25 remained stronger, which illustrates where lexical overlap still matters.

Using DPR in retrieval-augmented systems

In modern RAG systems, DPR-style bi-encoders form the first-stage retriever that narrows a large corpus to a few dozen candidates. A reranker or the language model then works only on that shortlist. The decision table below shows how practitioners typically configure the retriever.

SituationRecommended choiceReason
Many product codes or namesHybrid search with BM25Dense vectors blur exact strings
Specialized domain textFine-tune on in-domain pairsOff-the-shelf models generalize poorly
Precision matters mostAdd a cross-encoder rerankerRescores the top candidates jointly
Very large corpusQuantized ANN indexCuts memory and latency
Frequent content updatesRe-encode only changed passagesAvoids full index rebuilds
Configuration choices for a dense retriever

Index memory is a practical concern: 21 million passages with 768-dimensional float32 vectors need roughly 60 GB before compression. Product quantization or binary embeddings reduce this substantially at a modest cost in recall.

Limitations and failure modes

  • Poor out-of-domain generalization. DPR trained on Wikipedia questions often underperforms BM25 on benchmarks such as BEIR.
  • Weakness on rare entities. Unusual names, numbers and identifiers are compressed poorly into a single vector.
  • Fixed passage boundaries. Answers split across two 100-word chunks may never be retrieved together.
  • Re-encoding cost. Changing the passage encoder requires recomputing every vector in the index.

These limits explain why production systems rarely rely on dense retrieval alone. Hybrid search, reranking and domain fine-tuning address most of them, while the core DPR idea of encoding text into comparable vectors stays at the center of semantic search.

In everyday language

Dense passage retrieval is a way to find text by meaning, not by exact words. The system turns every question and every paragraph into a list of numbers. Similar meanings get similar numbers.

Imagine a librarian who understands what a question means. Ask about the tallest mountain, and the librarian also brings pages about Everest, even if the word tallest never appears. That is the core idea: match ideas, not just words.

Seen in the real world

A support team at a software company maintains about 40,000 help articles, split into roughly 300,000 short passages. Customers often describe problems in their own words, such as “the app forgets my login,” while the articles say “session token expiration.” Keyword search returns poor results for these questions.

The team fine-tunes a DPR-style bi-encoder on 20,000 historical pairs of customer questions and the articles that solved them. Passages are encoded overnight and stored in an approximate nearest neighbor index, and each incoming question is matched within about 50 milliseconds. A cross-encoder reranks the top 20 results before a language model drafts the answer.

The outcome is noticeably better answer coverage for paraphrased questions. The team keeps BM25 in a hybrid setup, however, because queries containing error codes such as E4031 still match more reliably by exact keywords.