Skip to content

NishchalMN/HyDE-Generative-Query-Expansion-Engine

Repository files navigation

Generative Query Expansion Engine (HyDE)

This project implements and evaluates Hypothetical Document Embeddings (HyDE) for question answering retrieval. HyDE generates hypothetical answer documents from queries using a language model, then uses these embeddings to retrieve relevant passages.

We compare HyDE against two baselines:

  • BM25 — Traditional sparse retrieval
  • Dense Retrieval — Direct query embedding with sentence-transformers

📄 Full Report (PDF)

Project Structure

├── main.py                  # Pipeline orchestration
├── config.py                # Runtime configuration
├── data_loader.py           # Dataset loading (MS MARCO, Natural Questions)
├── download_model.py        # Pre-download HuggingFace models
├── streamlit_app.py         # Interactive Streamlit demo
├── visualize_results.py     # Result visualization
├── baselines/
│   ├── bm25_retriever.py    # BM25 sparse retrieval
│   └── dense_retriever.py   # Dense retrieval with sentence-transformers
├── hyde/
│   └── hyde_retriever.py    # HyDE implementation
├── evaluation/
│   └── evaluator.py         # MRR, Recall@K, NDCG@K metrics
├── analysis/
│   └── error_analysis.py    # Error classification and case studies
├── experiments/
│   └── ablation_studies.py  # Ablation studies for HyDE parameters
├── figures/                 # Result visualizations
├── report/                  # LaTeX source and PDF report
└── results/                 # Evaluation outputs (CSV, JSON)

Setup

pip install -r requirements.txt

# Pre-download HuggingFace models (recommended)
python download_model.py

Usage

Run full evaluation:

python main.py

This runs data loading, indexing, retrieval, evaluation, and ablation studies. Results are saved to results/<timestamp>/.

Interactive demo:

streamlit run streamlit_app.py

Configuration

Edit config.py to adjust:

  • HYDE_GENERATION_MODEL — model for generation (default: Mistral-7B-Instruct)
  • EMBEDDING_MODEL — sentence transformer model
  • MAX_DOCUMENTS, MAX_QUERIES — dataset size
  • HYDE_TEMPERATURE, HYDE_MAX_TOKENS — generation parameters

Requirements

  • Python 3.8+
  • PyTorch with CUDA recommended
  • ~16GB GPU memory for Mistral-7B

Authors

Nishchal Marur & Yog Dharaskar

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors