A lightweight, reproducible toolkit for LLM-based query reformulation
🌐 Website • 📊 Leaderboard • 📚 Docs • 📦 PyPI • 📄 Paper
📢 News
- Nov 2026: We presented the tutorial Query Expansion Revisited: From Classical Retrieval to Agentic Search at CIKM 2026 (Nov 7–11). Slides (PDF)
Features
- Single Prompt Bank (YAML) with metadata
- Simple DataLoader: Dependency-free file loading for queries, qrels, and contexts
- Format Loaders: Optional BEIR, MS MARCO, and BRIGHT format loaders in
querygym.loaders - OpenAI-compatible LLM client (works with any OpenAI API–compatible endpoint)
- Pyserini optional: either pass contexts (JSONL) or pass a retriever instance to build contexts
- Export-only: emits reformulated queries; optionally generates a bash script for Pyserini +
trec_eval
Supported Methods
QueryGym implements the following query reformulation methods:
| Method | Description | Paper |
|---|---|---|
| GenQR | Generic keyword expansion using LLM | Wang et al., 2023 |
| GenQR Ensemble | Ensemble of 10 instruction variants for diverse keyword expansion | Dhole & Agichtein, 2024 |
| Query2Doc | Generates pseudo-documents from LLM knowledge | Wang et al., 2023 |
| QA Expand | Question-answer based expansion with sub-questions | Seo et al., 2025 |
| MuGI | Multi-granularity information expansion with adaptive concatenation | Zhang et al., 2024 |
| LameR | Context-based passage synthesis using retrieved documents | Shen et al., 2023 |
| CSQE | Context-based sentence-level query expansion (KEQE + CSQE) | Lei et al., 2024 |
| ThinkQE | Multi-round reasoning-based query expansion with corpus feedback | Lei et al., 2025 |
| Query2E | Query to entity/keyword expansion | Jagerman et al., 2023 |
| ReFormeR | Pattern-based, document-conditioned reformulation via learned transformation rules | Bigdeli et al., 2026 |
| HyDE | Precise Zero-Shot Dense Retrieval without Relevance Labels | Gao et al., 2022 |
For detailed usage and parameters, see the Methods Reference.
Installation
Option 1: Install from PyPI
pip install querygym
Option 2: Use Docker (Recommended for Quick Start)
# GPU version (default)
docker pull ghcr.io/ls3-lab/querygym:latest
docker run -it --gpus all ghcr.io/ls3-lab/querygym:latest
# CPU version (lightweight)
docker pull ghcr.io/ls3-lab/querygym:cpu
docker run -it ghcr.io/ls3-lab/querygym:cpu
# Or use Docker Compose
docker compose run --rm querygym
📖 Docker Setup: See DOCKER_SETUP.md for quick start or the full Docker guide for detailed usage.
Quickstart
Python API (Recommended)
import querygym as qg
# Load data
queries = qg.load_queries("queries.tsv")
qrels = qg.load_qrels("qrels.txt")
contexts = qg.load_contexts("contexts.jsonl")
# Create reformulator
reformulator = qg.create_reformulator("genqr_ensemble", model="gpt-4")
# Reformulate
results = reformulator.reformulate_batch(queries)
# Save
qg.DataLoader.save_queries(
[qg.QueryItem(r.qid, r.reformulated) for r in results],
"reformulated.tsv"
)
CLI
pip install -e .[hf,beir,dev]
export OPENAI_API_KEY=sk-...
# Run a method (e.g., genqr_ensemble)
querygym run --method genqr_ensemble \
--queries-tsv queries.tsv \
--output-tsv reformulated.tsv
Loading Datasets
BEIR:
import querygym as qg
# Download with BEIR library
from beir.datasets.data_loader import GenericDataLoader
data_path = GenericDataLoader("nfcorpus").download_and_unzip()
# Load with querygym
queries = qg.loaders.beir.load_queries(data_path)
qrels = qg.loaders.beir.load_qrels(data_path)
MS MARCO:
import querygym as qg
# Load from local files (download with ir_datasets)
queries = qg.loaders.msmarco.load_queries("queries.tsv")
qrels = qg.loaders.msmarco.load_qrels("qrels.tsv")
BRIGHT:
import querygym as qg
from datasets import load_dataset
examples = load_dataset("xlangai/BRIGHT", "examples")["biology"]
documents = load_dataset("xlangai/BRIGHT", "documents")["biology"]
queries = qg.loaders.bright.load_queries(examples)
reasoning_queries = qg.loaders.bright.load_reasoning_queries(examples)
qrels = qg.loaders.bright.load_qrels(examples)
corpus = qg.loaders.bright.load_corpus(documents)
Examples
See the examples directory for:
- Code snippets - Quick reference examples
- Docker examples - Containerized workflows with Jupyter notebooks
- QueryGym + Pyserini - Complete retrieval pipelines
- Methods Reference - Complete guide to all query reformulation methods
Check examples/README.md for the full guide.
Contributing
We welcome contributions! Here's how you can help:
Adding a New Prompt
- Edit
querygym/prompt_bank.yaml - Add an entry with fields:
id,method_family,version,introduced_by,license,authors,tags,template:{system,user},notes
Adding a New Method
- Create a class under
querygym/methods/*.py - Subclass
BaseReformulator, annotateVERSION, and register with@register_method("name") - Pull templates via
PromptBank.render(prompt_id, query=...)
Reporting Issues
- Found a bug? Open an issue
- Have a feature request? We'd love to hear it!
For detailed development guidelines, see the Contributing Guide in our documentation.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Citation
If you use QueryGym in your research, please cite the toolkit paper:
@inproceedings{DBLP:conf/www/BigdeliRIACB26,
author={Amin Bigdeli and Radin {Hamidi Rad} and Mert Incesu and Negar Arabzadeh and Charles L. A. Clarke and Ebrahim Bagheri},
title={QueryGym: {A} Toolkit for Reproducible LLM-Based Query Reformulation},
booktitle={Companion Proceedings of the ACM Web Conference 2026, WWW Companion 2026, Dubai, United Arab Emirates, 29 June 2026 - 3 July 2026},
pages={196--199},
publisher={ACM},
year={2026},
url={https://doi.org/10.1145/3774905.3793135},
doi={10.1145/3774905.3793135},
}
If you refer to the SIGIR 2026 reproducibility results or the leaderboard, please also cite:
@inproceedings{DBLP:conf/sigir/BigdeliRLIACB26,
author={Amin Bigdeli and Radin {Hamidi Rad} and Hai Son Le and Mert Incesu and Negar Arabzadeh and Charles L. A. Clarke and Ebrahim Bagheri},
title={A Reproducibility Study of LLM-Based Query Reformulation},
booktitle={Proceedings of the 49th International {ACM} {SIGIR} Conference on Research and Development in Information Retrieval, {SIGIR} 2026, Melbourne, VIC, Australia, July 20-24, 2026},
pages={2824--2834},
publisher={ACM},
year={2026},
url={https://doi.org/10.1145/3805712.3808560},
doi={10.1145/3805712.3808560},
}
Metadata
Release files for querygym 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| querygym-0.5.1.tar.gz | 130.8 kB | Without provenance | Details for querygym-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| querygym-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for querygym-0.5.1-py3-none-any.whl |
Total release size: 215.1 kB
Release files / querygym-0.5.1.tar.gz
| Download URL | querygym-0.5.1.tar.gz |
|---|---|
| Size | 130.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b7f78dd20b548d355309f5f95506f965caaf9599f387b1af1329061c2dcfb78
|
|
BLAKE2b-256 checksum How to use checksums |
7ec7812d3438097db4670f0e5b15756df3db953b88a5d0743891af2447d12931
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / querygym-0.5.1-py3-none-any.whl
| Download URL | querygym-0.5.1-py3-none-any.whl |
|---|---|
| Size | 84.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23995518269fd37ffa3edbc69c9c41e3d6a4c4d341ebc6be848bd9cb7e0b2b5a
|
|
BLAKE2b-256 checksum How to use checksums |
e98583fb8ff76b38e8b42c69c93945459da680b5d492480328a85d17b192223e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Security for querygym 0.5.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.