LLM Embeddings Security
Vektor-Embeddings sind das Rückgrat von RAG-Systemen — ohne Security können Angreifer Embeddings manipulieren und Poisoning-Attacken durchführen. Vier Kontrollen: Injection Protection, Vector Store ACL, Poisoning Detection und Versioning.
Was ist LLM Embeddings Security? Einfach erklärt
LLM Embeddings Security ist wie ein Schutzschild für Vektor-Datenbanken: Embedding Injection Protection desinfiziert Inputs vor der Embedding-Generierung und validiert die Vektor-Dimensionen. Vector Store ACL garantiert, dass User A nur User Bs Dokumente sehen kann mit Tenant-Isolation. Embedding Poisoning Detection erkennt vergiftete Vektoren mit statistischer Analyse und Cluster-Scanning. Embedding Versioning verwaltet Modell-Upgrades mit Rollback-Fenstern. Ohne Security können Angreifer RAG-Retrieval vergiften, Mandanten-Daten leaken oder Embedding-Modelle kompromittieren.
↓ Springe zu Embeddings-Security-Kontrollen
4 Embeddings-Security-Kontrollen
Prevent embedding injection attacks where an attacker crafts input that manipulates the embedding space to trigger malicious behavior in the RAG retrieval or LLM generation.
# Moltbot embedding injection protection:
embedding_injection_protection:
enabled: true
# Input sanitisation before embedding:
input_sanitisation:
enabled: true
# Remove known adversarial patterns:
# - Unicode homographs
# - Zero-width characters
# - Invisible characters
# - Repeated patterns (for embedding flooding)
# Embedding validation:
embedding_validation:
enabled: true
# Validate embedding dimensions and ranges
expected_dimensions: 1536 # OpenAI text-embedding-3-small
expected_range: [-1.0, 1.0]
# Reject embeddings outside expected range
# Rate limiting for embedding generation:
rate_limit:
enabled: true
per_user_per_minute: 100
per_user_per_hour: 1000
# Prevent embedding flooding attacks
# Adversarial embedding detection:
adversarial_detection:
enabled: true
# Detect embeddings that are too close to known adversarial patterns
# Use cosine similarity to detect clustering attacks
threshold: 0.95 # Alert if similarity > 95%Control access to your vector store. Ensure that RAG queries only retrieve documents the user is authorised to access. Implement per-tenant or per-user vector isolation.
# Moltbot vector store access control:
vector_store_acl:
enabled: true
# Per-tenant vector isolation:
tenant_isolation:
enabled: true
# Each tenant has its own vector index or namespace
# User queries only search within their tenant's vectors
# User-level access control:
user_acl:
enabled: true
# Check user permissions before retrieving vectors
# Only return vectors the user is authorised to see
# Example: user can only access documents in their department
# Row-level security:
row_level_security:
enabled: true
# Each vector document has metadata: owner_id, department_id
# Filter results based on user's access rights
# Example: WHERE department_id = user.department_id
# Vector store authentication:
authentication:
enabled: true
# Require authentication for all vector store operations
# Use JWT tokens with user context
# Validate tokens on each queryDetect poisoned embeddings in your vector store. Attackers may inject malicious documents that, when embedded, cluster near legitimate documents and influence RAG retrieval.
# Moltbot embedding poisoning detection:
poisoning_detection:
enabled: true
# Outlier detection:
outlier_detection:
enabled: true
# Detect vectors that are outliers in the embedding space
# Use statistical methods: Z-score, isolation forest
# Flag vectors with high outlier score for review
# Cluster analysis:
cluster_analysis:
enabled: true
# Analyse vector clusters for unusual patterns
# Look for: small clusters with many similar vectors (potential poisoning)
# Look for vectors that bridge unrelated clusters (potential poisoning)
# Semantic drift detection:
semantic_drift:
enabled: true
# Detect if document embeddings drift from their original semantic meaning
# Re-embed documents periodically and compare
# Alert if semantic similarity drops below threshold
# Source validation:
source_validation:
enabled: true
# Only accept embeddings from trusted sources
# Reject embeddings from untrusted or unknown sources
# Maintain a whitelist of approved embedding sourcesManage embedding model updates. When you upgrade to a new embedding model, re-embed your corpus and maintain version control for backward compatibility.
# Moltbot embedding versioning:
embedding_versioning:
enabled: true
current_version: "text-embedding-3-small-v2"
previous_versions: ["text-embedding-3-small-v1", "text-embedding-ada-002"]
# Embedding model configuration:
models:
text-embedding-3-small-v2:
dimensions: 1536
provider: "openai"
deployment_date: "2025-03-01"
# Migration strategy:
migration:
enabled: true
# When upgrading to a new model:
# 1. Create new vector index for new model
# 2. Re-embed all documents with new model
# 3. Validate new embeddings (semantic drift check)
# 4. Switch traffic to new index
# 5. Keep old index for rollback window (30 days)
# Backward compatibility:
backward_compatibility:
enabled: true
# Support querying across multiple embedding versions
# Map queries to appropriate index based on model version
# Fallback to previous version if new version unavailableHäufige Fragen
What is embedding injection and how does it work?
Embedding injection is an attack where an attacker crafts input that, when embedded, produces a vector that is intentionally close to target vectors in the embedding space. This can be used to: 1) Poison RAG retrieval — attacker's input retrieves malicious documents instead of legitimate ones. 2) Bias LLM generation — attacker's input influences the LLM toward malicious outputs. 3) Evade content filters — attacker's input produces an embedding that bypasses safety filters. How it works: the attacker studies the embedding space of your RAG system, identifies target vectors (e.g., vectors for sensitive documents), then crafts input that produces embeddings close to those targets. Defense: input sanitisation, embedding validation, adversarial embedding detection, rate limiting to prevent embedding flooding.
How do I implement per-tenant vector isolation?
Per-tenant vector isolation ensures that each tenant's RAG queries only retrieve their own documents. Implementation: 1) Separate vector indices — create one index per tenant in your vector store (Pinecone, Weaviate, Milvus). 2) Namespace isolation — use vector store namespaces to segregate tenant data (e.g., tenant_id as namespace). 3) Metadata filtering — tag each vector with tenant_id and filter queries by tenant_id. 4) Application-level filtering — enforce tenant isolation at the application layer before querying the vector store. 5) Access control checks — validate user's tenant membership before allowing RAG queries. Risk: if isolation fails, one tenant can retrieve another tenant's documents — a data breach under GDPR.
How do I detect poisoned embeddings in my vector store?
Poisoned embeddings are maliciously crafted vectors that cluster near legitimate vectors to influence RAG retrieval. Detection methods: 1) Outlier detection — use statistical methods (Z-score, isolation forest) to identify vectors that are statistical outliers. 2) Cluster analysis — analyse vector clusters for unusual patterns: small clusters with many similar vectors (potential poisoning), vectors that bridge unrelated clusters. 3) Semantic drift detection — re-embed documents periodically and compare new embeddings to old ones; alert if semantic similarity drops. 4) Source validation — only accept embeddings from trusted sources; maintain a whitelist of approved embedding sources. 5) Manual review — flag suspicious vectors for manual review by security analysts.
How do I handle embedding model upgrades?
Embedding model upgrades require careful planning to avoid breaking RAG functionality. Strategy: 1) Create new vector index — create a new index for the new embedding model, don't overwrite the existing one. 2) Re-embed corpus — re-embed all documents with the new model. 3) Validate embeddings — run semantic drift checks to ensure new embeddings preserve semantic meaning. 4) Canary deployment — switch a small percentage of traffic to the new index, monitor for issues. 5) Full rollout — if canary is successful, switch all traffic to the new index. 6) Rollback window — keep the old index for 30 days in case rollback is needed. 7) Backward compatibility — support querying across multiple embedding versions if needed for gradual migration.