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
├── 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)
pip install -r requirements.txt
# Pre-download HuggingFace models (recommended)
python download_model.pyRun full evaluation:
python main.pyThis runs data loading, indexing, retrieval, evaluation, and ablation studies. Results are saved to results/<timestamp>/.
Interactive demo:
streamlit run streamlit_app.pyEdit config.py to adjust:
HYDE_GENERATION_MODEL— model for generation (default: Mistral-7B-Instruct)EMBEDDING_MODEL— sentence transformer modelMAX_DOCUMENTS,MAX_QUERIES— dataset sizeHYDE_TEMPERATURE,HYDE_MAX_TOKENS— generation parameters
- Python 3.8+
- PyTorch with CUDA recommended
- ~16GB GPU memory for Mistral-7B
Nishchal Marur & Yog Dharaskar