research(nightly): semantic-query-cache — cosine-similarity cache for agent memory workloads (ADR-298) - #811
Draft
ruvnet wants to merge 1 commit into
Draft
Conversation
…arded backends (ADR-298) Implements a zero-dependency Rust semantic cache layer for RuVector agent memory workloads. Caches (query_vector → result_ids) pairs and detects cache hits via cosine similarity (dot product on pre-normalized vectors), tolerating natural-language rephrasing that would defeat exact-match caches. Two production-relevant backends: - LinearScanCache: O(C·D) exhaustive scan, optimal for C < 1 000 entries - ShardedCache: 6-bit LSH with multi-probe (primary + 6 one-bit-flip neighbors), lookup scans ~7×C/64 entries, suitable for C up to ~50 000 Benchmark results (N=10 000 base vectors, D=128, 50 clusters, 500 queries, k=10, threshold=0.92, noise_std=0.02): LinearCache: 90.0% hit rate, 9.5× speedup, 0.744 mean recall — PASS ShardedCache: 85.6% hit rate, 6.7× speedup, 0.757 mean recall — PASS Files added: crates/ruvector-semantic-cache/src/lib.rs — QueryCache trait, NoCache, utilities crates/ruvector-semantic-cache/src/linear.rs — LinearScanCache crates/ruvector-semantic-cache/src/sharded.rs — ShardedCache (multi-probe LSH) crates/ruvector-semantic-cache/src/metrics.rs — CacheStats (Cell-based, WASM-safe) crates/ruvector-semantic-cache/src/dataset.rs — deterministic clustered dataset generator crates/ruvector-semantic-cache/src/bin/benchmark.rs — benchmark binary docs/adr/ADR-298-semantic-query-cache.md — Architecture Decision Record docs/research/nightly/2026-08-09-semantic-query-cache/README.md — research doc docs/research/nightly/2026-08-09-semantic-query-cache/gist.md — public gist All 21 unit tests pass. Benchmark binary exits 0 with all acceptance criteria met. Co-Authored-By: claude-flow <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01DW2etWbojPcWNGMHQLcyb3
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
crates/ruvector-semantic-cache: a zero-dependency Rust crate implementing a semantic cache layer that maps(query_vector → result_ids)and detects cache hits via cosine similarity, enabling AI agents to skip redundant vector searches when they re-ask semantically identical questions with slightly different wording.LinearScanCache(O(C·D), optimal for C < 1 000) andShardedCache(6-bit multi-probe LSH, O(7·C/64·D), suitable for C up to ~50 000), both implementing theQueryCachetrait.docs/adr/ADR-298-semantic-query-cache.mdand full nightly research document underdocs/research/nightly/2026-08-09-semantic-query-cache/.What changed
New crate:
crates/ruvector-semantic-cachesrc/lib.rsQueryCachetrait,NoCachebaseline,dot()/normalize()utilitiessrc/linear.rsLinearScanCache: exhaustive cosine scan with FIFO eviction and TTLsrc/sharded.rsShardedCache: 6-bit LSH projection, multi-probe (primary + 6 one-bit-flip neighbors)src/metrics.rsCacheStatswithCell<u64>interior mutability (single-threaded / WASM-safe)src/dataset.rssrc/bin/benchmark.rsDesign choices
SystemTimeso the crate compiles to WASM without shims.Documentation
docs/adr/ADR-298-semantic-query-cache.md— context, decision, consequences, alternatives, benchmark evidence, failure modes, security considerations, migration path.docs/research/nightly/2026-08-09-semantic-query-cache/README.md— full research document with SOTA survey, forward-looking thesis, ecosystem fit analysis, architecture diagram, performance math, and next steps.docs/research/nightly/2026-08-09-semantic-query-cache/gist.md— SEO-optimized public article with comparison against 9 vector databases and practical + exotic application tables.Test plan
cargo test -p ruvector-semantic-cache— 21 tests, 0 failurescargo build --release -p ruvector-semantic-cache— clean build, 0 warnings (exceptdead_codeon public API surface)cargo run --release -p ruvector-semantic-cache --bin benchmark— all 6 acceptance criteria PASS:Generated by Claude Code