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 | Quick benchmark for Mnemosyne BEAM architecture. |
| #3 | Run: PYTHONPATH=. python tests/benchmark_beam.py |
| #4 | """ |
| #5 | |
| #6 | import time |
| #7 | import tempfile |
| #8 | import sqlite3 |
| #9 | from datetime import datetime, timedelta |
| #10 | from pathlib import Path |
| #11 | |
| #12 | from mnemosyne.core.beam import BeamMemory |
| #13 | |
| #14 | |
| #15 | def benchmark(): |
| #16 | with tempfile.TemporaryDirectory() as tmpdir: |
| #17 | db_path = Path(tmpdir) / "bench.db" |
| #18 | beam = BeamMemory(session_id="bench", db_path=db_path) |
| #19 | |
| #20 | n = 500 |
| #21 | print(f"Storing {n} working memories...") |
| #22 | t0 = time.time() |
| #23 | for i in range(n): |
| #24 | beam.remember(f"Task number {i}: solve problem {i * 7}", source="conversation", importance=0.5) |
| #25 | write_time = (time.time() - t0) / n * 1000 |
| #26 | print(f" Avg write: {write_time:.3f} ms") |
| #27 | |
| #28 | # Inject old memories so sleep has something to consolidate |
| #29 | print("Injecting old working memories for consolidation...") |
| #30 | conn = sqlite3.connect(db_path) |
| #31 | old_ts = (datetime.now() - timedelta(hours=20)).isoformat() |
| #32 | for i in range(100): |
| #33 | conn.execute( |
| #34 | "INSERT INTO working_memory (id, content, source, timestamp, session_id, importance) VALUES (?, ?, ?, ?, ?, ?)", |
| #35 | (f"old{i}", f"Old task {i}", "conversation", old_ts, "bench", 0.5) |
| #36 | ) |
| #37 | conn.commit() |
| #38 | conn.close() |
| #39 | |
| #40 | print("Running sleep/consolidation...") |
| #41 | t0 = time.time() |
| #42 | result = beam.sleep(dry_run=False) |
| #43 | sleep_time = (time.time() - t0) * 1000 |
| #44 | print(f" Sleep took: {sleep_time:.1f} ms | status: {result['status']}") |
| #45 | |
| #46 | print("Recalling from hybrid memory...") |
| #47 | queries = ["solve problem", "task number", "problem 3500", "nonexistent xyz"] |
| #48 | for q in queries: |
| #49 | times = [] |
| #50 | for _ in range(10): |
| #51 | t0 = time.time() |
| #52 | results = beam.recall(q, top_k=5) |
| #53 | times.append((time.time() - t0) * 1000) |
| #54 | avg_time = sum(times) / len(times) |
| #55 | print(f" Query '{q}': {avg_time:.2f} ms | {len(results)} results") |
| #56 | |
| #57 | stats = beam.get_working_stats() |
| #58 | ep_stats = beam.get_episodic_stats() |
| #59 | print(f"\nWorking memory: {stats}") |
| #60 | print(f"Episodic memory: {ep_stats}") |
| #61 | |
| #62 | |
| #63 | if __name__ == "__main__": |
| #64 | benchmark() |
| #65 |