Skip to main content

Ask DeepWiki about this repo Publish to PyPI Build and Push Docker Images PyPI version PyPI - Downloads Python 3.9+ License: Apache 2.0

QueryGym Logo

A lightweight, reproducible toolkit for LLM-based query reformulation

🌐 Website • 📊 Leaderboard • 📚 Docs • 📦 PyPI • 📄 Paper


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

For detailed usage and parameters, see the Methods Reference.

Installation

Option 1: Install from PyPI

pip install querygym
# 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

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:

Check examples/README.md for the full guide.

Contributing

We welcome contributions! Here's how you can help:

Adding a New Prompt

  1. Edit querygym/prompt_bank.yaml
  2. Add an entry with fields: id, method_family, version, introduced_by, license, authors, tags, template:{system,user}, notes

Adding a New Method

  1. Create a class under querygym/methods/*.py
  2. Subclass BaseReformulator, annotate VERSION, and register with @register_method("name")
  3. 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:

@inproceedings{10.1145/3774905.3793135,
  author    = {Bigdeli, Amin and Hamidi Rad, Radin and Incesu, Mert and Arabzadeh, Negar and Clarke, Charles and Bagheri, Ebrahim},
  title     = {QueryGym: A Toolkit for Reproducible LLM-Based Query Reformulation},
  booktitle = {Companion Proceedings of the ACM Web Conference 2026},
  series    = {WWW Companion '26},
  year      = {2026},
  pages     = {196--199},
  publisher = {Association for Computing Machinery},
  doi       = {10.1145/3774905.3793135},
  url       = {https://doi.org/10.1145/3774905.3793135}
}

Metadata

Release files for querygym 0.3.0

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

Source distribution (sdist)

Source distribution for querygym 0.3.0
File Size Uploaded
querygym-0.3.0.tar.gz 118.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for querygym 0.3.0
File Interpreter ABI Platform
querygym-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 199.4 kB

Release files / querygym-0.3.0.tar.gz

Download URL querygym-0.3.0.tar.gz
Size 118.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5161fa35898ef22be2aab9245f8081d982e7c5cffc892616131e74479e81497b
BLAKE2b-256 checksum
How to use checksums
6b2f6fb2ba3d9f838dab737b9a41009f5d81e7bb06bae9b9786af34c26d36f81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / querygym-0.3.0-py3-none-any.whl

Download URL querygym-0.3.0-py3-none-any.whl
Size 80.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d97eaece0071e41bab0edf446a060efa475f71b22b025509cd85ff1a5a2be26d
BLAKE2b-256 checksum
How to use checksums
f48aab1eea7d66819f1d01f9555fbc8715a4d2f883d34e5b95329087619c0021
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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