π The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
feat(memory): #2061 ADR-125 Phase 6 β runnable benchmarks + baseline results
ruved95d6782224
diff --git a/v3/@claude-flow/memory/benchmarks/hnsw-search.bench.ts b/v3/@claude-flow/memory/benchmarks/hnsw-search.bench.tsnew file mode 100644index 0000000000..4c419c041d--- /dev/null+++ b/v3/@claude-flow/memory/benchmarks/hnsw-search.bench.ts@@ -0,0 +1,102 @@+/**+ * HNSW Search Benchmark (ADR-125 Phase 6).+ *+ * Vitest `bench()` suite that measures the canonical `HNSWIndex.search()`+ * against a 1k-entry index. The bench exists so `npm run bench` produces+ * non-empty output and gives the README perf table a real referent.+ *+ * Result interpretation:+ * - `hnsw.search k=10` is the headline number β single-query latency against+ * 1,000 random 128-dim vectors.+ * - `hnsw.add (single)` measures incremental insert cost; useful for tracking+ * regression as ADR-125 Phase 3 adds persistence.+ *+ * @see {@link ../docs/adr/ADR-125-memory-consolidation.md}+ */++import { describe, bench, beforeAll } from 'vitest';+import { HNSWIndex } from '../src/hnsw-index.js';++// Bench scale chosen to fit Phase 6's "ONE simple benchmark against 1k entries"+// scope. Dimensions kept small (128) so the bench completes in seconds β the+// goal is a runnable referent, not a full perf evaluation (that's Phase 3+).+const N = 1_000;+const DIM = 128;+const M = 16;+const EF_CONSTRUCTION = 200;++function randomVector(dim: number): Float32Array {+ const v = new Float32Array(dim);+ let norm = 0;+ for (let i = 0; i < dim; i++) {+ v[i] = Math.random() * 2 - 1;+ norm += v[i] * v[i];+ }+ norm = Math.sqrt(norm) || 1;+ for (let i = 0; i < dim; i++) v[i] /= norm;+ return v;+}++describe('HNSW search β 1k entries, 128-dim', () => {+ let index: HNSWIndex;+ let queries: Float32Array[];++ beforeAll(async () => {+ index = new HNSWIndex({+ dimensions: DIM,+ M,+ efConstruction: EF_CONSTRUCTION,+ maxElements: N + 100,+ metric: 'cosine',+ });++ // Pre-populate+ for (let i = 0; i < N; i++) {+ await index.addPoint(`vec-${i}`, randomVector(DIM));+ }++ // Pre-generate query vectors so the bench measures search, not RNG.+ queries = Array.from({ length: 50 }, () => randomVector(DIM));+ });++ bench(+ 'hnsw.search k=10',+ async () => {+ const q = queries[Math.floor(Math.random() * queries.length)]!;+ await index.search(q, 10);+ },+ { iterations: 100, warmupIterations: 10 }+ );++ bench(+ 'hnsw.search k=50',+ async () => {+ const q = queries[Math.floor(Math.random() * queries.length)]!;+ await index.search(q, 50);+ },+ { iterations: 100, warmupIterations: 10 }+ );+});++describe('HNSW add β incremental insert cost', () => {+ let index: HNSWIndex;+ let counter = 0;++ beforeAll(() => {+ index = new HNSWIndex({+ dimensions: DIM,+ M,+ efConstruction: EF_CONSTRUCTION,+ maxElements: 10_000,+ metric: 'cosine',+ });+ });++ bench(+ 'hnsw.add (single)',+ async () => {+ await index.addPoint(`add-${counter++}`, randomVector(DIM));+ },+ { iterations: 500, warmupIterations: 50 }+ );+});diff --git a/v3/@claude-flow/memory/benchmarks/results/baseline-20260519T212453Z.md b/v3/@claude-flow/memory/benchmarks/results/baseline-20260519T212453Z.mdnew file mode 100644index 0000000000..5bc81da2ef--- /dev/null+++ b/v3/@claude-flow/memory/benchmarks/results/baseline-20260519T212453Z.md@@ -0,0 +1,61 @@+# HNSW Search Benchmark β Baseline `20260519T212453Z`++First measured baseline that ADR-125 Phase 6 commits so the README perf table has a real referent.++## Environment++| Field | Value |+| --- | --- |+| Package | `@claude-flow/[email protected]` (head of `feat/adr-125-memory-consolidation`) |+| Node | `v22.22.1` |+| Vitest | `4.0.16` |+| OS | `darwin 25.1.0` (macOS) |+| CPU | Apple Silicon (M-series) |+| Date | 2026-05-19 (UTC) |++## Scenario++- `HNSWIndex` from `src/hnsw-index.ts` (canonical, post-ADR-125-Phase-1 surface).+- 1,000 random 128-dim cosine-normalized vectors pre-loaded.+- Bench source: `benchmarks/hnsw-search.bench.ts`.+- Raw script: `benchmarks/results/scripts/run-baseline.mjs`.++## Results++| Metric | Value | Notes |+| --- | --- | --- |+| `build_time_ms` | **533.42 ms** | Sequential `addPoint()` Γ 1,000. |+| `search_k10_avg_ms` | **0.5294 ms** | 200-iteration average, post-warmup. |+| `search_k50_avg_ms` | **0.5235 ms** | k=50 nearly identical to k=10 β heap-based candidate selection dominates. |+| `add_avg_ms` | **0.8656 ms** | Incremental insert after the initial 1k. |+| `search_k10_ops_per_sec` | **1,888.9 ops/s** | Derived from `search_k10_avg_ms`. |+| `search_k50_ops_per_sec` | **1,910.1 ops/s** | Derived from `search_k50_avg_ms`. |++## Raw JSON++```json+{+ "build_time_ms": 533.42,+ "search_k10_avg_ms": 0.5294,+ "search_k50_avg_ms": 0.5235,+ "add_avg_ms": 0.8656,+ "search_k10_ops_per_sec": 1888.9,+ "search_k50_ops_per_sec": 1910.1+}+```++## How to reproduce++```bash+cd v3/@claude-flow/memory+npm run build+npm run bench # runs benchmarks/hnsw-search.bench.ts under vitest+# OR+node benchmarks/results/scripts/run-baseline.mjs+```++## Notes for future runs++- ADR-125 Phase 3 (persistent HNSW) will add `serialize` / `deserialize` benchmarks here. The post-Phase-3 baseline should show **cold-start** restoration β€ 50% of `build_time_ms`.+- ADR-125 Phase 4 (consolidator) will add a `sweepExpired` measurement.+- These numbers are device-specific; CI baselines will replace this file once the GitHub Actions bench job lands.diff --git a/v3/@claude-flow/memory/benchmarks/results/scripts/run-baseline.mjs b/v3/@claude-flow/memory/benchmarks/results/scripts/run-baseline.mjsnew file mode 100644index 0000000000..ffe1e2de61--- /dev/null+++ b/v3/@claude-flow/memory/benchmarks/results/scripts/run-baseline.mjs@@ -0,0 +1,85 @@+#!/usr/bin/env node+/**+ * ADR-125 Phase 6 β HNSW baseline measurement script.+ *+ * Pre-builds the package (`npm run build`) then exercises the canonical+ * HNSWIndex against 1,000 random 128-dim cosine vectors. Emits a JSON blob+ * suitable for archiving alongside `baseline-<timestamp>.md`.+ *+ * Usage:+ * cd v3/@claude-flow/memory+ * npm run build+ * node benchmarks/results/scripts/run-baseline.mjs+ *+ * Companion to `benchmarks/hnsw-search.bench.ts` (which runs under vitest).+ */++import { HNSWIndex } from '../../../dist/hnsw-index.js';++const N = 1000;+const DIM = 128;+const M = 16;+const EF_CONSTRUCTION = 200;+const ITERS = 200;++function randomVector(dim) {+ const v = new Float32Array(dim);+ let norm = 0;+ for (let i = 0; i < dim; i++) {+ v[i] = Math.random() * 2 - 1;+ norm += v[i] * v[i];+ }+ norm = Math.sqrt(norm) || 1;+ for (let i = 0; i < dim; i++) v[i] /= norm;+ return v;+}++const buildStart = performance.now();+const index = new HNSWIndex({+ dimensions: DIM,+ M,+ efConstruction: EF_CONSTRUCTION,+ maxElements: N + 1000,+ metric: 'cosine',+});+for (let i = 0; i < N; i++) {+ await index.addPoint('vec-' + i, randomVector(DIM));+}+const buildTime = performance.now() - buildStart;++const queries = Array.from({ length: 50 }, () => randomVector(DIM));+for (let i = 0; i < 10; i++) await index.search(queries[i % queries.length], 10);++let t = performance.now();+for (let i = 0; i < ITERS; i++) {+ await index.search(queries[i % queries.length], 10);+}+const k10Avg = (performance.now() - t) / ITERS;++t = performance.now();+for (let i = 0; i < ITERS; i++) {+ await index.search(queries[i % queries.length], 50);+}+const k50Avg = (performance.now() - t) / ITERS;++let addCounter = N;+t = performance.now();+for (let i = 0; i < 200; i++) {+ await index.addPoint('add-' + addCounter++, randomVector(DIM));+}+const addAvg = (performance.now() - t) / 200;++console.log(+ JSON.stringify(+ {+ build_time_ms: +buildTime.toFixed(2),+ search_k10_avg_ms: +k10Avg.toFixed(4),+ search_k50_avg_ms: +k50Avg.toFixed(4),+ add_avg_ms: +addAvg.toFixed(4),+ search_k10_ops_per_sec: +(1000 / k10Avg).toFixed(1),+ search_k50_ops_per_sec: +(1000 / k50Avg).toFixed(1),+ },+ null,+ 2+ )+);diff --git a/v3/@claude-flow/memory/package.json b/v3/@claude-flow/memory/package.jsonindex d9858c2621..b0602da5c4 100644--- a/v3/@claude-flow/memory/package.json+++ b/v3/@claude-flow/memory/package.json@@ -11,7 +11,7 @@},"scripts": {"test": "vitest run",- "bench": "vitest bench",+ "bench": "vitest bench --config vitest.bench.config.ts","build": "tsc","prebuild": "rm -rf dist tsconfig.tsbuildinfo","prepublishOnly": "npm run build && node -e \"const m = await import('./dist/index.js'); const required = ['ControllerRegistry','MemoryService','UnifiedMemoryService','PersistentSonaCoordinator','RvfLearningStore','RvfMigrator']; const missing = required.filter(k => !m[k]); if (missing.length) { console.error('Missing exports:', missing); process.exit(1); } const forbidden = ['HnswLite','RvfBackend']; const leaks = forbidden.filter(k => k in m); if (leaks.length) { console.error('Forbidden public exports present (ADR-125):', leaks); process.exit(1); } console.log('All required exports present; ADR-125 surface clean');\""diff --git a/v3/@claude-flow/memory/vitest.bench.config.ts b/v3/@claude-flow/memory/vitest.bench.config.tsnew file mode 100644index 0000000000..a071e61c19--- /dev/null+++ b/v3/@claude-flow/memory/vitest.bench.config.ts@@ -0,0 +1,38 @@+/**+ * Vitest benchmark configuration (ADR-125 Phase 6).+ *+ * The main `vitest.config.ts` only includes `src/**\/*.test.ts`, which means+ * `npm run bench` previously matched nothing. This config exists so+ * `vitest bench --config vitest.bench.config.ts` discovers and runs the+ * `benchmarks/**\/*.bench.ts` suites that ship with the package.+ *+ * @see {@link ../docs/adr/ADR-125-memory-consolidation.md} Phase 6.+ */+import { defineConfig } from 'vitest/config';++// Excluded β these legacy bench files use a custom `BenchmarkRunner` framework+// rather than vitest `bench()` blocks. They are still runnable via `tsx` but+// don't fit vitest's discovery model. They are kept on-disk as reference and+// will be ported in a follow-up alongside ADR-125 Phase 3 (persistent HNSW).+const LEGACY_BENCHES = [+ 'benchmarks/cache-hit-rate.bench.ts',+ 'benchmarks/hnsw-indexing.bench.ts',+ 'benchmarks/memory-write.bench.ts',+ 'benchmarks/vector-search.bench.ts',+];++export default defineConfig({+ test: {+ environment: 'node',+ include: ['benchmarks/**/*.bench.ts'],+ exclude: ['node_modules', 'dist', 'benchmarks/longmemeval/**', ...LEGACY_BENCHES],+ testTimeout: 60_000,+ hookTimeout: 30_000,+ globals: false,+ typecheck: { enabled: false },+ benchmark: {+ include: ['benchmarks/**/*.bench.ts'],+ exclude: ['node_modules', 'dist', 'benchmarks/longmemeval/**', ...LEGACY_BENCHES],+ },+ },+});