Views
No views yet
agentic_rag_poisoning/
├── data/
│ ├── raw_pdfs/ ← source PDFs (generated by generate_pdfs.py)
│ └── faiss_index/ ← saved vector store (auto-created)
├── src/
│ ├── __init__.py
│ ├── ingestion.py ← Phase 1 & 2: PDF → chunks → embeddings → FAISS
│ ├── rag_pipeline.py ← Phase 3: retrieval + Ollama LLM generation
│ ├── agent_monitor.py ← Phase 4: autonomous validation & refinement
│ ├── poisoning.py ← Phase 5: 4 attack strategies
│ └── evaluation.py ← Phase 6: RAGAS metrics comparison
├── results/
│ └── evaluation_report.json ← auto-generated after evaluation
├── generate_pdfs.py ← creates the 3 sample PDFs
├── main.py ← unified pipeline runner
├── requirements.txt
├── .env
└── README.mdpython --versionPython 3.11.xollama --version1mkdir C:\Projects\agentic_rag_poisoning
2cd C:\Projects\agentic_rag_poisoningcode C:\Projects\agentic_rag_poisoningagentic_rag_poisoningpython -m venv venvvenv\Scripts\activatesource venv/bin/activate(venv) at the start of your terminal prompt.Ctrl+Shift+P → type "Python: Select Interpreter".\venv\Scripts\python.exe1pip install --upgrade pip
2pip install -r requirements.txtThis installs ~1.5 GB of packages. Takes 5–15 minutes depending on internet speed.
pip install torch --index-url https://download.pytorch.org/whl/cpuollama pull mistralDownloads ~4 GB. This is the Mistral 7B model. Takes 5–20 minutes.
ollama serveollama run mistral "Hello, are you working?"python generate_pdfs.pyCreated: data/raw_pdfs/machine_learning_intro.pdf
Created: data/raw_pdfs/rag_systems_guide.pdf
Created: data/raw_pdfs/data_poisoning_attacks.pdf
All 3 PDFs generated successfully in data/raw_pdfs/python src/ingestion.pyLoading PDFs from 'data/raw_pdfs'...
✓ machine_learning_intro.pdf (5 pages)
✓ rag_systems_guide.pdf (4 pages)
✓ data_poisoning_attacks.pdf (4 pages)
Chunking complete: 13 pages → ~80 chunks
Loading embedding model: sentence-transformers/all-MiniLM-L6-v2
(First run downloads ~90 MB — subsequent runs use cache)
Building FAISS index from 80 chunks...
✓ Vector store saved to 'data/faiss_index'python src/rag_pipeline.pypython src/agent_monitor.pypython src/poisoning.pypython src/evaluation.py══════════════════════════════════════════════════════════════
Evaluation: Clean RAG vs Poisoned RAG [Label Flipping]
══════════════════════════════════════════════════════════════
Metric Clean Poisoned Drop
──────────────────────────────────────────────────────
faithfulness 0.842 0.531 ▼ 0.311
answer_relevancy 0.791 0.624 ▼ 0.167
context_recall 0.768 0.592 ▼ 0.176
context_precision 0.803 0.641 ▼ 0.162
══════════════════════════════════════════════════════════════results/evaluation_report.json.python main.py1python main.py --phase ingestion
2python main.py --phase rag
3python main.py --phase agent
4python main.py --phase poison
5python main.py --phase eval
6python main.py --rebuild # force rebuild vector storedata/raw_pdfs/python src/ingestion.py (force rebuild)run_ingestion(force_rebuild=True)| Error | Fix |
|---|---|
ollama: connection refused | Run ollama serve in a separate CMD window |
ModuleNotFoundError | Activate venv: venv\Scripts\activate |
torch not found | pip install torch --index-url https://download.pytorch.org/whl/cpu |
No PDF files found | Run python generate_pdfs.py first |
FAISS index not found | Run python src/ingestion.py first |
out of memory | Reduce CHUNK_SIZE in ingestion.py to 256 |
| Component | Tool | Version |
|---|---|---|
| LLM | Mistral 7B via Ollama | 0.3.x |
| Embeddings | all-MiniLM-L6-v2 | sentence-transformers 3.x |
| Vector DB | FAISS (CPU) | faiss-cpu 1.9 |
| RAG Framework | LangChain | 0.3.7 |
| PDF Loading | PyMuPDF | 1.24 |
| Evaluation | RAGAS | 0.2.5 |
| PDF Generation | ReportLab | 4.2 |