Skip to content

ISE-Lab-AI4LIFE/GASLITE-lite

 
 

Repository files navigation

GASLITEing the Retrieval - Reproduction

This official repository of the paper "GASLITEing the Retrieval: Exploring Vulnerabilities in Dense Embedding-based Search", allowing reproduction of experiments and the presented ablation studies presented. The repository contains code for attacking retrieval models via crafting of passages (with GASLITE method) to poison the used retrieval corpus, and evaluating these attacks.

fig1.png

ℹ️ Currently the repo is meant for reproduction of the attack and evaluation in the original work. We intend to continue to develop this attack and to make a useful framework for retrieval attacks in this repo.

Demo Notebook

For a quick demonstration of the attack, see the demo notebook, or run it in Colab, showcasing the attack on concept-specific queries with a single adversarial passage.

Setup

The project requires Python 3.8.5 and on and the installation of pip install -r requirements.txt (preferably in an isolated env: conda create -n gaslite-env python=3.8.5).

  • For recording metrics to wandb, you may need to login to wandb.
  • When cloning the project make sure to load included submodules, e.g. by: git clone --recurse-submodules. For details on dependencies see Dependencies section.

Usage (Attack)

Run the attack script (on of the following) to craft adversarial passage(s). Results will be saved to a JSON file in ./results/.

For further modifying the attack parameters, refer to the configuration files in (./config/) and use Hydra's CLI override syntax.

Usage (Evaluation)

Evaluation with covering.py's API: This module can be used to evaluate retrieval corpus poisoning attacks (such as GASLITE). In particular, the method evaluate_retrieval(..), which given with a set of adversarial passages, evaluates the poisoning attack on a retrieval model with common measures (including visibility of these passages in the top-10 retrieved passages) w.r.t. the targeted queries.

Additional Usage

  • Cache Retrieval Results with cache-retrieval.sh. This script caches the similarities of a model on a dataset (to a json, ./data/cached_evals/). It is a prerequisite for the following steps, to not repeat on this heavy logic per attack evaluation. For models evaluated in the paper this caching was uploaded to HuggingFace, so it is not required. Script can be used with any BEIR-supported dataset and SentenceTransformer embedding model.
  • Cache Query Partitions with cache-q-partitions.sh. This script caches the partition of queries, using a specified method that defaults to k-means. Resulted parition is saved into a JSON, ./data/cached_clustering/. These partitions can be used for exploration, to simulate the perfect attack, or to run a multi-budget attack.

Dependencies

This project utilizes the following projects:

  • retrieval-datasets-similarities: cached similarities of various retrieval datasets and models, downloaded and used within the project for evaluating the attack (to avoid recalculating these per attack run).
  • GPT2 on BERT's tokenizer: a nanoGPT fork and weight that uses BERT's tokenizer (instead of GPT2's); used for crafting fluent adversarial passages.

Acknowledgements

Some code snippets are loosely inspired by the following codebases:

Citation

If you find this work useful, please cite our paper as follows:

@article{bentov2024gasliteingretrievalexploringvulnerabilities,
     title={{GASLITE}ing the {R}etrieval: {E}xploring {V}ulnerabilities in {D}ense {E}mbedding-based {S}earch}, 
     author={Matan Ben-Tov and Mahmood Sharif},
     year={2024},
     eprint={2412.20953},
     archivePrefix={arXiv},
     primaryClass={cs.CR},
     url={https://arxiv.org/abs/2412.20953}, 
} 

About

SEO attack on dense embedding-based retrieval via poisoning. Forked for optimization purpose.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 68.9%
  • Jupyter Notebook 28.8%
  • Shell 2.3%