mengram-ai
v2.22.0
Published
Human-like memory for AI — auto-save, auto-recall, cognitive profile. Claude Code hooks, MCP server (29 tools), semantic/episodic/procedural memory. Free Mem0 alternative.
Maintainers
Readme
mengram-ai
JavaScript / TypeScript SDK for Mengram — Human-like memory for AI with 3 memory types: semantic, episodic, and procedural.
Install
npm install mengram-aiQuick Start
const { MengramClient } = require('mengram-ai');
const m = new MengramClient('om-your-api-key');
// Add memories — auto-extracts facts, events, workflows
await m.add([
{ role: 'user', content: 'Fixed the auth bug. My process: check logs, reproduce locally, fix and deploy.' },
]);
// Semantic search (classic)
const results = await m.search('auth issues');
// Episodic — what happened?
const events = await m.episodes({ query: 'auth bug' });
// → [{summary: "Fixed auth bug", outcome: "Resolved", participants: [...]}]
// Procedural — how to do it?
const procs = await m.procedures({ query: 'debug' });
// → [{name: "Debug process", steps: [...], success_count: 3}]
// Unified search — all 3 types at once
const all = await m.searchAll('deployment issues');
// → { semantic: [...], episodic: [...], procedural: [...] }
// Procedure feedback — AI learns what works
await m.procedureFeedback(procId, { success: true });
// Experience-driven evolution — procedure improves on failure
await m.procedureFeedback(procId, {
success: false, context: 'OOM on step 3', failedAtStep: 3
});
// View procedure version history
const history = await m.procedureHistory(procId);
// → { versions: [v1, v2, v3], evolution_log: [...] }
// Cognitive Profile — instant personalization
const profile = await m.getProfile('ali');
// → { system_prompt: "You are talking to Ali, a developer..." }TypeScript
import { MengramClient, SearchResult, Episode, Procedure, UnifiedSearchResult, ProcedureHistoryResult } from 'mengram-ai';
const m = new MengramClient('om-...');
const results: SearchResult[] = await m.search('preferences');
const events: Episode[] = await m.episodes({ query: 'deployment' });
const procs: Procedure[] = await m.procedures({ query: 'release' });
const all: UnifiedSearchResult = await m.searchAll('issues');Import Existing Data
Kill the cold-start problem — import ChatGPT, Obsidian, or text files (Node.js only, requires jszip for ChatGPT):
// ChatGPT export
npm install jszip // one-time dependency
await m.importChatgpt('~/Downloads/chatgpt-export.zip');
// Obsidian vault
await m.importObsidian('~/Documents/MyVault');
// Text/markdown files
await m.importFiles(['notes.md', 'journal.txt']);
// With progress callback
await m.importChatgpt('export.zip', {
onProgress: (current, total, title) => console.log(`${current}/${total} ${title}`)
});API
| Method | Description |
|--------|-------------|
| Core | |
| add(messages, options?) | Add memories (extracts all 3 types) |
| addText(text, options?) | Add memories from plain text |
| search(query, options?) | Semantic search |
| searchAll(query, options?) | Unified search (all 3 types) |
| getAll(options?) | List all memories |
| getAllFull(options?) | List all memories with full details |
| get(name) | Get specific entity |
| delete(name) | Delete entity |
| stats(options?) | Usage statistics |
| Memory Types | |
| episodes(options?) | Search/list episodic memories |
| procedures(options?) | Search/list procedural memories |
| procedureFeedback(id, options?) | Record success/failure (triggers evolution) |
| procedureHistory(id) | Version history + evolution log |
| procedureEvolution(id) | Evolution log (what changed and why) |
| getProfile(userId?, options?) | Cognitive Profile |
| Memory Management | |
| dedup(options?) | Find and merge duplicate entities |
| dedupAll(options?) | Deduplicate facts across all entities |
| dedupEntity(name, options?) | Deduplicate facts on specific entity |
| merge(source, target, options?) | Merge two entities |
| archiveFact(entity, fact, options?) | Archive a specific fact |
| reindex(options?) | Re-embed all entities |
| fixEntityType(name, type, options?) | Fix entity type classification |
| Search & Discovery | |
| graph(options?) | Get knowledge graph (nodes + edges) |
| timeline(options?) | Search facts by time range |
| feed(options?) | Activity feed |
| Agents & Insights | |
| runAgents(options?) | Run memory agents (curator, connector, digest) |
| agentHistory(options?) | Agent run history |
| agentStatus(options?) | Check which agents are due |
| insights(options?) | AI reflections |
| reflect(options?) | Trigger memory reflection |
| Triggers | |
| getTriggers(options?) | List smart triggers |
| detectTriggers(userId, options?) | Detect triggers for a user |
| processTriggers() | Fire all pending triggers |
| dismissTrigger(id) | Dismiss a trigger |
| Webhooks | |
| createWebhook(url, options?) | Create a webhook |
| listWebhooks() | List all webhooks |
| updateWebhook(id, options?) | Update a webhook |
| deleteWebhook(id) | Delete a webhook |
| Teams | |
| createTeam(name) | Create shared team |
| joinTeam(code) | Join team |
| listTeams() | List your teams |
| shareMemory(entity, teamId) | Share with team |
| unshareMemory(entity, teamId) | Make memory personal again |
| teamMembers(teamId) | List team members |
| leaveTeam(teamId) | Leave a team |
| deleteTeam(teamId) | Delete a team (owner only) |
| Import | |
| importChatgpt(zipPath, options?) | Import ChatGPT export ZIP |
| importObsidian(vaultPath, options?) | Import Obsidian vault |
| importFiles(paths, options?) | Import text/markdown files |
| Billing | |
| getBilling() | Current plan and usage |
| createCheckout(plan) | Create checkout session |
| createPortal() | Manage subscription |
Multi-User Isolation
Building a multi-tenant app? Pass userId to isolate memories per end-user. One API key, many users — each sees only their own data:
// Each userId gets its own isolated memory space
await m.add([{ role: 'user', content: 'I prefer dark mode' }], { userId: 'alice' });
await m.add([{ role: 'user', content: 'I prefer light mode' }], { userId: 'bob' });
const alice = await m.searchAll('preferences', { userId: 'alice' });
// → Only Alice's memories (dark mode)
const bob = await m.searchAll('preferences', { userId: 'bob' });
// → Only Bob's memories (light mode)
const profile = await m.getProfile('alice');
// → Alice's cognitive profileNo userId? Everything works as before — defaults to a single shared memory space.
