research(streaming-qng): QNG-Stream — reservoir-sampled adaptive PQ for distribution-drift resilience - #816
Draft
ruvnet wants to merge 1 commit into
Draft
research(streaming-qng): QNG-Stream — reservoir-sampled adaptive PQ for distribution-drift resilience#816ruvnet wants to merge 1 commit into
ruvnet wants to merge 1 commit into
Conversation
…voir adaptation Adds crates/ruvector-streaming-qng: three measurable ANN variants for distribution-drift resilience in agent memory systems. StreamPQ achieves 1.0000 cluster precision after a 3.0-unit distribution shift vs 0.9863 for StaticPQ (Phase-B n=10000, dims=64, k=10). Full k-means retrain on a Vitter-sampled reservoir is required — EMA one-pass was explored first and abandoned because centroid collision (two Phase-B clusters mapping to the same Phase-A centroid bin) causes EMA to converge to a merged midpoint that represents neither cluster. Key findings: - Cluster precision is the correct PQ metric; recall@k is invalid at realistic densities because quantization error ≈ within-cluster variance. - Reservoir domination condition: Phase-B stream ≥3× Phase-A for ≥75% Phase-B in reservoir; benchmark uses 4× for ~80% domination. - 148× insert overhead at update_freq=200 is the cost of correctness; async retrain or larger update_freq amortizes this for production. All 5 unit tests pass. All 4 benchmark acceptance gates pass. ADR-298 documents the decision, consequences, and alternatives considered. Research README includes full benchmark tables, per-cluster breakdown, and production integration path. Co-Authored-By: claude-flow <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01G94862kbmLDhA3dQjfPfH9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
crates/ruvector-streaming-qng: a standalone research crate implementing three measurable ANN variants for evaluating codebook adaptation under distribution drift in agent memory systems.StreamPQ achieves 1.0000 cluster precision after a 3.0-unit distribution shift vs 0.9863 for StaticPQ (dims=64, 4 clusters, Phase-B n=10,000, k=10). All 4 benchmark acceptance gates pass. All 5 unit tests pass.
Motivation
Agent memory systems emit vectors continuously as the agent shifts context (code → natural language → scientific reasoning). A static PQ codebook trained at startup systematically misquantizes the new distribution — centroids that fitted the original data no longer partition the new data. The recall degradation is silent: no error raised, but wrong memories returned.
Technical Approach
Why full k-means retrain instead of EMA one-pass:
EMA was explored first and abandoned. When the distribution shift is comparable to cluster spacing, two different Phase-B clusters map to the same Phase-A centroid bin. EMA averages them into a merged centroid at the midpoint — representing neither cluster — and no future update can separate them. Full k-means retrain from reservoir data restarts without this bias and correctly separates all clusters once the reservoir is dominated by the new distribution.
Reservoir domination condition: Phase-B stream must be ≥3× Phase-A for the reservoir to reach ≥75% Phase-B vectors. The benchmark uses 4× (n_per_b=2000, n_per_a=500) to achieve ~80% Phase-B domination.
Cluster precision vs recall@k: PQ discriminates between clusters with near-perfect accuracy but cannot rank within-cluster vectors precisely — quantization error is comparable to within-cluster distance variance at realistic densities.
recall@krequires exact within-cluster top-k ordering and is invalid for PQ evaluation. Cluster precision is the correct metric.Benchmark Results (verified, release build)
Config:
dims=64, clusters=4, shift=3.0, std=0.3, Phase-A: 2000 vecs, Phase-B: 8000 vecs, k=10Acceptance gates: all 4 PASS (FullPrecision ≥0.90, StreamPQ Phase-A ≥0.60, StreamPQ Phase-B ≥0.50, StreamPQ Phase-B ≥ StaticPQ Phase-B − 0.05)
Trade-off: 148× insert overhead at
update_freq=200. Production mitigations: increaseupdate_freq, async background retrain, or drift-threshold-triggered retrain via ruFlo.Files Changed
Running
Integration Path
features = ["stream-pq"]inruvector-pq-search(non-breaking)reservoir_capandupdate_freqas runtime parametersruvector-corewhen recall advantage confirmed on 1M+ vector drift scenariosSee ADR-298 for full decision record.
Generated by Claude Code