# ragdrift-core

Pure-Rust core for [ragdrift](https://github.com/MukundaKatta/ragdrift):
5-dimensional drift detection for production RAG systems.

This crate is the numerical engine. It has no Python or FFI surface and is
suitable for embedding in a Rust service that wants to compute drift scores
without going through Python. The Python bindings live in `ragdrift-py`
in the same workspace.

## What it computes

- **Data drift** — feature-wise Kolmogorov-Smirnov and Population Stability Index.
- **Embedding drift** — Maximum Mean Discrepancy (RBF kernel, median-heuristic
  bandwidth) plus sliced Wasserstein-1 over the embedding matrix.
- **Response drift** — distribution shift over response length and unigram
  entropy, with optional embedding-based semantic shift.
- **Confidence drift** — KS test on score distributions plus Expected
  Calibration Error delta.
- **Query-pattern drift** — k-means cluster assignment shift (KL divergence).

## Quick example

```rust
use ndarray::Array2;
use ragdrift_core::detectors::EmbeddingDriftDetector;

let baseline: Array2<f32> = Array2::zeros((1024, 384));
let current: Array2<f32> = Array2::zeros((1024, 384));
let detector = EmbeddingDriftDetector::default();
let score = detector.detect(&baseline.view(), &current.view()).unwrap();
println!("{} = {:.4}", score.method, score.score);
```

## License

Dual-licensed under MIT or Apache-2.0 at your option.
