12 KiB
AIMDS Documentation
Comprehensive documentation for the AI Manipulation Defense System (AIMDS) - Production-ready adversarial defense for AI applications.
Part of the AIMDS platform by rUv.
📚 Documentation Index
Getting Started
- Quick Start Guide - Get up and running in 5 minutes
- Installation Guide - Rust and TypeScript setup
- Architecture Overview - System design and components
- Configuration - Environment and programmatic config
Core Concepts
Detection Layer
- Threat Detection - Pattern matching, PII sanitization (<10ms)
- Prompt Injection Patterns - 50+ attack signatures
- Performance Benchmarks - Validated metrics and targets
Analysis Layer
- Behavioral Analysis - Temporal pattern analysis (<100ms)
- Formal Verification - LTL policy checking (<500ms)
- Anomaly Detection - Statistical baseline learning
Response Layer
- Adaptive Mitigation - Strategy selection (<50ms)
- Meta-Learning - 25-level recursive optimization
- Rollback Management - Automatic undo
API Reference
Rust APIs
-
aimds-core - Core types and configuration
- Type system documentation
- Configuration options
- Error handling patterns
-
aimds-detection - Detection service API
DetectionService::new()detect(),detect_batch()- Pattern matching and sanitization
-
aimds-analysis - Analysis engine API
AnalysisEngine::new()analyze(),train_baseline()- Policy verification
-
aimds-response - Response system API
ResponseSystem::new()mitigate(),rollback_last()- Meta-learning integration
TypeScript API Gateway
- Gateway Server - REST API endpoints
/api/v1/defend- Single request defense/api/v1/defend/batch- Batch processing/api/v1/stats- Statistics endpoint/metrics- Prometheus metrics
Integration Guides
- TypeScript Integration - Gateway integration with Rust
- AgentDB Integration - Vector database setup (150x faster)
- lean-agentic Integration - Formal verification setup
- Midstream Platform - Temporal analysis crates
Deployment
- Docker Deployment - Container orchestration
- Kubernetes - K8s manifests and Helm charts
- Configuration Management - Environment-specific configs
- Monitoring Setup - Prometheus and logging
Performance & Optimization
- Performance Report - Validated benchmarks
- Optimization Guide - Tuning recommendations
- Benchmarking - Criterion benchmarks
- Test Results - Integration test outcomes
Security
- Security Audit - Security analysis
- Threat Models - Attack patterns
- Policy Examples - LTL policies
- Audit Logging - Compliance trails
Examples
- Basic Usage - Simple detection example
- Advanced Pipeline - Full detection-analysis-response
- Batch Processing - High-throughput scenarios
- Custom Policies - LTL policy creation
🎯 Use Case Guides
LLM API Gateway
Protect ChatGPT-style APIs from prompt injection:
use aimds_core::{Config, PromptInput};
use aimds_detection::DetectionService;
use aimds_analysis::AnalysisEngine;
let detector = DetectionService::new(Config::default()).await?;
let analyzer = AnalysisEngine::new(Config::default()).await?;
// Fast path: <10ms detection
let detection = detector.detect(&user_input).await?;
if detection.is_threat && detection.confidence > 0.8 {
return Err("Malicious input detected");
}
// Deep path: <520ms analysis for suspicious inputs
if detection.requires_deep_analysis() {
let analysis = analyzer.analyze(&user_input, Some(&detection)).await?;
if analysis.is_threat() {
responder.mitigate(&user_input, &analysis).await?;
}
}
Multi-Agent Security
Coordinate defense across agent swarms:
// Initialize components for all agents
let detector = DetectionService::new(config).await?;
let analyzer = AnalysisEngine::new(config).await?;
// Detect anomalous behavior
for agent in swarm.agents() {
let trace = agent.action_history();
let result = analyzer.analyze_sequence(&trace).await?;
if result.anomaly_score > 0.8 {
coordinator.flag_agent(agent.id, result).await?;
}
}
See: Multi-Agent Security Guide
Real-Time Chat
Sub-10ms defense for interactive UIs:
// WebSocket message handler
async fn on_message(msg: ChatMessage) {
let input = PromptInput::new(&msg.text, None);
// <10ms latency
let result = detector.detect(&input).await?;
if result.is_threat {
send_error("Message blocked").await?;
} else {
process_message(msg).await?;
}
}
See: Real-Time Chat Guide
Fraud Detection
Identify unusual transaction patterns:
// Train baseline on normal behavior
analyzer.train_baseline(&normal_transactions).await?;
// Analyze new transaction
let result = analyzer.analyze(&new_transaction, None).await?;
if result.anomaly_score > 0.9 {
fraud_system.flag_for_review(new_transaction).await?;
}
📊 Performance Targets
All performance targets validated in production:
| Component | Target | Actual | Documentation |
|---|---|---|---|
| Detection | <10ms | ~8ms | Detection Benchmarks |
| Behavioral Analysis | <100ms | ~80ms | Analysis Benchmarks |
| Policy Verification | <500ms | ~420ms | Verification Benchmarks |
| Mitigation | <50ms | ~45ms | Response Benchmarks |
| API Throughput | >10,000 req/s | >12,000 req/s | Integration Report |
🔧 Configuration Reference
Core Configuration
pub struct Config {
// Detection
pub detection_enabled: bool,
pub detection_timeout_ms: u64,
pub max_pattern_cache_size: usize,
// Analysis
pub behavioral_analysis_enabled: bool,
pub behavioral_threshold: f64,
pub policy_verification_enabled: bool,
// Response
pub adaptive_mitigation_enabled: bool,
pub max_mitigation_attempts: usize,
pub mitigation_timeout_ms: u64,
// Logging
pub log_level: String,
pub metrics_enabled: bool,
pub audit_logging_enabled: bool,
}
See: Configuration Guide
Environment Variables
# Detection
AIMDS_DETECTION_ENABLED=true
AIMDS_DETECTION_TIMEOUT_MS=10
AIMDS_MAX_PATTERN_CACHE_SIZE=10000
# Analysis
AIMDS_BEHAVIORAL_ANALYSIS_ENABLED=true
AIMDS_BEHAVIORAL_THRESHOLD=0.75
AIMDS_POLICY_VERIFICATION_ENABLED=true
# Response
AIMDS_ADAPTIVE_MITIGATION_ENABLED=true
AIMDS_MAX_MITIGATION_ATTEMPTS=3
AIMDS_MITIGATION_TIMEOUT_MS=50
# Logging
AIMDS_LOG_LEVEL=info
AIMDS_METRICS_ENABLED=true
AIMDS_AUDIT_LOGGING_ENABLED=true
See: Environment Configuration
📈 Monitoring & Observability
Prometheus Metrics
# Detection metrics
aimds_detection_requests_total
aimds_detection_latency_ms
aimds_pattern_cache_hit_rate
# Analysis metrics
aimds_analysis_latency_ms
aimds_anomaly_score_distribution
aimds_policy_violations_total
# Response metrics
aimds_mitigation_success_rate
aimds_rollback_total
aimds_strategy_effectiveness
See: Monitoring Guide
Structured Logging
{
"timestamp": "2025-10-27T12:34:56.789Z",
"level": "INFO",
"target": "aimds_detection",
"message": "Threat detected",
"fields": {
"threat_id": "thr_abc123",
"severity": "HIGH",
"confidence": 0.95,
"latency_ms": 8.5
}
}
🧪 Testing Guide
Running Tests
# All Rust tests
cargo test --all-features
# Specific crate
cargo test --package aimds-detection
# Integration tests
cargo test --test integration_tests
# TypeScript tests
npm test
# Benchmarks
cargo bench
npm run bench
See: Test Report
Test Coverage
- aimds-core: 100% (7/7 tests)
- aimds-detection: 90% (20/22 tests)
- aimds-analysis: 100% (27/27 tests)
- aimds-response: 97% (38/39 tests)
- TypeScript: 100% (all integration tests)
🤝 Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
Documentation Contributions
- Fork the repository
- Update documentation in relevant files
- Test code examples
- Submit pull request
Documentation locations:
- Crate READMEs:
/crates/*/README.md - Main README:
/README.md - This index:
/docs/README.md - Guides:
/docs/*.md
📄 License
MIT OR Apache-2.0
🔗 Related Documentation
Midstream Platform
- temporal-compare - Sub-microsecond temporal ordering
- nanosecond-scheduler - Adaptive task scheduling
- temporal-attractor-studio - Chaos analysis
- temporal-neural-solver - Neural ODE solving
- strange-loop - Meta-learning engine
External Projects
- AgentDB - 150x faster vector database
- lean-agentic - Formal verification engine
- Claude Flow - Multi-agent orchestration
- Flow Nexus - Cloud AI swarm platform
🆘 Support
- Website: https://ruv.io/aimds
- Documentation: https://ruv.io/aimds/docs
- GitHub Issues: https://github.com/agenticsorg/midstream/issues
- Discord: https://discord.gg/ruv
- Twitter: @ruvnet
- LinkedIn: ruvnet
📝 Documentation Changelog
Latest Updates
- 2025-10-27: Initial comprehensive documentation
- Added crate-specific READMEs
- Created documentation index
- Added use case guides
- Included performance benchmarks
Built with ❤️ by rUv | GitHub | Twitter | LinkedIn
Keywords: AI security documentation, adversarial defense guide, prompt injection detection, Rust AI security, TypeScript API gateway, real-time threat detection, behavioral analysis, formal verification, LLM security, production AI safety