Skip to main content

Trove

A Flexible Toolkit for Dense Retrieval


Trove Logo


Trove is a lightweight toolkit for training and evaluating transformer-based dense retrievers. It aims to keep the codebase simple and hackable, while offering a clean, unified interface for quickly experimenting with new ideas.

Key features:

  • Well-documented and easy-to-understand codebase
  • Simple, modular design that's easy to extend and integrate into different workflows
  • Minimal, consistent interface for evaluation and hard negative mining
  • Built to work seamlessly with the Hugging Face ecosystem (e.g., PEFT methods, distributed training/inference)
  • Effortless manipulation and combination of multiple datasets on-the-fly

🎓 Documentation

📚 Examples

⭐ Check out our recent paper (and code) to see how Trove's data manipulation capabilities enable us to train retrievers with synthetic multi-level ranking contexts.

Quick Tour

Install Trove from PyPI:

pip install ir-trove

To get the latest changes, install from source:

pip install git+https://github.com/BatsResearch/trove

Training

Documentation

Train with binary labels:

from transformers import AutoTokenizer, HfArgumentParser
from trove import *

parser = HfArgumentParser((RetrievalTrainingArguments, ModelArguments, DataArguments))
train_args, model_args, data_args = parser.parse_args_into_dataclasses()

tokenizer = AutoTokenizer.from_pretrained(model_args.model_name_or_path)
model = BiEncoderRetriever.from_model_args(args=model_args)

pos = MaterializedQRelConfig(min_score=1, qrel_path="train_qrel.tsv", corpus_path="corpus.jsonl", query_path="queries.jsonl")
neg = MaterializedQRelConfig(max_score=1, qrel_path="train_qrel.tsv", corpus_path="corpus.jsonl", query_path="queries.jsonl")
dataset = BinaryDataset(data_args=data_args, positive_configs=pos, negative_configs=neg, format_query=model.format_query, format_passage=model.format_passage)
data_collator = RetrievalCollator(data_args=data_args, tokenizer=tokenizer, append_eos=model.append_eos_token)

trainer = RetrievalTrainer(args=train_args, model=model, tokenizer=tokenizer, data_collator=data_collator, train_dataset=dataset)
trainer.train()

To train with graduated relevance labels (e.g., {0, 1, 2, 3}), you just need to change a few lines:

...
conf = MaterializedQRelConfig(qrel_path="train_qrel.tsv", corpus_path="corpus.jsonl", query_path="queries.jsonl")
dataset = MultiLevelDataset(data_args=data_args, qrel_config=conf, format_query=model.format_query, format_passage=model.format_passage)
...

Data Manipulation

Documentation

Manipulate and combine multiple data sources with just a few lines of code. The following snippet combines a multi-level synthetic dataset (with labels {0, 1, 2, 3}) with real annotated positives and two mined hard negatives per query. Before merging, it also reassigns the label values: real positives are labeled 3, and mined negatives are labeled 1.

...
real_pos = MaterializedQRelConfig(min_score=1, score_transform=3, corpus_path="real_corpus.jsonl", qrel_path="qrels/train.tsv", query_path="queries.jsonl")
mined_neg = MaterializedQRelConfig(group_random_k=2, score_transform=1, corpus_path="real_corpus.jsonl", qrel_path="mined_qrel.tsv", query_path="queries.jsonl")
synth_data = MaterializedQRelConfig(corpus_path="corpus_multilevel_synth.jsonl", qrel_path="qrel_multilevel_synth.tsv", query_path="queries.jsonl")

dataset = MultiLevelDataset(qrel_config=[real_pos, mined_neg, synth_data], data_args=data_args, format_query=model.format_query, format_passage=model.format_passage)
...

Inference

Documentation

Evaluation: Calculate IR metrics

from transformers import AutoTokenizer, HfArgumentParser
from trove import *

parser = HfArgumentParser((EvaluationArguments, ModelArguments, DataArguments))
eval_args, model_args, data_args = parser.parse_args_into_dataclasses()

tokenizer = AutoTokenizer.from_pretrained(model_args.model_name_or_path)
model = BiEncoderRetriever.from_model_args(args=model_args)

conf = MaterializedQRelConfig(qrel_path="test_qrel.tsv", corpus_path="corpus.jsonl", query_path="queries.jsonl")
dataset = MultiLevelDataset(data_args=data_args, qrel_config=conf, format_query=model.format_query, format_passage=model.format_passage)
data_collator = RetrievalCollator(data_args=data_args, tokenizer=tokenizer, append_eos=model.append_eos_token)

evaluator = RetrievalEvaluator(args=eval_args, model=model, tokenizer=tokenizer, data_collator=data_collator, eval_dataset=dataset)
evaluator.evaluate()

Hard Negative Mining: With very minor changes, you can use the above snippet to mine hard negatives for the given queries. You only need to change the last line:

...
evaluator.mine_hard_negatives()
...

Distributed Environments

Trove supports both training and inference in multi-gpu and multi-node environments. You just need to run your scripts with a distributed launcher.

accelerate launch --multi_gpu {train.py or eval.py} {script arguments}

You can also use deepspeed for training. Since Trove wraps around and is fully compatible with huggingface transformers, you just need to pass your deepspeed config file as a command line argument. See huggingface transformers documentation for more details.

Citation

If you use this software, please cite us.

@misc{esfandiarpoortrove,
  author = {Reza Esfandiarpoor and Stephen H. Bach},
  title = {Trove: A Flexible Toolkit for Dense Retrieval},
  year = {2025},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/BatsResearch/trove}}
}

Acknowledgment

Some of the high-level design choices are inspired by Tevatron library. Trove also adapts some implementation details of Tevatron. Some data manipulations are inspired by ideas in Huggingface datasets source code.

This material is based upon work supported by the National Science Foundation under Grant No. RISE-2425380. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation. Disclosure: Stephen Bach is an advisor to Snorkel AI, a company that provides software and services for data-centric artificial intelligence.

Metadata

Release files for ir-trove 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ir-trove 0.0.2
File Size Uploaded
ir_trove-0.0.2.tar.gz 123.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ir-trove 0.0.2
File Interpreter ABI Platform
ir_trove-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 277.6 kB

Release files / ir_trove-0.0.2.tar.gz

Download URL ir_trove-0.0.2.tar.gz
Size 123.6 kB
Tags Source
SHA-256 checksum
How to use checksums
68d180fe4cf38a2274f99f3d3f7c9cfcb9361a05c0e5f9e7446ec26863fc5b12
BLAKE2b-256 checksum
How to use checksums
651a14bb30b9239b58da38f07b6e587a6c77ffc26eda86b0a139758b690bdcc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 29, 2025.

Transparency log

Release files / ir_trove-0.0.2-py3-none-any.whl

Download URL ir_trove-0.0.2-py3-none-any.whl
Size 153.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3bfa526a3124a328eb0bf7113b6dc9526e11e7dc068931bd75fae2736c7bb01b
BLAKE2b-256 checksum
How to use checksums
95aa90cdde1b2a0d9e3d265ca204b85d1599fd3f0e9164a5e0a7d91fb8898c78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 29, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page