Skip to main content

drift-lens demo

drift-lens-monitor

Your metrics lie. Your embeddings don't.

PyPI Python License Stars

Quick Start • Why drift-lens? • Methods • CLI • API • Dashboard • Contributing


The Problem

Your model's accuracy looks fine — until it doesn't. By the time precision drops, your embeddings have been silently drifting for days. Traditional monitoring watches the wrong signals: accuracy, loss, and latency are lagging indicators. The embedding space is the leading indicator, and nobody's watching it.

drift-lens-monitor detects embedding space drift days before your accuracy drops — with zero infra changes.

Install

pip install drift-lens-monitor

Quick Start

from drift_lens import EmbeddingLogger, DriftDetector

logger = EmbeddingLogger(path="./embeddings", window="1d")
logger.log(embeddings)  # numpy, torch, or list — we handle it

detector = DriftDetector(method="frechet")  # or "mmd" or "topology"
result = detector.compare(baseline_embeddings, current_embeddings)
print(f"Drift score: {result.drift_score:.3f} | Alert: {result.is_drift}")

That's it. Five lines. No API keys, no cloud, no YAML files.


Why drift-lens?

drift-lens Evidently Arize
Topology-aware detection ✅ Persistent homology catches cluster merges/splits ❌ Statistical tests only ❌ Statistical tests only
Zero infrastructure ✅ pip install and go — flat files, no DB ⚠️ Requires dashboard server ❌ SaaS platform, needs API keys
Embedding-native ✅ Built specifically for embedding spaces (FED, MMD, Wasserstein) ⚠️ Generic feature drift, bolt-on embedding support ⚠️ General-purpose observability

Detection Methods

1. Fréchet Embedding Distance (FED)

The FID of embeddings. Fast, interpretable, great first pass.

  • Models embeddings as multivariate Gaussians
  • Measures: FED = ‖μ₁ - μ₂‖² + Tr(Σ₁ + Σ₂ - 2·(Σ₁·Σ₂)^½)
  • Numerically stabilized with eigenvalue clipping and covariance regularization
  • Best for: Quick daily checks, CI/CD gates, dashboards

2. Maximum Mean Discrepancy (MMD)

No Gaussian assumption. Kernel-based. Comes with a p-value.

  • RBF kernel with adaptive median-heuristic bandwidth
  • Permutation test (200 permutations) for statistical significance
  • Detects non-linear distribution shifts FED would miss
  • Best for: Rigorous statistical testing, regulatory compliance

3. Topological Drift Detection 🧬

Our moat. No other production drift tool does this.

  • Computes persistent homology via Vietoris-Rips filtration (Ripser)
  • H₀ features = connected components (cluster count changes)
  • H₁ features = loops and holes (structural topology shifts)
  • Compares persistence diagrams via Wasserstein distance
  • Best for: Detecting cluster merges, splits, and structural collapse

CLI Reference

drift-lens ships as a CLI tool. Every command works on parquet snapshot files.

drift-lens compare

Compare two embedding snapshots:

drift-lens compare \
  --baseline ./snapshots/day1.parquet \
  --current  ./snapshots/day14.parquet \
  --method   frechet \
  --threshold 0.3
Flag Default Description
--baseline (required) Path to baseline snapshot (file or directory)
--current (required) Path to current snapshot (file or directory)
--method frechet Detection method: frechet, mmd, topology
--threshold 0.3 Alert threshold (0-1)

drift-lens watch

Continuously monitor a snapshot directory:

drift-lens watch \
  --snapshots ./snapshots \
  --method mmd \
  --threshold 0.4 \
  --interval 60
Flag Default Description
--snapshots (required) Directory to watch for new parquet files
--method frechet Detection method
--threshold 0.3 Alert threshold
--interval 60 Polling interval in seconds

drift-lens report

Generate a standalone HTML drift report:

drift-lens report \
  --snapshots ./snapshots \
  --output drift_report.html \
  --method frechet
Flag Default Description
--snapshots (required) Directory containing snapshot parquet files
--output drift_report.html Output HTML file path
--method frechet Detection method

drift-lens dashboard

Launch the interactive Streamlit dashboard:

drift-lens dashboard                    # uses built-in demo data
drift-lens dashboard --snapshots ./data # uses your data
Flag Default Description
--snapshots None Path to snapshots (uses demo data if omitted)

Python API

EmbeddingLogger

Log embeddings to disk as time-windowed parquet snapshots:

from drift_lens import EmbeddingLogger

