task_categories:text-retrieval region:us pyterrier pyterrier-artifact pyterrier-artifact.sparse_index pyterrier-artifact.sparse_index.anserini
---
# pretty_name: "" # Example: "MS MARCO Terrier Index"
tags:
- pyterrier
- pyterrier-artifact
- pyterrier-artifact.sparse_index
- pyterrier-artifact.sparse_index.anserini
task_categories:
- text-retrieval
viewer: false
---

# MS MARCO Anserini Index

## Description

This is an index of the MS MARCO passage (v1) dataset with Anserini. It can be used for passage retrieval using lexical methods.

## Usage

```python
>>> from pyterrier_anserini import AnseriniIndex
>>> index = AnseriniIndex.from_hf('macavaney/msmarco-passage.anserini')
>>> bm25 = index.bm25(include_fields=['contents'])
>>> bm25.search('terrier breeds')
  qid           query    docno    score  rank                                      contents
0   1  terrier breeds  5785957  11.9588     0  The Jack Russell Terrier and the Russell ...
1   1  terrier breeds  7455374  11.9343     1  FCI, ANKC, and IKC recognize the shorts a...
2   1  terrier breeds  1406578  11.8640     2  Norfolk terrier (English breed of small t...
3   1  terrier breeds  3984886  11.7518     3  Terrier Group is the name of a breed Grou...
4   1  terrier breeds  7728131  11.5660     4  The Yorkshire Terrier didn't begin as the...
...
```

## Benchmarks

**TREC DL 2019**

<details>
  <summary>Code</summary>

```python
from ir_measures import nDCG, RR, MAP, R
import pyterrier as pt
from pyterrier_anserini import AnseriniIndex
index = AnseriniIndex.from_hf('macavaney/msmarco-passage.anserini')
dataset = pt.get_dataset('irds:msmarco-passage/trec-dl-2019/judged')
pt.Experiment(
  [index.bm25(), index.qld(), index.tfidf()],
  dataset.get_topics(),
  dataset.get_qrels(),
  [nDCG@10, nDCG, RR(rel=2), MAP(rel=2), R(rel=2)@1000],
  ['BM25', 'QLD', 'TF-IDF'],
  round=4,
)
```
</details>

|    | name   |   nDCG@10 |   nDCG |   RR(rel=2) |   AP(rel=2) |   R(rel=2)@1000 |
|---:|:-------|----------:|-------:|------------:|------------:|----------------:|
|  0 | BM25   |    0.5121 | 0.61   |      0.715  |      0.3069 |          0.7529 |
|  1 | QLD    |    0.4689 | 0.5995 |      0.606  |      0.3014 |          0.7662 |
|  2 | TF-IDF |    0.3742 | 0.5083 |      0.5203 |      0.2012 |          0.7016 |

**TREC DL 2020**

<details>
  <summary>Code</summary>

```python
from ir_measures import nDCG, RR, MAP, R
import pyterrier as pt
from pyterrier_anserini import AnseriniIndex
index = AnseriniIndex.from_hf('macavaney/msmarco-passage.anserini')
dataset = pt.get_dataset('irds:msmarco-passage/trec-dl-2020/judged')
pt.Experiment(
  [index.bm25(), index.qld(), index.tfidf()],
  dataset.get_topics(),
  dataset.get_qrels(),
  [nDCG@10, nDCG, RR(rel=2), MAP(rel=2), R(rel=2)@1000],
  ['BM25', 'QLD', 'TF-IDF'],
  round=4,
)
```
</details>

|    | name   |   nDCG@10 |   nDCG |   RR(rel=2) |   AP(rel=2) |   R(rel=2)@1000 |
|---:|:-------|----------:|-------:|------------:|------------:|----------------:|
|  0 | BM25   |    0.4769 | 0.5832 |      0.672  |      0.2827 |          0.7865 |
|  1 | QLD    |    0.4584 | 0.5872 |      0.6238 |      0.2811 |          0.8179 |
|  2 | TF-IDF |    0.4029 | 0.5039 |      0.5526 |      0.2107 |          0.7323 |

**MS MARCO Dev (small)**

<details>
  <summary>Code</summary>

```python
from ir_measures import RR, R
import pyterrier as pt
from pyterrier_anserini import AnseriniIndex
index = AnseriniIndex.from_hf('macavaney/msmarco-passage.anserini')
dataset = pt.get_dataset('irds:msmarco-passage/dev/small')
pt.Experiment(
  [index.bm25(), index.qld(), index.tfidf()],
  dataset.get_topics(),
  dataset.get_qrels(),
  [RR@10, R@1000],
  ['BM25', 'QLD', 'TF-IDF'],
  round=4,
)
```
</details>

|    | name   |   RR@10 |   R@1000 |
|---:|:-------|--------:|---------:|
|  0 | BM25   |  0.1844 |   0.8567 |
|  1 | QLD    |  0.1664 |   0.8508 |
|  2 | TF-IDF |  0.1368 |   0.8288 |

## Reproduction

```python
>>> import pyterrier as pt
>>> import pyterrier_anserini
>>> idx = pyterrier_anserini.AnseriniIndex('msmarco-passage.anserini')
>>> idx.indexer().index(pt.get_dataset('irds:msmarco-passage').get_corpus_iter())
```

## Metadata

```
{
  "type": "sparse_index",
  "format": "anserini",
  "package_hint": "pyterrier-anserini"
}
```
