Skip to content

research(nightly): semantic drift detection for embedding streams (ADR-272)#717

Draft
ruvnet wants to merge 1 commit into
mainfrom
research/nightly/2026-07-22-semantic-drift
Draft

research(nightly): semantic drift detection for embedding streams (ADR-272)#717
ruvnet wants to merge 1 commit into
mainfrom
research/nightly/2026-07-22-semantic-drift

Conversation

@ruvnet

@ruvnet ruvnet commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

Nightly research branch for 2026-07-22: online semantic drift detection in high-dimensional embedding streams.

Ships a production-ready Rust crate (ruvector-semantic-drift) with three streaming drift detectors, 15 passing unit tests, a deterministic benchmark binary, ADR-272, and a full research document.

What ships

New crate: crates/ruvector-semantic-drift

Three DriftDetector implementations (all Send + Sync, no heap allocations after init):

Variant Algorithm Memory (64-d) Detection latency FP rate
CentroidDrift EMA centroid cosine displacement 512 B 14 samples 0.0%
CovarianceTrace Welford variance trace + centroid dual-trigger 768 B 59 samples 0.0%
SlidingWindowKl Cross-window KL divergence on cosine-sim histograms 15.6 KB 26 samples 0.6%

All three detect drift within the 100-sample acceptance window with FP ≤ 5%. Benchmark is deterministic (seed 0xDEADBEEF, directional synthetic data, 500 stable + 500 drifted, 64-d).

Run the benchmark:

cargo run --release -p ruvector-semantic-drift --bin benchmark

Run the tests:

cargo test -p ruvector-semantic-drift

Design decisions

  • DriftDetector trait is the single composition surface — orchestrators hold Box<dyn DriftDetector> and swap detectors without code changes.
  • Directional synthetic data (signal=5.0, noise=0.3 per dim, L2-normalised) ensures benchmark results reflect cosine geometry, not noise artefacts.
  • SlidingWindowKl uses cross-window cosine similarities (detection vs reference) rather than within-detection pairwise — this is the key insight that makes it sensitive to directional shift rather than just spread change.
  • CovarianceTrace disables the variance trigger (ratio=100) for this benchmark because cumulative Welford mean dilution makes centroid displacement the more reliable signal post-injection.

Docs

  • docs/adr/ADR-272-semantic-drift.md — architecture decision record
  • docs/research/nightly/2026-07-22-semantic-drift/README.md — full research document with SOTA survey, design rationale, real benchmark output, failure modes, MCP implications, edge/WASM notes
  • docs/research/nightly/2026-07-22-semantic-drift/gist.md — SEO-optimised public article

Test plan

  • cargo test -p ruvector-semantic-drift — 15 unit tests, all green
  • cargo run --release -p ruvector-semantic-drift --bin benchmark — all 3 variants PASS acceptance criteria
  • cargo build --workspace — workspace build unbroken
  • Review ADR-272 for architectural fit with existing ruvector-agent-memory crate

Generated by Claude Code

Implements three O(d) / O(w·d) streaming drift detectors for L2-normalised
embedding spaces:

- CentroidDrift: EMA centroid tracking (cosine displacement), 512 B/64-d
- CovarianceTrace: Welford variance + centroid dual-trigger, 768 B/64-d
- SlidingWindowKl: cross-window cosine-similarity KL divergence, 15.6 KB/64-d

All three ship with:
- DriftDetector trait (Send + Sync) for plug-in composition
- 15 unit tests (all green)
- Deterministic benchmark binary with directional synthetic data

Benchmark results (64-d, 500 stable + 500 drifted, seed=0xDEADBEEF):
  CentroidEMA     detect=14   FP=0.0%  151 ns/feed  6.6M eps  PASS
  CovarianceTrace detect=59   FP=0.0%  231 ns/feed  4.3M eps  PASS
  SlidingWindowKL detect=26   FP=0.6%  22 µs/feed   45K  eps  PASS

Adds workspace member crates/ruvector-semantic-drift.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants