engram-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CONTRIBUTING.md +65 -0
  2. package/Dockerfile +21 -0
  3. package/EVAL-FRAMEWORK.md +70 -0
  4. package/EVAL.md +127 -0
  5. package/LICENSE +17 -0
  6. package/README.md +309 -0
  7. package/ROADMAP.md +113 -0
  8. package/deploy/fly.toml +26 -0
  9. package/dist/auto-ingest.d.ts +3 -0
  10. package/dist/auto-ingest.d.ts.map +1 -0
  11. package/dist/auto-ingest.js +334 -0
  12. package/dist/auto-ingest.js.map +1 -0
  13. package/dist/brief.d.ts +45 -0
  14. package/dist/brief.d.ts.map +1 -0
  15. package/dist/brief.js +183 -0
  16. package/dist/brief.js.map +1 -0
  17. package/dist/claude-watcher.d.ts +3 -0
  18. package/dist/claude-watcher.d.ts.map +1 -0
  19. package/dist/claude-watcher.js +385 -0
  20. package/dist/claude-watcher.js.map +1 -0
  21. package/dist/cli.d.ts +3 -0
  22. package/dist/cli.d.ts.map +1 -0
  23. package/dist/cli.js +764 -0
  24. package/dist/cli.js.map +1 -0
  25. package/dist/embeddings.d.ts +42 -0
  26. package/dist/embeddings.d.ts.map +1 -0
  27. package/dist/embeddings.js +145 -0
  28. package/dist/embeddings.js.map +1 -0
  29. package/dist/eval.d.ts +2 -0
  30. package/dist/eval.d.ts.map +1 -0
  31. package/dist/eval.js +281 -0
  32. package/dist/eval.js.map +1 -0
  33. package/dist/extract.d.ts +11 -0
  34. package/dist/extract.d.ts.map +1 -0
  35. package/dist/extract.js +139 -0
  36. package/dist/extract.js.map +1 -0
  37. package/dist/hosted.d.ts +3 -0
  38. package/dist/hosted.d.ts.map +1 -0
  39. package/dist/hosted.js +144 -0
  40. package/dist/hosted.js.map +1 -0
  41. package/dist/index.d.ts +11 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +7 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/ingest.d.ts +28 -0
  46. package/dist/ingest.d.ts.map +1 -0
  47. package/dist/ingest.js +192 -0
  48. package/dist/ingest.js.map +1 -0
  49. package/dist/mcp.d.ts +3 -0
  50. package/dist/mcp.d.ts.map +1 -0
  51. package/dist/mcp.js +349 -0
  52. package/dist/mcp.js.map +1 -0
  53. package/dist/server.d.ts +17 -0
  54. package/dist/server.d.ts.map +1 -0
  55. package/dist/server.js +515 -0
  56. package/dist/server.js.map +1 -0
  57. package/dist/store.d.ts +87 -0
  58. package/dist/store.d.ts.map +1 -0
  59. package/dist/store.js +548 -0
  60. package/dist/store.js.map +1 -0
  61. package/dist/types.d.ts +204 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +77 -0
  64. package/dist/types.js.map +1 -0
  65. package/dist/vault.d.ts +116 -0
  66. package/dist/vault.d.ts.map +1 -0
  67. package/dist/vault.js +1234 -0
  68. package/dist/vault.js.map +1 -0
  69. package/package.json +61 -0
@@ -0,0 +1,65 @@
1
+ # Contributing to Engram
2
+
3
+ Thanks for wanting to contribute! Engram is early-stage and moving fast — contributions are welcome.
4
+
5
+ ## Getting Started
6
+
7
+ ```bash
8
+ git clone https://github.com/tstockham96/engram.git
9
+ cd engram
10
+ npm install
11
+ npm test # Run all tests (59 and counting)
12
+ npm run lint # Type check
13
+ ```
14
+
15
+ ## Development
16
+
17
+ ```bash
18
+ npm run cli -- remember "test memory" # Test CLI
19
+ npm run cli -- recall "test" # Test recall
20
+ npm run serve # Start REST API on :3800
21
+ npm test # Run tests
22
+ ```
23
+
24
+ ## What We Need Help With
25
+
26
+ - **Python SDK** — thin client wrapping the REST API
27
+ - **Framework integrations** — OpenClaw, LangChain, CrewAI, AutoGen adapters
28
+ - **Consolidation improvements** — smarter rule-based consolidation, better LLM prompts
29
+ - **Embedding providers** — Voyage, Cohere, local models
30
+ - **Documentation** — examples, tutorials, guides
31
+ - **Testing** — edge cases, stress tests, benchmarks
32
+
33
+ ## Pull Request Process
34
+
35
+ 1. Fork the repo and create a branch from `main`
36
+ 2. Add tests for any new functionality
37
+ 3. Make sure all tests pass (`npm test`)
38
+ 4. Make sure types check (`npm run lint`)
39
+ 5. Keep PRs focused — one feature or fix per PR
40
+ 6. Write a clear description of what and why
41
+
42
+ ## Code Style
43
+
44
+ - TypeScript, strict mode
45
+ - Use Zod for input validation
46
+ - Tests in `src/__tests__/` using Vitest
47
+ - No external runtime dependencies without discussion (we're at 4 deps total — let's keep it lean)
48
+
49
+ ## Architecture Decisions
50
+
51
+ - **Zero-dependency server**: The REST API uses Node's built-in `http` module, not Express/Hono/Fastify. This is intentional — fewer deps = fewer supply chain risks.
52
+ - **SQLite**: Single-file database, no server setup. sqlite-vec for vector search.
53
+ - **Local-first**: Everything runs on your machine by default. Cloud is opt-in.
54
+
55
+ ## Reporting Issues
56
+
57
+ Open an issue on GitHub. Include:
58
+ - What you expected
59
+ - What happened instead
60
+ - Steps to reproduce
61
+ - Node version, OS
62
+
63
+ ## License
64
+
65
+ By contributing, you agree that your contributions will be licensed under the MIT License.
package/Dockerfile ADDED
@@ -0,0 +1,21 @@
1
+ FROM node:20-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install build dependencies for better-sqlite3 native addon
6
+ RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
7
+
8
+ COPY package.json package-lock.json* ./
9
+ RUN npm ci
10
+
11
+ COPY . .
12
+ RUN npm run build
13
+ RUN npm prune --production
14
+
15
+ # Persistent data volume mount point
16
+ RUN mkdir -p /data
17
+
18
+ EXPOSE 3800
19
+
20
+ # Use hosted multi-tenant server
21
+ CMD ["node", "dist/hosted.js"]
@@ -0,0 +1,70 @@
1
+ # Engram Eval Framework
2
+
3
+ ## The Question
4
+ Does Engram make an AI agent meaningfully better at its job compared to flat-file memory (MEMORY.md + daily notes + vector search)?
5
+
6
+ ## What "Better" Means
7
+ 1. **Fewer repeated questions** — Agent doesn't ask things it should already know
8
+ 2. **Surprise recall** — Agent surfaces relevant context the human didn't prompt for
9
+ 3. **Contradiction prevention** — Agent catches itself before giving conflicting info
10
+ 4. **Reduced curation toil** — Human spends less time maintaining memory files
11
+ 5. **Token efficiency** — Same or better context quality with fewer tokens
12
+
13
+ ## Daily Automated Eval (runs via cron)
14
+
15
+ ### Recall Accuracy Test
16
+ Run a fixed set of 20 questions with known answers. Score: % of correct top-3 results.
17
+ Track over time as memories accumulate and consolidation runs.
18
+
19
+ Questions should cover:
20
+ - Factual (What is Thomas's job? → Senior PM at BambooHR)
21
+ - Procedural (How do I deploy the site? → cd engram-site && npx vercel --prod)
22
+ - Relational (Who are Engram's competitors? → Mem0, Zep, Letta, LangMem)
23
+ - Temporal (What did we build yesterday? → depends on date)
24
+ - Personal preference (How does Thomas like communication? → direct, no fluff)
25
+
26
+ ### Token Comparison
27
+ - Measure: bytes of MEMORY.md + loaded daily files vs Engram briefing() output
28
+ - Track both as they grow over time
29
+ - Calculate: tokens saved per request if using Engram briefing instead of file dump
30
+
31
+ ### Consolidation Quality
32
+ After each consolidation run, evaluate:
33
+ - Are new semantic memories factually accurate?
34
+ - Are they non-redundant with existing memories?
35
+ - Do they capture something the raw episodes didn't explicitly state? (insight generation)
36
+
37
+ ### Memory Freshness
38
+ - Count: memories with status "pending" that are actually fulfilled
39
+ - Count: memories that contradict each other
40
+ - Track whether lifecycle management is happening
41
+
42
+ ## Weekly Human Eval
43
+
44
+ Thomas rates (1-5) on a weekly basis:
45
+ 1. Did the agent remember things it should have?
46
+ 2. Did the agent forget things it shouldn't have?
47
+ 3. Did the agent surprise you with relevant context?
48
+ 4. Was there less repetitive Q&A this week vs last?
49
+
50
+ ## Success Criteria
51
+
52
+ ### Engram is WORKING when:
53
+ - Recall accuracy consistently >80% on the fixed question set
54
+ - Agent surfaces relevant context Thomas didn't ask for at least 2x/week
55
+ - Agent catches a contradiction or stale commitment at least 1x/week
56
+ - MEMORY.md stops growing because Engram captures what it used to
57
+
58
+ ### Engram is NOT WORKING when:
59
+ - MEMORY.md remains the primary useful memory source
60
+ - Recall accuracy stays flat or degrades as memories accumulate
61
+ - Consolidation produces redundant summaries instead of insights
62
+ - Token cost increases without quality improvement
63
+
64
+ ## Scale Milestones
65
+ Track value at each milestone:
66
+ - 220 memories (current) — baseline
67
+ - 500 memories — first consolidation cycle quality check
68
+ - 1,000 memories — graph density threshold
69
+ - 5,000 memories — flat-file memory should be breaking down by here
70
+ - 10,000+ memories — Engram must be clearly better or it's not working
package/EVAL.md ADDED
@@ -0,0 +1,127 @@
1
+ # Engram Self-Eval: Agent Performance With vs Without Memory
2
+
3
+ *Designed Feb 16, 2026. Running over 72 hours.*
4
+
5
+ ## Hypothesis
6
+
7
+ An AI agent with Engram memory performs measurably better at tasks requiring context from prior conversations than the same agent without it.
8
+
9
+ ## Design
10
+
11
+ **Subject:** Jarvis (Claude Opus via OpenClaw) — the same agent, tested in two conditions:
12
+
13
+ 1. **Baseline (no Engram):** Agent uses only OpenClaw's default memory system (MEMORY.md flat files + vector search over markdown)
14
+ 2. **Engram-enhanced:** Agent uses Engram vault (auto-ingest, semantic recall, consolidation, knowledge graph)
15
+
16
+ **Interface:** REST API + auto-ingest pipeline — the same way any OpenClaw user would run it. No MCP needed. Just the Engram server running alongside the agent, auto-ingesting conversations, and serving recall queries via HTTP.
17
+
18
+ **Method:** Over 72 hours of normal use with Thomas, I'll log specific moments where memory matters. At each moment, I'll:
19
+ 1. Query Engram's REST API for relevant context
20
+ 2. Note what my flat-file memory (MEMORY.md + vector search) would have returned
21
+ 3. Compare the quality of recall
22
+
23
+ This isn't a synthetic benchmark — it's real-world usage on the same setup any OpenClaw user would have. More ecologically valid than a lab test.
24
+
25
+ ## Metrics
26
+
27
+ ### 1. Recall Accuracy (quantitative)
28
+ At each memory-dependent moment, score:
29
+ - **Hit**: Correct, relevant memory surfaced → 1 point
30
+ - **Partial**: Related but incomplete or slightly wrong → 0.5 points
31
+ - **Miss**: Relevant memory existed but wasn't recalled → 0 points
32
+ - **Hallucination**: Confidently wrong memory → -1 point
33
+
34
+ Score both systems independently. Compare hit rates.
35
+
36
+ ### 2. Context Richness (qualitative, 1-5 scale)
37
+ When recalling context, rate the depth:
38
+ - 1: No useful context
39
+ - 2: Basic facts only ("Thomas works at BambooHR")
40
+ - 3: Facts + preferences ("Thomas works at BambooHR, prefers direct communication")
41
+ - 4: Facts + preferences + history ("...and he pivoted from Kin to Engram because thin-margin hosting has no moat")
42
+ - 5: Full situational awareness including decisions, reasoning, and emotional context
43
+
44
+ ### 3. Consolidation Quality (qualitative)
45
+ After each consolidation run:
46
+ - How many genuinely useful semantic memories were created?
47
+ - Were any contradictions correctly identified?
48
+ - Were any stale memories correctly superseded?
49
+ - Did the knowledge graph capture meaningful relationships?
50
+
51
+ ### 4. Time-to-Context (qualitative)
52
+ How quickly does the agent reach useful context?
53
+ - Engram: single API call, structured results
54
+ - Flat files: grep through markdown, parse manually, hope the right section is there
55
+
56
+ ### 5. "Surprise" Moments
57
+ Log any moment where Engram surfaced context the agent wouldn't have thought to look for. These are the moments that demonstrate proactive value.
58
+
59
+ ## Test Scenarios
60
+
61
+ Run these naturally over the 72-hour period:
62
+
63
+ ### Day 1 (Feb 16-17): Foundation
64
+ - [x] Seed vault from existing conversations
65
+ - [x] Run auto-ingest on current session
66
+ - [x] First consolidation run
67
+ - [ ] Evening: Ask about decisions made in morning (test same-day recall)
68
+ - [ ] Evening: Run consolidation, note what it produces
69
+
70
+ ### Day 2 (Feb 17-18): Cross-Session Recall
71
+ - [ ] Morning: Can Engram recall yesterday's context without being told?
72
+ - [ ] Ask about pricing decisions (tests semantic memory from consolidation)
73
+ - [ ] Ask about Thomas's preferences (tests across multiple conversations)
74
+ - [ ] Work on a task that references past decisions — compare with/without
75
+ - [ ] Run consolidation, note cross-day patterns
76
+
77
+ ### Day 3 (Feb 18-19): Stress Tests
78
+ - [ ] Ask a question that requires connecting 3+ separate memories
79
+ - [ ] Ask about something mentioned once 3 days ago (tests decay/persistence)
80
+ - [ ] Introduce contradictory information — does consolidation catch it?
81
+ - [ ] Ask an ambiguous question — does the knowledge graph help disambiguate?
82
+ - [ ] Final consolidation + full analysis
83
+
84
+ ## Logging Format
85
+
86
+ Each test moment gets logged as:
87
+
88
+ ```markdown
89
+ ### Test #N: [Description]
90
+ **Time:** YYYY-MM-DD HH:MM
91
+ **Query:** "What I asked / needed to recall"
92
+ **Engram result:** [what Engram returned]
93
+ **Flat-file result:** [what MEMORY.md search would return]
94
+ **Recall accuracy:** Hit / Partial / Miss / Hallucination (for each system)
95
+ **Context richness:** X/5 (for each system)
96
+ **Notes:** [observations]
97
+ ```
98
+
99
+ ## Success Criteria
100
+
101
+ Engram is **better** if:
102
+ - Recall accuracy is ≥20% higher than flat files
103
+ - Context richness averages ≥1 point higher
104
+ - At least 3 "surprise" moments where Engram surfaced unexpected relevant context
105
+ - Consolidation produces ≥10 genuinely useful semantic memories over 72 hours
106
+ - Zero hallucinated memories (confidence should prevent false recalls)
107
+
108
+ Engram is **equivalent** if scores are within 10%. Even equivalence is a win if Engram requires less manual effort (no hand-editing MEMORY.md).
109
+
110
+ Engram **fails** if:
111
+ - Recall accuracy is lower than flat files
112
+ - Consolidation produces mostly noise
113
+ - The agent performs worse on tasks due to bad memory surfacing
114
+
115
+ ## Results
116
+
117
+ *Will be filled in as the eval progresses.*
118
+
119
+ ### Summary (to be completed Feb 19)
120
+ - Total test moments:
121
+ - Engram recall accuracy:
122
+ - Flat-file recall accuracy:
123
+ - Engram context richness avg:
124
+ - Flat-file context richness avg:
125
+ - Surprise moments:
126
+ - Semantic memories from consolidation:
127
+ - Verdict:
package/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ GNU AFFERO GENERAL PUBLIC LICENSE
2
+ Version 3, 19 November 2007
3
+
4
+ Copyright (C) 2026 Thomas Stockham
5
+
6
+ This program is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Affero General Public License as published
8
+ by the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Affero General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Affero General Public License
17
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
package/README.md ADDED
@@ -0,0 +1,309 @@
1
+ # 🧠 Engram
2
+
3
+ **Universal memory protocol for AI agents.**
4
+
5
+ AI agents have amnesia. Every session starts blank. Engram fixes this — a memory protocol with a REST API, knowledge graph, and consolidation engine that turns raw episodes into structured knowledge. Think of it as giving your agent a hippocampus.
6
+
7
+ ## Why
8
+
9
+ Every AI agent framework bolts on memory as an afterthought — a flat file, a vector DB, maybe a conversation log. None of them solve the real problem:
10
+
11
+ - **Amnesia**: Agents forget everything between sessions
12
+ - **No consolidation**: Raw episodes pile up, never distilled into knowledge
13
+ - **No relationships**: Memories exist in isolation, no graph of connections
14
+ - **No decay**: Everything is equally important forever
15
+ - **No portability**: Memory locked into one framework
16
+
17
+ Engram is a protocol, not a plugin. It works with any agent, any framework, any language.
18
+
19
+ ## Quick Start (60 seconds)
20
+
21
+ ### 1. Install & run
22
+
23
+ ```bash
24
+ npm install engram-sdk
25
+ export GEMINI_API_KEY=your-key-here # Get one free at ai.google.dev
26
+ npx engram-serve
27
+ # → Engram listening on http://localhost:3800
28
+ ```
29
+
30
+ That's it. Engram is running with vector search, auto-extraction, and consolidation.
31
+
32
+ > **No Gemini key?** Engram works without one — you just won't get embeddings or LLM-powered features. Or use our [hosted API](https://engram-site.vercel.app) and skip setup entirely.
33
+
34
+ ### 2. Remember & recall
35
+
36
+ ```bash
37
+ # Store a memory
38
+ curl -X POST http://localhost:3800/v1/memories \
39
+ -H 'Content-Type: application/json' \
40
+ -d '{"content": "User prefers dark mode and concise answers"}'
41
+
42
+ # Recall relevant memories
43
+ curl -X POST http://localhost:3800/v1/memories/recall \
44
+ -H 'Content-Type: application/json' \
45
+ -d '{"query": "user preferences", "context": "settings page"}'
46
+
47
+ # Consolidate (distill episodes into knowledge)
48
+ curl -X POST http://localhost:3800/v1/consolidate
49
+ ```
50
+
51
+ ### TypeScript SDK
52
+
53
+ ```typescript
54
+ import { Vault } from 'engram-sdk';
55
+
56
+ const vault = new Vault();
57
+
58
+ // Remember
59
+ await vault.remember('User prefers dark mode and concise answers');
60
+ await vault.remember('User is training for a marathon in April');
61
+
62
+ // Recall
63
+ const memories = await vault.recall('What are the user preferences?');
64
+ console.log(memories);
65
+
66
+ // Consolidate
67
+ await vault.consolidate();
68
+ vault.close();
69
+ ```
70
+
71
+ ### Python (via REST API)
72
+
73
+ ```python
74
+ import requests
75
+
76
+ API = "http://localhost:3800/v1"
77
+
78
+ # Store a memory
79
+ requests.post(f"{API}/memories", json={
80
+ "content": "User prefers dark mode and concise answers",
81
+ "entities": ["User"],
82
+ "topics": ["preferences"],
83
+ "salience": 0.8,
84
+ })
85
+
86
+ # Recall
87
+ memories = requests.get(f"{API}/memories/recall", params={"context": "user preferences"}).json()
88
+ ```
89
+
90
+ Python SDK coming soon. The REST API works with any language — no SDK required.
91
+
92
+ ## REST API Reference
93
+
94
+ Start the server:
95
+
96
+ ```bash
97
+ # Environment variables
98
+ ENGRAM_OWNER=my-agent # Vault owner ID (required)
99
+ ENGRAM_DB_PATH=./my.db # Database path (optional)
100
+ ENGRAM_PORT=3800 # Port (default: 3800)
101
+ ENGRAM_HOST=127.0.0.1 # Host (default: 127.0.0.1)
102
+ ENGRAM_LLM_PROVIDER=anthropic # LLM for consolidation (optional)
103
+ ENGRAM_LLM_API_KEY=sk-... # LLM API key (optional)
104
+
105
+ npx engram serve
106
+ # or
107
+ npm run serve
108
+ ```
109
+
110
+ ### Endpoints
111
+
112
+ | Method | Path | Description |
113
+ |--------|------|-------------|
114
+ | `POST` | `/v1/memories` | Store a memory |
115
+ | `GET` | `/v1/memories/recall?context=...` | Recall memories (simple) |
116
+ | `POST` | `/v1/memories/recall` | Recall memories (complex query) |
117
+ | `DELETE` | `/v1/memories/:id` | Forget a memory |
118
+ | `GET` | `/v1/memories/:id/neighbors` | Graph traversal |
119
+ | `POST` | `/v1/connections` | Connect two memories |
120
+ | `POST` | `/v1/consolidate` | Run consolidation engine |
121
+ | `GET` | `/v1/entities` | List tracked entities |
122
+ | `GET` | `/v1/stats` | Vault statistics |
123
+ | `POST` | `/v1/export` | Export full vault as JSON |
124
+ | `GET` | `/health` | Health check |
125
+
126
+ ### POST /v1/memories
127
+
128
+ ```json
129
+ {
130
+ "content": "User prefers TypeScript over JavaScript",
131
+ "type": "episodic", // episodic | semantic | procedural
132
+ "entities": ["User", "TypeScript", "JavaScript"],
133
+ "topics": ["preferences", "engineering"],
134
+ "salience": 0.8, // 0-1, importance
135
+ "confidence": 0.9, // 0-1, certainty
136
+ "visibility": "owner_agents" // private | owner_agents | shared | public
137
+ }
138
+ ```
139
+
140
+ ### GET /v1/memories/recall
141
+
142
+ Query params: `context` (required), `entities`, `topics`, `types`, `limit`
143
+
144
+ ### POST /v1/memories/recall
145
+
146
+ ```json
147
+ {
148
+ "context": "project status",
149
+ "entities": ["Engram"],
150
+ "topics": ["engineering"],
151
+ "types": ["semantic"],
152
+ "minSalience": 0.5,
153
+ "limit": 10
154
+ }
155
+ ```
156
+
157
+ ### POST /v1/connections
158
+
159
+ ```json
160
+ {
161
+ "sourceId": "memory-uuid-1",
162
+ "targetId": "memory-uuid-2",
163
+ "type": "supports", // supports | contradicts | elaborates | supersedes | causes | caused_by | ...
164
+ "strength": 0.7
165
+ }
166
+ ```
167
+
168
+ ## Core Concepts
169
+
170
+ ### Memory Types
171
+
172
+ | Type | What | Example |
173
+ |------|------|---------|
174
+ | **Episodic** | Events, conversations, observations | "User asked about React performance" |
175
+ | **Semantic** | Facts, knowledge, patterns | "User prefers TypeScript over JavaScript" |
176
+ | **Procedural** | How-to knowledge, workflows | "To deploy: run tests → build → push to main" |
177
+
178
+ ### The Memory Lifecycle
179
+
180
+ ```
181
+ Episode → Remember → Store → Recall → Consolidate → Knowledge
182
+
183
+ Decay / Archive
184
+ ```
185
+
186
+ 1. **Remember**: Raw episodes go in with metadata (entities, topics, salience)
187
+ 2. **Recall**: Hybrid retrieval — entity matching, topic matching, semantic search, recency
188
+ 3. **Consolidate**: The "sleep cycle" — episodes get distilled into semantic memories, entities get discovered, connections form, contradictions surface
189
+ 4. **Decay**: Memories naturally fade unless reinforced by access. High-salience memories resist decay.
190
+
191
+ ### Memory Graph
192
+
193
+ Memories aren't flat — they're a graph. Edges connect related memories:
194
+
195
+ - `supports` / `contradicts` — agreement or conflict
196
+ - `elaborates` — adds detail
197
+ - `supersedes` — replaces outdated info
198
+ - `causes` / `caused_by` — causal chains
199
+ - `temporal_next` — sequential events
200
+ - `derived_from` — consolidation lineage
201
+
202
+ ### Entities
203
+
204
+ Engram automatically tracks entities (people, places, projects, concepts) across memories. Entity frequency and co-occurrence drive importance scores and recall relevance.
205
+
206
+ ## LLM-Powered Consolidation
207
+
208
+ For the full consolidation experience, configure an LLM:
209
+
210
+ ```typescript
211
+ const vault = new Vault({
212
+ owner: 'my-agent',
213
+ llm: {
214
+ provider: 'anthropic',
215
+ apiKey: process.env.ANTHROPIC_API_KEY!,
216
+ model: 'claude-3-5-haiku-20241022',
217
+ },
218
+ });
219
+ ```
220
+
221
+ Or via environment variables with the REST API:
222
+
223
+ ```bash
224
+ ENGRAM_LLM_PROVIDER=anthropic ENGRAM_LLM_API_KEY=sk-... npx engram serve
225
+ ```
226
+
227
+ The LLM analyzes episodes and extracts:
228
+ - **Semantic memories**: General facts and patterns
229
+ - **Entities**: People, places, projects with properties
230
+ - **Contradictions**: Conflicting information
231
+ - **Connections**: How episodes relate to each other
232
+
233
+ ## CLI
234
+
235
+ ```bash
236
+ npx engram remember "User prefers React over Vue"
237
+ npx engram recall "frontend preferences"
238
+ npx engram stats
239
+ npx engram entities
240
+ npx engram consolidate
241
+ npx engram export > backup.json
242
+ npx engram repl # Interactive mode
243
+ npx engram serve # Start REST API server
244
+ ```
245
+
246
+ ## Architecture
247
+
248
+ ```
249
+ ┌─────────────────────────────────────────────────┐
250
+ │ REST API Server │
251
+ │ POST /v1/memories · GET /v1/memories/recall · … │
252
+ ├─────────────────────────────────────────────────┤
253
+ │ Vault API │
254
+ │ remember() · recall() · consolidate() · forget() │
255
+ ├─────────────────────────────────────────────────┤
256
+ │ Retrieval Engine │
257
+ │ Entity match · Topic match · Vector search · FTS │
258
+ ├─────────────────────────────────────────────────┤
259
+ │ Consolidation Engine │
260
+ │ Rule-based │ LLM-powered (Anthropic/OpenAI) │
261
+ ├─────────────────────────────────────────────────┤
262
+ │ SQLite Storage Layer │
263
+ │ Memories · Edges · Entities · Embeddings │
264
+ └─────────────────────────────────────────────────┘
265
+ ```
266
+
267
+ **Open source**: Fully MIT licensed. Memory is sensitive data — you should be able to see exactly what happens with it. Self-host, fork, contribute, or use the hosted API for production.
268
+
269
+ **Portable**: Export your entire vault as JSON. Import it elsewhere. Your agent's memory belongs to you.
270
+
271
+ ## Comparison
272
+
273
+ | Feature | Engram | Mem0 | Zep | Letta/MemGPT |
274
+ |---------|--------|------|-----|-------------|
275
+ | Spreading activation | ✅ | ❌ | ❌ | ❌ |
276
+ | LLM consolidation | ✅ | ❌ | ❌ | Partial |
277
+ | Knowledge graph | ✅ | ✅ (graph memory) | ✅ | ❌ |
278
+ | Entity tracking | ✅ | ✅ | ✅ | ❌ |
279
+ | Memory decay | ✅ | ❌ | ❌ | ❌ |
280
+ | REST API | ✅ | ✅ | ✅ | ✅ |
281
+ | Local-first | ✅ | Cloud-default | Cloud-default | ✅ |
282
+ | Language-agnostic | ✅ | Python-first | Python-first | Python-first |
283
+ | Source-available | ✅ | Partial | Partial | ✅ |
284
+
285
+ ## Roadmap
286
+
287
+ - [x] TypeScript SDK
288
+ - [x] REST API server
289
+ - [x] sqlite-vec vector search
290
+ - [x] LLM-powered consolidation
291
+ - [x] CLI with REPL
292
+ - [ ] Hosted service (api.engram.ai)
293
+ - [ ] Python SDK
294
+ - [ ] Framework integrations (OpenClaw, LangChain, CrewAI)
295
+ - [ ] Protocol spec (open standard)
296
+ - [ ] Multi-agent vault sharing
297
+ - [ ] Conflict resolution across agents
298
+
299
+ ## Contributing
300
+
301
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
302
+
303
+ ## License
304
+
305
+ MIT. See [LICENSE](LICENSE) for details.
306
+
307
+ ---
308
+
309
+ *Built by [Thomas Stockham](https://tstockham.com). Engram is the memory layer the AI agent ecosystem is missing.*