repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources15d ago| #1 | """ |
| #2 | BEAM Working Memory Scale Benchmark — demonstrates working_memory recall |
| #3 | stays fast as working_memory grows, thanks to FTS5 fast path. |
| #4 | Run: PYTHONPATH=. python tests/benchmark_beam_working_memory.py |
| #5 | """ |
| #6 | |
| #7 | import time |
| #8 | import tempfile |
| #9 | from pathlib import Path |
| #10 | |
| #11 | from mnemosyne.core.beam import BeamMemory |
| #12 | |
| #13 | |
| #14 | def benchmark(): |
| #15 | with tempfile.TemporaryDirectory() as tmpdir: |
| #16 | db_path = Path(tmpdir) / "wm_scale.db" |
| #17 | beam = BeamMemory(session_id="wm_scale", db_path=db_path) |
| #18 | |
| #19 | sizes = [100, 1000, 5000, 10000] |
| #20 | print("🔍 BEAM Working Memory Recall Latency vs Corpus Size") |
| #21 | print("-" * 55) |
| #22 | |
| #23 | cumulative = 0 |
| #24 | for size in sizes: |
| #25 | print(f"Inserting batch to reach {size} working memories...") |
| #26 | t0 = time.time() |
| #27 | batch = size - cumulative |
| #28 | items = [ |
| #29 | { |
| #30 | "content": f"Working memory item {cumulative + i}: concept {i % 100} in domain {(cumulative + i) % 10}", |
| #31 | "source": "conversation", |
| #32 | "importance": 0.5 |
| #33 | } |
| #34 | for i in range(batch) |
| #35 | ] |
| #36 | beam.remember_batch(items) |
| #37 | insert_sec = time.time() - t0 |
| #38 | cumulative = size |
| #39 | print(f" Batch insert ({batch} items): {insert_sec:.1f}s") |
| #40 | |
| #41 | # Benchmark recall |
| #42 | queries = ["concept 42", "domain 7", "nonexistent xyz"] |
| #43 | for q in queries: |
| #44 | times = [] |
| #45 | for _ in range(10): |
| #46 | t0 = time.time() |
| #47 | results = beam.recall(q, top_k=5) |
| #48 | times.append((time.time() - t0) * 1000) |
| #49 | avg = sum(times) / len(times) |
| #50 | p95 = sorted(times)[int(len(times) * 0.95)] |
| #51 | print(f" WM={size:5d} | Query='{q[:20]:<20}' | {avg:.2f}ms avg | {p95:.2f}ms p95") |
| #52 | |
| #53 | wm_stats = beam.get_working_stats() |
| #54 | ep_stats = beam.get_episodic_stats() |
| #55 | print(f"\n📊 Final working memory: {wm_stats['total']} items") |
| #56 | print(f"📊 Final episodic memory: {ep_stats['total']} items | vectors: {ep_stats['vectors']} | vec_type: {ep_stats.get('vec_type', 'none')}") |
| #57 | |
| #58 | |
| #59 | if __name__ == "__main__": |
| #60 | benchmark() |
| #61 |