{"_id":"@aid-on/embersm","_rev":"3-1498b1c8dcd76dd118f39ade2f684d32","name":"@aid-on/embersm","dist-tags":{"latest":"2.0.4"},"versions":{"2.0.1":{"name":"@aid-on/embersm","version":"2.0.1","keywords":["cloudflare","workers","d1","kv","vectorize","memory","llm","ai"],"author":{"name":"Aid-On"},"license":"MIT","_id":"@aid-on/embersm@2.0.1","maintainers":[{"name":"aid-on","email":"hiromi.motodera@aid-on.org"}],"dist":{"shasum":"6f88376b24a73392d826f14a086d161c6a74cce0","tarball":"https://registry.npmjs.org/@aid-on/embersm/-/embersm-2.0.1.tgz","fileCount":112,"integrity":"sha512-HBZWdyv0gDfvGs73WrC5U6guUc93WGNOe/jxPIayr/aXEtfswKyF2vdkJPzEKexT/hE3oc6u4sdXRlQZ733yFQ==","signatures":[{"sig":"MEYCIQCBRHOR9uT4G7Ls6qpwGRnWDABIlYWVE23o/jYw7yTmGwIhAKGALZE5NPUCTBlrSQeV7Lssig9Dc7z3mEVH+kGPPjMy","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":959929},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./testing":{"types":"./dist/testing/index.d.ts","import":"./dist/testing/index.js"}},"gitHead":"45f550388ad3243b44a0c55acee0004baad4e91e","scripts":{"dev":"tsc --watch","test":"vitest run","build":"tsc","benchmark":"npx tsx scripts/benchmark.ts","typecheck":"tsc --noEmit","test:watch":"vitest"},"_npmUser":{"name":"aid-on","email":"hiromi.motodera@aid-on.org"},"_npmVersion":"10.8.2","description":"EmbersM - Cloudflare Native Memory System with 5-Layer Architecture","directories":{},"_nodeVersion":"20.19.6","dependencies":{"@aid-on/unilmp":"file:../unilmp"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.0.0","typescript":"^5.0.0","@cloudflare/workers-types":"^4.20241127.0"},"_npmOperationalInternal":{"tmp":"tmp/embersm_2.0.1_1771341610338_0.23868749951092694","host":"s3://npm-registry-packages-npm-production"}},"2.0.2":{"name":"@aid-on/embersm","version":"2.0.2","keywords":["cloudflare","workers","d1","kv","vectorize","memory","llm","ai"],"author":{"name":"Aid-On"},"license":"MIT","_id":"@aid-on/embersm@2.0.2","maintainers":[{"name":"aid-on","email":"hiromi.motodera@aid-on.org"}],"dist":{"shasum":"3f8f4d7011a1417caf2f2aea754508430210cca4","tarball":"https://registry.npmjs.org/@aid-on/embersm/-/embersm-2.0.2.tgz","fileCount":112,"integrity":"sha512-KLdXFeyc0bbQg7hmF010qEAXUTO/81bKgiOQkFwGkyZ2JfnOmA5nRHEvDjcAMuwNF5z9KlpYWbR10jxTK0AWsA==","signatures":[{"sig":"MEUCIFdK3/mU0I9L2p2UFg26k4/at0v8OG6uFuuduA1vp8uWAiEA7MH9+sPSJ6fummirtHvTbceZmoQqzz0V6aBLIdlP2Dg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":959921},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./testing":{"types":"./dist/testing/index.d.ts","import":"./dist/testing/index.js"}},"gitHead":"45f550388ad3243b44a0c55acee0004baad4e91e","scripts":{"dev":"tsc --watch","test":"vitest run","build":"tsc","benchmark":"npx tsx scripts/benchmark.ts","typecheck":"tsc --noEmit","test:watch":"vitest"},"_npmUser":{"name":"aid-on","email":"hiromi.motodera@aid-on.org"},"_npmVersion":"10.8.2","description":"EmbersM - Cloudflare Native Memory System with 5-Layer Architecture","directories":{},"_nodeVersion":"20.19.6","dependencies":{"@aid-on/unillm":"^0.5.3"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.0.0","typescript":"^5.0.0","@cloudflare/workers-types":"^4.20241127.0"},"_npmOperationalInternal":{"tmp":"tmp/embersm_2.0.2_1771343159995_0.03147568480907359","host":"s3://npm-registry-packages-npm-production"}},"2.0.4":{"name":"@aid-on/embersm","version":"2.0.4","description":"EmbersM - Cloudflare Native Memory System with 5-Layer Architecture","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts"},"./testing":{"import":"./dist/testing/index.js","types":"./dist/testing/index.d.ts"}},"scripts":{"build":"tsc","dev":"tsc --watch","typecheck":"tsc --noEmit","test":"vitest run","test:watch":"vitest","benchmark":"npx tsx scripts/benchmark.ts"},"keywords":["cloudflare","workers","d1","kv","vectorize","memory","llm","ai"],"author":{"name":"Aid-On"},"license":"MIT","dependencies":{"@aid-on/unillm":"^0.5.5"},"devDependencies":{"@cloudflare/workers-types":"^4.20241127.0","typescript":"^5.0.0","vitest":"^2.0.0"},"_id":"@aid-on/embersm@2.0.4","_nodeVersion":"20.19.6","_npmVersion":"10.8.2","dist":{"integrity":"sha512-zzYrA8Uuh3L39/yaV6G3DoOh2pIGIqlRuH2SmPEHbU+TdxAHp+54DNZOCkOtEyh6s0qXia5R6Xc3ckdbaMZazA==","shasum":"6e25a715f70f52fd1e7323cffb1650b10168d8e4","tarball":"https://registry.npmjs.org/@aid-on/embersm/-/embersm-2.0.4.tgz","fileCount":113,"unpackedSize":965081,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC0BHL971FgNXgJ74pbvI3b7GXC6dp8xlyNz+AMOOmnqAIhAIjj9/1CyVPsjYdPiG5xDGUnj88R+DKoccQ+P6l4ed5h"}]},"_npmUser":{"name":"aid-on","email":"hiromi.motodera@aid-on.org"},"directories":{},"maintainers":[{"name":"aid-on","email":"hiromi.motodera@aid-on.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/embersm_2.0.4_1771435081308_0.30363480541585175"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-17T15:20:10.268Z","modified":"2026-02-18T17:18:01.649Z","2.0.1":"2026-02-17T15:20:10.566Z","2.0.2":"2026-02-17T15:46:00.181Z","2.0.4":"2026-02-18T17:18:01.519Z"},"author":{"name":"Aid-On"},"license":"MIT","keywords":["cloudflare","workers","d1","kv","vectorize","memory","llm","ai"],"description":"EmbersM - Cloudflare Native Memory System with 5-Layer Architecture","maintainers":[{"name":"aid-on","email":"hiromi.motodera@aid-on.org"}],"readme":"# @aid-on/embersm\n\n<div align=\"center\">\n\n[![npm version](https://img.shields.io/npm/v/@aid-on/embersm.svg?style=flat-square&color=00DC82)](https://www.npmjs.com/package/@aid-on/embersm)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-3178C6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)\n\n**Cloudflare Workers native 5-layer memory architecture**\n\nProvide long-term memory for LLM agents\n\n**English** | [日本語](README.ja.md)\n\n</div>\n\n## Benchmark Results\n\nEvaluation on the LOCOMO benchmark (100 questions):\n\n| Configuration | Score | vs Mem0 |\n|---------------|-------|---------|\n| **Best (Semantic + Episode)** | **66-75%** | **+25-34%** |\n| 5-Layer (temporal/graph added) | 47-55% | +6-14% |\n\n> Mem0 baseline: 41%\n\n### Best Configuration\n\nThe simplest configuration achieved the highest scores:\n\n```\nSemantic Search (50 results) + Episode Keyword (15) + Recent (10)\n```\n\nThe 5-layer architecture (with Temporal/Graph) introduces noise and is not recommended at this time.\n\n## Architecture\n\n### Best Configuration (Recommended)\n\n```mermaid\nflowchart TB\n    Query[\"Query\"] --> Semantic & Keyword & Recent\n\n    Semantic[\"Semantic Search<br/>(Vectorize)<br/>50 results\"]\n    Keyword[\"Episode Keyword<br/>(D1)<br/>15 results\"]\n    Recent[\"Episode Recent<br/>(D1)<br/>10 results\"]\n\n    Semantic & Keyword & Recent --> LLM[\"LLM Response\"]\n```\n\n### 5-Layer Architecture (Experimental)\n\n> Temporal/Graph layers introduce noise at this stage; the best configuration above is recommended\n\n```\nQuery Router → Semantic / Temporal / Graph / Episode → Fusion → LLM\n```\n\n### Layer Roles\n\n| Layer | Storage | Purpose | Latency |\n|-------|---------|---------|---------|\n| **Flash** | KV | Recent context (last few turns) | ~1ms |\n| **Episode** | D1 | Full conversation history | ~5ms |\n| **Semantic** | Vectorize | Vector similarity search | ~10ms |\n| **Temporal** | D1 | Time-indexed event management | ~5ms |\n| **Graph** | D1 | Facts & relationships in Prolog format | ~5ms |\n\n## Installation\n\n```bash\nnpm install @aid-on/embersm\n```\n\n## Usage\n\n### Basic Usage\n\n```typescript\nimport { createEmbersM } from \"@aid-on/embersm\";\n\n// Initialize from Cloudflare Workers env\nconst memory = createEmbersM(env);\n\n// Record a conversation turn\nawait memory.extract(\n  userId,\n  threadId,\n  userMessage,\n  assistantResponse\n);\n\n// Query memory\nconst context = await memory.query(userId, question);\n```\n\n### D1 Migrations\n\n```typescript\nimport {\n  EPISODE_MIGRATION,\n  SEMANTIC_MIGRATION,\n  TEMPORAL_MIGRATION,\n  GRAPH_MIGRATION,\n} from \"@aid-on/embersm\";\n\n// Create tables in D1\nawait env.DB.exec(EPISODE_MIGRATION);\nawait env.DB.exec(SEMANTIC_MIGRATION);\nawait env.DB.exec(TEMPORAL_MIGRATION);\nawait env.DB.exec(GRAPH_MIGRATION);\n```\n\n### Environment Configuration\n\n`wrangler.toml`:\n\n```toml\n[[kv_namespaces]]\nbinding = \"KV\"\nid = \"your-kv-namespace-id\"\n\n[[d1_databases]]\nbinding = \"DB\"\ndatabase_name = \"your-db-name\"\ndatabase_id = \"your-db-id\"\n\n[[vectorize]]\nbinding = \"VECTORIZE\"\nindex_name = \"your-index-name\"\n\n[ai]\nbinding = \"AI\"\n```\n\n## API\n\n### `createEmbersM(env: EmbersMEnv): EmbersM`\n\nMain factory function.\n\n```typescript\ninterface EmbersM {\n  // Extract and store memories from a conversation turn\n  extract(\n    userId: string,\n    threadId: string,\n    userMessage: string,\n    assistantResponse: string\n  ): Promise<MemoryUpdates>;\n\n  // Query memory and generate context\n  query(userId: string, question: string): Promise<MemoryContext>;\n\n  // Run D1 migrations\n  migrate(): Promise<void>;\n}\n```\n\n### Memory Context\n\n```typescript\ninterface MemoryContext {\n  flash: string[];      // Recent conversation\n  episodes: string[];   // Related past conversations\n  semantic: string[];   // Semantically similar content\n  temporal: string[];   // Time-related events\n  graph: string[];      // Relationships & facts\n  fusedContext: string;  // Fused context string\n}\n```\n\n## Testing\n\n```bash\n# Unit tests\nnpm test\n\n# Benchmarks (mock environment)\nnpm run benchmark\n```\n\n## Technical Highlights\n\n### High-Accuracy Temporal Memory (94.4%)\n\n- Automatically extracts datetime information from conversations\n- Resolves relative dates (\"yesterday\", \"last week\") based on conversation timestamp\n- Classifies event types (one-time / recurring / duration)\n\n### Semantic Search\n\n- Fast vector search via Cloudflare Vectorize\n- 768-dimensional embeddings with BGE-base-en-v1.5 model\n- Indexes both user and assistant messages\n\n### Graph Memory\n\n- Stores facts in Prolog format: `predicate(subject, object)`\n- Example: `painted(Melanie, lake sunrise)`, `attended(Caroline, LGBTQ support group)`\n- Supports inference queries\n\n## License\n\nMIT\n","readmeFilename":"README.md"}