logger = EmbeddingLogger(path="./drift_data", window="1d")  # 1h, 6h, 1d, 7d

# Log from any source — numpy, torch tensors, or plain lists
logger.log(embeddings, metadata={"model": "minilm", "source": "prod"})

# List and load snapshots
files = logger.list_snapshots()
baseline = logger.load_snapshot(files[0])

DriftDetector

Unified interface for all three detection methods:

from drift_lens import DriftDetector

detector = DriftDetector(method="frechet", threshold=0.3)
result = detector.compare(baseline, current)

print(result.drift_score)  # 0.0 - 1.0 (normalized)
print(result.is_drift)     # True/False
print(result.p_value)      # float (MMD only) or None
print(result.details)      # method-specific diagnostics

DriftProjector

Fit-on-baseline / transform-current pattern prevents data leakage:

from drift_lens import DriftProjector

projector = DriftProjector(method="umap", n_components=2)
projector.fit(baseline)
proj_base = projector.transform(baseline)
proj_curr = projector.transform(current)

projector.save("projection.pkl")
projector = DriftProjector.load("projection.pkl")

AlertEngine

Threshold-based alerting with cooldowns and audit trail:

from drift_lens import AlertEngine

engine = AlertEngine(threshold=0.3, cooldown_hours=6, alert_dir="./alerts")
alert = engine.check(result)

print(alert.fired)               # True/False
print(alert.severity)            # low, medium, high, critical
print(alert.recommended_action)  # human-readable next steps

Dashboard

The Streamlit dashboard is the demo that sells itself:

# Quick demo with synthetic data
drift-lens dashboard

# or
streamlit run drift_lens/dashboard.py

Features:

  • 🔬 Side-by-side UMAP projections (baseline vs. current)
  • 📈 Drift score timeline with accuracy overlay
  • 🚨 Early warning banner ("DETECTED 4 DAYS BEFORE ACCURACY DROP")
  • 📊 All three methods compared in tabs (FED, MMD, Topology)
  • 🎯 Severity-based recommended actions
  • 📋 Full alert history table

How It Works

Your Model                    drift-lens
─────────                    ───────────
embeddings ──┐
             │   EmbeddingLogger     DriftDetector
             ├──→ .log()  ──→ .parquet ──→ .compare()
             │                              │
             │                        ┌─────┴─────┐
             │                        │  drift_score │
             │                        │  is_drift    │
             │                        │  p_value     │
             │                        └─────┬─────┘
             │                              │
             │                        AlertEngine
             │                         .check()
             │                              │
             │                    ┌─────────┴────────┐
             │                    │ 🟢 low            │
             │                    │ 🟡 medium         │
             │                    │ 🟠 high           │
             │                    │ 🔴 critical       │
             │                    └──────────────────┘

Contributing

We welcome contributions! See CONTRIBUTING.md for the full guide.

Quick version:

# Fork & clone
git clone https://github.com/YOUR_USERNAME/Drift_lens.git
cd Drift_lens

# Install in dev mode
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Make changes, then PR

License

MIT — see LICENSE.


Built by Praful Reddy
If drift-lens saved you from a production incident, consider giving it a ⭐

Metadata

Release files for drift-lens-monitor 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drift-lens-monitor 0.1.0
File Size Uploaded Provenance Actions
drift_lens_monitor-0.1.0.tar.gz 2.2 MB Without provenance Details for drift_lens_monitor-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drift-lens-monitor 0.1.0
File Interpreter ABI Platform Actions
drift_lens_monitor-0.1.0-py3-none-any.whl Python 3 none any Details for drift_lens_monitor-0.1.0-py3-none-any.whl

Total release size: 2.2 MB

Release files / drift_lens_monitor-0.1.0.tar.gz

Download URL drift_lens_monitor-0.1.0.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
1baf17f63032bdb9c24762843cfa01e77950dda4b7e86abbba14ac866ec5d5e9
BLAKE2b-256 checksum
How to use checksums
8fa150bfb9084ffc2607bb4b0919cd35f9a0d67df851c263df70c46e5e7f2276
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / drift_lens_monitor-0.1.0-py3-none-any.whl

Download URL drift_lens_monitor-0.1.0-py3-none-any.whl
Size 30.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1059840be0cbc976f89c5b68a6515940cc646aefaff00a2bf2188af5836474f3
BLAKE2b-256 checksum
How to use checksums
f1065eff4a5dd890797ffc1ffa47ae059d45a594e6cc221a2206ad9d4a045787
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Security for drift-lens-monitor 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page