embeddings-guardian
Open-source RAG poisoning detection. OWASP LLM08:2025 reference implementation.
What is RAG Poisoning?
Retrieval-Augmented Generation (RAG) systems retrieve documents from a vector database and feed them into an LLM as context. RAG poisoning is an attack where adversarial documents are injected into the vector store with crafted embeddings designed to:
- Appear relevant to targeted queries (high cosine similarity)
- Contain malicious, misleading, or policy-violating content
- Hijack the LLM's output for specific topics
Research from Zou et al. (PoisonedRAG, 2024) demonstrated 97--99% attack success rates against production RAG systems, with poisoned documents retrieved in the top-k results for targeted queries. The attack requires injecting as few as 5 documents into a corpus of thousands.
This is tracked as OWASP LLM08:2025 -- Vector and Embedding Weaknesses.
Why It Matters
- 97--99% attack success rate in academic evaluations
- 5 poisoned documents can compromise a corpus of 10,000+
- No built-in defenses in ChromaDB, Pinecone, Weaviate, or any major vector DB
- Compliance risk for healthcare, finance, and regulated industries
- Silent failure -- poisoned results look normal to end users
Quick Start (2 Minutes)
pip install embeddings-guardian
from embeddings_guardian import PoisoningDetector
# Initialize detector
detector = PoisoningDetector(algorithm="magnitude", sensitivity=0.95)
# Build baseline from your existing (trusted) embeddings
for embedding in your_corpus_embeddings:
detector.update_baseline(embedding)
# Check new embeddings before inserting
is_poisoned, confidence, reason = detector.is_poisoned(new_embedding)
if is_poisoned:
print(f"BLOCKED: {reason} (confidence: {confidence:.0%})")
else:
# Safe to insert into your vector store
collection.add(embedding=new_embedding)
Installation
Core only (numpy + scikit-learn):
pip install embeddings-guardian
With a specific backend:
pip install embeddings-guardian[chromadb]
pip install embeddings-guardian[pinecone]
pip install embeddings-guardian[weaviate]
pip install embeddings-guardian[qdrant]
pip install embeddings-guardian[milvus]
pip install embeddings-guardian[pgvector]
pip install embeddings-guardian[faiss]
All backends:
pip install embeddings-guardian[all]
Backend Integration
Use an adapter to get automatic pre-insert screening:
import chromadb
from embeddings_guardian import PoisoningDetector
from embeddings_guardian.backends import ChromaDBAdapter
client = chromadb.Client()
collection = client.get_or_create_collection("documents")
detector = PoisoningDetector(algorithm="magnitude", sensitivity=0.95)
adapter = ChromaDBAdapter(collection=collection, detector=detector)
# Calibrate from existing data
baseline = adapter.get_baseline_embeddings(sample_size=1000)
detector.update_baseline_batch(baseline)
# Upsert with automatic screening
adapter.upsert_embeddings(
ids=["doc_1", "doc_2"],
embeddings=vectors,
metadata=[{"source": "trusted"}, {"source": "trusted"}],
)
Detection Algorithms
| Algorithm | Speed | Best For | How It Works |
|---|---|---|---|
| magnitude | <0.5ms | Real-time screening | L2 norm z-score analysis |
| centroid | ~1ms | Semantic outliers | Cosine distance to cluster centroids |
| neighborhood | 5--10ms | Sophisticated attacks | k-NN density analysis |
| dimension | <0.5ms | Secondary checks | Per-dimension z-score |
| ensemble | varies | Maximum accuracy | Weighted combination of algorithms |
Detection Modes
| Mode | Behavior |
|---|---|
warn |
Log the detection, insert anyway |
quarantine |
Flag in metadata, exclude from queries |
strict |
Reject the embedding outright |
Supported Vector Stores
| Store | Status | Install |
|---|---|---|
| ChromaDB | Full | [chromadb] |
| Pinecone | Full | [pinecone] |
| Weaviate | Full | [weaviate] |
| Qdrant | Full | [qdrant] |
| Milvus | Full | [milvus] |
| pgvector | Full | [pgvector] |
| FAISS | Testing/Research | [faiss] |
Documentation
- Getting Started -- per-backend setup and configuration
- Backends Guide -- performance, cost, and quirks per store
- Algorithms -- detailed explanation of detection methods
- Examples -- real-world code samples
Contributing
See CONTRIBUTING.md for development setup, testing, and pull request guidelines.
License
Apache License 2.0. See LICENSE.
References
- Zou et al., "PoisonedRAG: Knowledge Corruption Attacks to Retrieval-Augmented Generation of Large Language Models," 2024
- OWASP Top 10 for LLM Applications 2025 -- LLM08: Vector and Embedding Weaknesses
- Xue et al., "BadRAG: Identifying Vulnerabilities in Retrieval Augmented Generation of Large Language Models," 2024
- Zeng et al., "RevPRAG: Reverse Prompt Engineering for RAG Poisoning Detection," 2024
Metadata
Release files for embeddings-guardian 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| embeddings_guardian-0.1.0.tar.gz | 31.2 kB | Without provenance | Details for embeddings_guardian-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| embeddings_guardian-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for embeddings_guardian-0.1.0-py3-none-any.whl |
Total release size: 64.3 kB
Release files / embeddings_guardian-0.1.0.tar.gz
| Download URL | embeddings_guardian-0.1.0.tar.gz |
|---|---|
| Size | 31.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02c580be3c4c88957bf6b66e127677be582fe10d5e04cfab4238db38da9200b9
|
|
BLAKE2b-256 checksum How to use checksums |
fc1579653978dee1320566bbb13168d53edc05abfc15a9cbda68738518629c4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / embeddings_guardian-0.1.0-py3-none-any.whl
| Download URL | embeddings_guardian-0.1.0-py3-none-any.whl |
|---|---|
| Size | 33.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fff7341b6ad571cbf9a71df05fdc84902ae8c90d8cea0be52dbc099375a62a1e
|
|
BLAKE2b-256 checksum How to use checksums |
02636deb421952923914acd4b48c902c4fe6b7fd1b4a5e54d2034930ba485d25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for embeddings-guardian 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.