This repository contains the code for our paper: "On the Robustness of LLM-Based Dense Retrievers: A Systematic Analysis of Generalizability and Stability".
We use this codebase to evaluate the robustness of state-of-the-art (SOTA) open-source LLM-based dense retrievers.
We are cleaning our code and will publish it as soon as possible.
The datasets used in the experiments are from the Extended Beir Datasets code repository. The datasets are stored in the datasets/ folder. These datasets will download automatically when you run the code.
You can set up the environment using either conda or pip.
environment.ymlrequirements.txtWe recommend using pip for installation. In addition to common deep learning and NLP libraries such as PyTorch and Transformers, this project requires the following dependencies:
# Using pip (recommended)
pip install -r requirements.txt
# Using conda
conda env create -f environment.yml
conda activate <env_name>
For statistical analysis (e.g., Linear Mixed Models), R language support is required via rpy2:
conda install conda-forge::rpy2
Run evaluation on all models and datasets:
bash scripts/eval.sh
This script evaluates all models on all datasets at the query level. Embeddings are saved to ./embeddings/clean/, and query-level results are stored in the output/ folder. This produces the data for Table 7.
Classify queries by type:
python nf_cats_all_datasets.py
This script classifies all queries across datasets. The classification results are saved to data/nf_cats_all_datasets.csv. It then combines query categories with the scores from Step 1 to generate data/nf_cats_all_datasets_with_scores.csv.
Prepare data for LMM analysis:
Run all cells in nf_cats_all_datasets_scores_analysis and LMM data preprocess.ipynb to prepare data for Linear Mixed Model (LMM) analysis. This produces the data for Table 8 and generates data/df_long_all_model_scores.csv.
Run LMM and ANOVA analysis:
python LMM_ANOVA_Analysis_R.py
This script performs LMM analysis and produces the data for Table 1 and Table 2.
Generate query variations:
bash scripts/augment_query_variation_text.sh
Query variations are saved to output_attack/attacked_text/query/.
Evaluate query variations:
bash scripts/eval_attack_query.sh
Generate adversarial documents (corpus poisoning):
Use the HotFlip Corpus Poisoning repository to generate adversarial documents for all LLM-based retrievers. Place the generated documents in output_attack/attacked_text/document/.
Evaluate corpus poisoning:
bash scripts/eval_attack_document.sh
Generate statistics and figures:
python eval_attack_data_statistics.py
This produces Figure 1 and Table 3 for RQ2.
Generate embedding analysis figures:
python draw_isoscore.py
model_embedding_isoscore_and_avg_cosine_and_query_variations() to generate Figure 2model_embedding_isoscore_and_avg_cosine_and_asr_20_horizontal() to generate Figure 3Compute average cosine similarity:
The average cosine similarity for each model on each dataset is computed in draw_cosine.py (lines 67-128). Results are saved to data/average_cosine_similarity_data_100k.json.
Compute IsoScore:
The IsoScore for each model on each dataset is computed using the IsoScore_numpy function in draw_isoscore.py. Results are saved to data/isoscore_data_100k.json.
Compute spectral norm:
python draw_spectral_norm.py
This computes the average spectral norm for each model.
17 commits
Python
69.9%
Jupyter Notebook
28.6%
Shell
1.4%
This repository contains the code for our paper: "On the Robustness of LLM-Based Dense Retrievers: A Systematic Analysis of Generalizability and Stability".
We use this codebase to evaluate the robustness of state-of-the-art (SOTA) open-source LLM-based dense retrievers.
We are cleaning our code and will publish it as soon as possible.
The datasets used in the experiments are from the Extended Beir Datasets code repository. The datasets are stored in the datasets/ folder. These datasets will download automatically when you run the code.
You can set up the environment using either conda or pip.
environment.ymlrequirements.txtWe recommend using pip for installation. In addition to common deep learning and NLP libraries such as PyTorch and Transformers, this project requires the following dependencies:
# Using pip (recommended)
pip install -r requirements.txt
# Using conda
conda env create -f environment.yml
conda activate <env_name>
For statistical analysis (e.g., Linear Mixed Models), R language support is required via rpy2:
conda install conda-forge::rpy2
Run evaluation on all models and datasets:
bash scripts/eval.sh
This script evaluates all models on all datasets at the query level. Embeddings are saved to ./embeddings/clean/, and query-level results are stored in the output/ folder. This produces the data for Table 7.
Classify queries by type:
python nf_cats_all_datasets.py
This script classifies all queries across datasets. The classification results are saved to data/nf_cats_all_datasets.csv. It then combines query categories with the scores from Step 1 to generate data/nf_cats_all_datasets_with_scores.csv.
Prepare data for LMM analysis:
Run all cells in nf_cats_all_datasets_scores_analysis and LMM data preprocess.ipynb to prepare data for Linear Mixed Model (LMM) analysis. This produces the data for Table 8 and generates data/df_long_all_model_scores.csv.
Run LMM and ANOVA analysis:
python LMM_ANOVA_Analysis_R.py
This script performs LMM analysis and produces the data for Table 1 and Table 2.
Generate query variations:
bash scripts/augment_query_variation_text.sh
Query variations are saved to output_attack/attacked_text/query/.
Evaluate query variations:
bash scripts/eval_attack_query.sh
Generate adversarial documents (corpus poisoning):
Use the HotFlip Corpus Poisoning repository to generate adversarial documents for all LLM-based retrievers. Place the generated documents in output_attack/attacked_text/document/.
Evaluate corpus poisoning:
bash scripts/eval_attack_document.sh
Generate statistics and figures:
python eval_attack_data_statistics.py
This produces Figure 1 and Table 3 for RQ2.
Generate embedding analysis figures:
python draw_isoscore.py
model_embedding_isoscore_and_avg_cosine_and_query_variations() to generate Figure 2model_embedding_isoscore_and_avg_cosine_and_asr_20_horizontal() to generate Figure 3Compute average cosine similarity:
The average cosine similarity for each model on each dataset is computed in draw_cosine.py (lines 67-128). Results are saved to data/average_cosine_similarity_data_100k.json.
Compute IsoScore:
The IsoScore for each model on each dataset is computed using the IsoScore_numpy function in draw_isoscore.py. Results are saved to data/isoscore_data_100k.json.
Compute spectral norm:
python draw_spectral_norm.py
This computes the average spectral norm for each model.
17 commits
Python
69.9%
Jupyter Notebook
28.6%
Shell
1.4%