A simple pipeline to chunk text, generate embeddings, and perform semantic search using faiss for fast retrieval.
Create a malicious .txt file and inject it into the vectordb to poison the knowledge and the RAG App.
| Base RAG Response | Data Poison Attack: RAG Response |
|---|---|
![]() |
![]() |
-
clone the repository
git clone https://github.com/dhruvXcode247/Data-Poisoning-Attack-On-LLM-RAG.git cd Data-Poisoning-Attack-on-LLM-RAG -
create a virtual environment (optional)
python -m venv venv source venv/bin/activate # windows: venv\Scripts\activate
-
install dependencies
pip install -r requirements.txt
-
Get Text Files:
Run create_dataset.ipynb to create a dataset from scratch.export GROQ_API_KEY="<groq-api-key>"
-
Create VectorDB:
Run create_vectorstore.ipynb to generate the HuggingFace Embeddings (intfloat/multilingual-e5-small) and store in FAISS Vector Store. -
Poison Data Injection:
Run poison_data.py script which addsmalicious payloadto single .txt file, and creates relevant vector stores for retreival.python poison_data.py
-
Run Streamlit App
Run the app.py python script.streamlit start app.py
- load and process
.txtfiles from a directory - use
HuggingFaceembeddings for vector representation - store and retrieve chunks with faiss
- persistent storage with faiss index + json
- create streamlit app for user interaction
- create poisoned .txt file
- add poisoned .txt into vector store
- include vector store selection (base/poison) in streamlit app
- test data poisoning vulnerability
- LangChain
- FAISS
- Groq API
This repository implements a data poisoning attack done on a LLM-RAG application hosted on Streamlit using FAISS.

