Skip to content

lofder/Engram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

19 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Engram

Conquer your AI with personality, not a rulebook. ไปฅๅพทๆœ AIใ€‚

License: MIT MCP Mem0 Qdrant

An engram is the trace a memory leaves in the brain. This project does the same for AI โ€” memory that persists across sessions, stays organized, and cleans up after itself.


English ย |ย  ไธญๆ–‡

English

Why Engram?

You've had this experience: you spend 20 minutes explaining your project setup, coding style, or preferences to an AI assistant. It does exactly what you want. Next morning, new session โ€” it knows nothing. You start over.

So you try the workaround: write it all down in a markdown file. .cursor/rules, AGENTS.md, a system prompt doc โ€” whatever your tool calls it. It works at first. But then:

  • The file keeps growing. Every time the AI gets something wrong, you add another rule.
  • Old instructions conflict with new ones, and you have to go back and reconcile.
  • You realize you're spending more time maintaining the AI's memory than doing actual work.
  • You have multiple projects, multiple agents โ€” and now multiple files to keep in sync.

You've become a full-time memory manager for your AI. That's backwards.

The deeper problem isn't just "AI forgets." It's that the burden of remembering falls entirely on you. You're manually doing what memory should do automatically: deciding what matters, updating when things change, and throwing out what's stale.

Engram flips this. Instead of you maintaining files for the AI, the AI maintains its own memory โ€” structured, scoped, and self-cleaning. It decides what to keep, compresses old information, and forgets what's no longer relevant. You just use it.

Today:     You write rules.md โ†’ AI reads it โ†’ you update rules.md โ†’ repeat forever
Engram:    AI remembers on its own โ†’ compresses over time โ†’ you never maintain a file again

Design Philosophy

1. Let the AI manage its own memory

You don't manually save bookmarks for every webpage you visit. Your brain decides what's worth remembering. Engram works the same way โ€” the AI decides what to store, when to recall, and what to ignore. You just use it naturally; memory happens in the background.

2. Less is more

Returning 50 old memories into every conversation doesn't help โ€” it wastes tokens and confuses the model. Engram keeps memory lean: duplicates are merged, old logs get summarized into compact knowledge, and stale entries fade away automatically. The result is a small, high-quality set of memories that actually improve responses.

3. Important things should last

Not all memories are equal. Your preferences ("always use TypeScript"), lessons learned ("that API has a 5-second timeout"), and key decisions ("we're using PostgreSQL") should never be forgotten. But yesterday's deployment log? That can fade โ€” after being distilled into lasting knowledge first.

MCP Tools

Engram exposes 5 tools via the MCP protocol. Any MCP-compatible client (Cursor, Claude Desktop, custom agents) can call them:

mem0_add โ€” Store a memory

Parameter Type Required Description
content string yes The memory text
scope string yes global, group:xxx, dm, agent:xxx
mem_type string no preference, fact, procedure, lesson, decision, task_log, knowledge
source string no user_direct, agent_output, tool_result, inferred (default: agent_output)
trust string no high, medium, low (default: medium)
context string no Additional context for retrieval
agent string no Caller identity for permission check

Returns: {"results": [...]} on success, {"queued": true, "write_id": "..."} if Mem0 is down (auto-replayed later), {"error": "..."} on permission/safety violation.

Guards: permission check โ†’ never_store regex โ†’ scope validation โ†’ write (or queue).

mem0_search โ€” Dual-query search

Parameter Type Required Description
query string yes Natural language search query
scope string no Target scope (default: global). Use cross:group_id for cross-scope
mem_type string no Filter by memory type
trust_min string no Minimum trust level: high, medium, low
limit int no Max results (default: 5)
agent string no Caller identity

How dual-query works: When scope is group:xxx, Engram runs two parallel searches (group + global), then interleaves results by relevance. You always get the best of both local and global context in one call.

Returns: Array of memory objects with content, metadata (scope, trust, mem_type, source, agent, access_count), sorted by relevance then trust.

mem0_get_all โ€” Full inventory

Parameter Type Required Description
user_id string no User filter (default: default)
scope string no Scope filter
agent string no Caller identity

Returns: {"total": N, "results": [...]} โ€” all active (non-archived) memories matching the filter.

mem0_status โ€” Health check

Parameter Type Required Description
agent string no Caller identity

Returns: Full system health including:

  • mem0_ready / qdrant_ready โ€” backend status
  • total_memories / active_memories / archived_memories
  • by_scope โ€” count per scope
  • by_type โ€” count per memory type
  • by_trust โ€” count per trust level
  • write_queue_size โ€” pending offline writes
  • embedding_model / config_version / schema_version

mem0_maintenance โ€” Maintenance report

Parameter Type Required Description
mode string no report_only (default: daily). daily/weekly are placeholders โ€” run via CLI
agent string no Caller identity (needs main/devops permission)

Note: The MCP tool generates reports. Actual maintenance (Opus re-extraction, dedup, consolidation, decay) runs via python src/maintenance.py scheduled through cron.

Architecture

System layers

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  L1: Agent Layer                                                โ”‚
โ”‚                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
โ”‚  โ”‚   Main   โ”‚  โ”‚  Worker  โ”‚  โ”‚  Worker  โ”‚  โ”‚  DevOps  โ”‚       โ”‚
โ”‚  โ”‚  Agent   โ”‚  โ”‚  Agent A โ”‚  โ”‚  Agent B โ”‚  โ”‚  Agent   โ”‚       โ”‚
โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚          โ”‚       โ”‚
โ”‚  โ”‚ r: all   โ”‚  โ”‚ r: โ€”     โ”‚  โ”‚ r: โ€”     โ”‚  โ”‚ r: all   โ”‚       โ”‚
โ”‚  โ”‚ w: globalโ”‚  โ”‚ w: self  โ”‚  โ”‚ w: self  โ”‚  โ”‚ w: all   โ”‚       โ”‚
โ”‚  โ”‚   group  โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚          โ”‚       โ”‚
โ”‚  โ”‚   dm     โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚          โ”‚       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ”‚       โ”‚              โ”‚              โ”‚              โ”‚             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚              โ”‚              โ”‚              โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚ MCP (stdio)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  L2: Engram MCP Server      โ–ผ                                   โ”‚
โ”‚                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚                     5 MCP Tools                          โ”‚   โ”‚
โ”‚  โ”‚  mem0_add ยท mem0_search ยท mem0_get_all                   โ”‚   โ”‚
โ”‚  โ”‚  mem0_status ยท mem0_maintenance                          โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                              โ”‚                                  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Permission  โ”‚  โ”‚   Write Pipeline   โ”‚  โ”‚  never_store   โ”‚  โ”‚
โ”‚  โ”‚ Enforcer    โ”‚  โ”‚                    โ”‚  โ”‚  Regex Guard   โ”‚  โ”‚
โ”‚  โ”‚             โ”‚  โ”‚  infer=False       โ”‚  โ”‚                โ”‚  โ”‚
โ”‚  โ”‚ per-agent   โ”‚  โ”‚  (embedding only,  โ”‚  โ”‚  blocks keys,  โ”‚  โ”‚
โ”‚  โ”‚ read/write  โ”‚  โ”‚   no LLM call)     โ”‚  โ”‚  passwords,    โ”‚  โ”‚
โ”‚  โ”‚ scope rules โ”‚  โ”‚                    โ”‚  โ”‚  tokens        โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚  on failure:       โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                   โ”‚  โ†’ write_queue     โ”‚                       โ”‚
โ”‚                   โ”‚    (auto-replay)   โ”‚                       โ”‚
โ”‚                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                       โ”‚
โ”‚                            โ”‚                                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚                    โ”‚                    โ”‚
        โ–ผ                    โ–ผ                    โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Mem0 SDK   โ”‚    โ”‚   Qdrant     โ”‚    โ”‚   Maintenance CLI    โ”‚
โ”‚              โ”‚    โ”‚   Server     โ”‚    โ”‚                      โ”‚
โ”‚  embedding + โ”‚    โ”‚              โ”‚    โ”‚  Daily (3 AM):       โ”‚
โ”‚  vector writeโ”‚    โ”‚  persistent  โ”‚    โ”‚  ยท Opus re-extract   โ”‚
โ”‚              โ”‚    โ”‚  vector      โ”‚    โ”‚  ยท Vector dedup      โ”‚
โ”‚  primary:    โ”‚    โ”‚  storage     โ”‚    โ”‚                      โ”‚
โ”‚   Gemini     โ”‚    โ”‚              โ”‚    โ”‚  Weekly (Sun 4 AM):  โ”‚
โ”‚  fallback:   โ”‚    โ”‚  payload     โ”‚    โ”‚  ยท Conflict detect   โ”‚
โ”‚   OpenAI API โ”‚    โ”‚  metadata    โ”‚    โ”‚  ยท Consolidation     โ”‚
โ”‚              โ”‚    โ”‚  filtering   โ”‚    โ”‚  ยท Bjork decay       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Data flow: write

Agent calls mem0_add("User prefers dark mode", scope="global", mem_type="preference")
  โ”‚
  โ”œโ”€ Permission check: does this agent have write access to "global"?
  โ”œโ”€ never_store check: does content match any sensitive pattern?
  โ”œโ”€ Scope validation: is this a writable scope?
  โ”‚
  โ–ผ
  Mem0.add(content, metadata={scope, trust, mem_type, source, agent, ...}, infer=False)
  โ”‚
  โ”œโ”€ Success โ†’ return result
  โ””โ”€ Failure โ†’ append to write_queue.jsonl โ†’ auto-replay on next successful call

Data flow: search

Agent calls mem0_search("user preferences", scope="group:team_alpha")
  โ”‚
  โ”œโ”€ Permission check: can this agent read "group:team_alpha"?
  โ”‚
  โ–ผ
  Two parallel searches:
  โ”œโ”€ Search 1: scope="group:team_alpha", archived=false
  โ””โ”€ Search 2: scope="global", archived=false
  โ”‚
  โ–ผ
  Interleave by relevance โ†’ trust_min filter โ†’ limit โ†’ bump access_count (async)
  โ”‚
  โ–ผ
  Return: [{content, metadata: {scope, trust, mem_type, ...}}, ...]

Memory lifecycle

Type Decay Lifespan Purpose
preference Never Permanent "User prefers dark mode"
fact Never Permanent "Project uses PostgreSQL 16"
lesson Never Permanent "Don't use recursive CTE for this table"
decision Never Permanent "We chose React over Vue for the dashboard"
knowledge Never Permanent Consolidated from task_logs
procedure 90-day half-life Months "Deploy command: kubectl apply -f ..."
task_log 30-day half-life Weeks "Deployed v2.3 to staging" โ†’ consolidates before decay

Maintenance pipeline

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  Cron   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
                         โ”‚
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ–ผ                     โ–ผ
     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
     โ”‚  Daily (3 AM)  โ”‚    โ”‚ Weekly (Sun 4) โ”‚
     โ”‚                โ”‚    โ”‚                โ”‚
     โ”‚ 1. Opus re-    โ”‚    โ”‚ 1. Everything  โ”‚
     โ”‚    extract     โ”‚    โ”‚    from daily  โ”‚
     โ”‚    today's     โ”‚    โ”‚                โ”‚
     โ”‚    memories    โ”‚    โ”‚ 2. Conflict    โ”‚
     โ”‚                โ”‚    โ”‚    detection   โ”‚
     โ”‚ 2. Vector      โ”‚    โ”‚    (same-scope โ”‚
     โ”‚    dedup       โ”‚    โ”‚     fact vs    โ”‚
     โ”‚    (โ‰ฅ0.92      โ”‚    โ”‚     fact)      โ”‚
     โ”‚     cosine)    โ”‚    โ”‚                โ”‚
     โ”‚                โ”‚    โ”‚ 3. Consolidate โ”‚
     โ”‚ 3. Report      โ”‚    โ”‚    (N task_log โ”‚
     โ”‚                โ”‚    โ”‚     โ†’ 1        โ”‚
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚     knowledge) โ”‚
                           โ”‚                โ”‚
                           โ”‚ 4. Bjork decay โ”‚
                           โ”‚    importance  โ”‚
                           โ”‚    < 0.10 โ†’    โ”‚
                           โ”‚    archive     โ”‚
                           โ”‚                โ”‚
                           โ”‚ 5. Report      โ”‚
                           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Bjork decay formula:

effective_age = age_days / (1 + min(ln(1 + access_count), 3.0))
importance    = e^(-ln(2)/half_life ร— effective_age)

Frequently accessed memories decay slower. When importance < 0.10, the memory is archived.

Installation

Step 1: Clone

git clone https://github.com/lofder/Engram.git
cd Engram

Step 2: Run setup

./setup.sh

This creates config.yaml and .env from templates. You'll be asked to choose Docker or Local mode.

Step 3: Set your API keys

Edit .env:

GOOGLE_API_KEY=your-google-api-key-here    # For Gemini embeddings
LLM_API_KEY=your-llm-api-key-here          # For Mem0 inference + maintenance

GOOGLE_API_KEY is used for gemini-embedding-001 embeddings โ€” get one at Google AI Studio. LLM_API_KEY (or OPENAI_API_KEY) is used by Mem0 for memory operations and by maintenance for re-extraction.

Step 4: Start

Docker mode (Qdrant included):

docker compose up -d

Local mode (manage Qdrant yourself):

docker run -d -p 6333:6333 qdrant/qdrant    # or install Qdrant binary
python src/server.py

Step 5: Verify

# Docker mode
docker compose logs engram | tail -5
# Should show: "engram: initialized OK"

# Local mode โ€” server.py outputs to stderr:
# "engram: initialized OK"

Step 6: Connect your MCP client

Cursor โ€” add to .cursor/mcp.json:

{
  "mcpServers": {
    "engram": {
      "command": "python",
      "args": ["/absolute/path/to/Engram/src/server.py"],
      "env": {
        "GOOGLE_API_KEY": "your-key",
        "LLM_API_KEY": "your-llm-key",
        "NO_PROXY": "localhost,127.0.0.1"
      }
    }
  }
}

Claude Desktop โ€” add to claude_desktop_config.json:

{
  "mcpServers": {
    "engram": {
      "command": "python",
      "args": ["/absolute/path/to/Engram/src/server.py"],
      "env": {
        "GOOGLE_API_KEY": "your-key",
        "LLM_API_KEY": "your-llm-key"
      }
    }
  }
}

Step 7: Set up maintenance (optional)

crontab -e
15 2 * * * /path/to/Engram/scripts/mem0-backup.sh
 0 3 * * * /path/to/Engram/scripts/run-maintenance.sh daily
 0 4 * * 0 /path/to/Engram/scripts/run-maintenance.sh weekly

Real-World Usage

Scenario 1: Personal preferences across sessions

Your agent learns your style once, remembers it forever:

You:    "I prefer concise responses, no bullet points, always include code examples"
Agent:  (calls mem0_add with scope="global", mem_type="preference", trust="high")

--- next day, new session ---

Agent:  (calls mem0_search("response style preferences", scope="global"))
        โ†’ gets back: "User prefers concise responses, no bullet points, always include code examples"
        โ†’ applies this to all future responses automatically

Scenario 2: Multi-agent team with isolation

A main agent coordinates workers, each with their own memory namespace:

Main Agent:     writes to global, group:team, dm
  โ”œโ”€โ”€ Writer:   writes to agent:writer only (procedures, task_logs)
  โ”œโ”€โ”€ Analyst:  writes to agent:analyst only
  โ””โ”€โ”€ Browser:  writes to agent:browser only

Main can search all scopes. Workers can only see their own memories.
No cross-contamination.

Scenario 3: Cross-group context

Your agent needs info from another group without switching context:

Agent:  (calls mem0_search("shipping API docs", scope="cross:team_backend"))
        โ†’ searches team_backend's memories + global context
        โ†’ returns relevant results from both, interleaved by relevance

Scenario 4: Graceful degradation

When Mem0 or the embedding API goes down:

Agent:  (calls mem0_add(...))
        โ†’ Mem0 unreachable
        โ†’ Engram queues the write to write_queue.jsonl
        โ†’ Returns: {"queued": true, "write_id": "abc-123", "reason": "Mem0 unavailable"}
        โ†’ On next successful mem0_add, queued writes are auto-replayed

Configuration

Key sections in config.yaml:

# Agent permissions โ€” who can read/write where
agents:
  main:
    read: [global, "group:*", dm, "agent:*", all, "cross:*"]
    write: [global, "group:*", dm]
  worker:
    read: []
    write: ["agent:worker"]
    allowed_types: [procedure, task_log]

# Memory types โ€” each has its own decay and conflict strategy
memory_types:
  preference: {decay: never, conflict: update_latest}
  fact:       {decay: never, conflict: verify_source}
  task_log:   {decay: half_life_30d, conflict: no_dedup}

# Embedding โ€” primary + fallback
embedding:
  primary:
    provider: gemini
    model: models/gemini-embedding-001
    dimensions: 3072
  fallback:
    provider: openai
    model: gemini-embedding-001
    base_url: https://your-proxy.example.com/v1

# Qdrant connection
qdrant:
  host: localhost     # or "qdrant" in docker-compose
  port: 6333
  collection: memories

# Credential safety โ€” these patterns are never stored
never_store_patterns:
  - 'sk-[A-Za-z0-9]{20,}'
  - 'password\s*[:=]\s*\S+'
  - '-----BEGIN\s+(RSA\s+)?PRIVATE'

See docs/configuration.md for the full reference.

Documentation

Academic Foundation

Paper Key Insight Our Application
Hindsight (2512.12818) 4-network memory, 91.4% accuracy 7 memory type classification
MAPLE (2602.13258) HOT/COLD path separation Daytime infer=False + nightly Opus
FadeMem (2601.18642) Importance-based decay, -45% storage Bjork-enhanced decay formula
OWASP ASI06 (2026) Memory poisoning risk 40%โ†’80% trust + never_store + scope isolation
Bjork (1992) Storage-retrieval strength theory access_count suppresses decay
TierMem (2602.17913) Provenance tracking reduces token Structured metadata per memory

License

MIT โ€” See LICENSE

Contributing

Issues and PRs welcome. Please read docs/development.md first.

ไธญๆ–‡

ไธบไป€ไนˆ้œ€่ฆ Engram๏ผŸ

ไฝ ไธ€ๅฎšๆœ‰่ฟ‡่ฟ™ๆ ท็š„ไฝ“้ชŒ๏ผš่Šฑไบ† 20 ๅˆ†้’Ÿ่ทŸ AI ๅŠฉๆ‰‹่งฃ้‡Šไฝ ็š„้กน็›ฎ็ป“ๆž„ใ€็ผ–็ ้ฃŽๆ ผใ€ไธชไบบๅๅฅฝใ€‚ๅฎƒๅนฒๅพ—ๆผ‚ไบฎใ€‚็ฌฌไบŒๅคฉ๏ผŒๆ–ฐไผš่ฏโ€”โ€”ๅฎƒไป€ไนˆ้ƒฝไธ่ฎฐๅพ—ไบ†ใ€‚ไฝ ๅช่ƒฝไปŽๅคดๅ†ๆฅใ€‚

ไบŽๆ˜ฏไฝ ๆƒณไบ†ไธชๅŠžๆณ•๏ผšๅ†™ไธช md ๆ–‡ไปถใ€‚.cursor/rulesใ€AGENTS.mdใ€็ณป็ปŸ prompt ๆ–‡ๆกฃโ€”โ€”ๅซไป€ไนˆ้ƒฝ่กŒใ€‚ไธ€ๅผ€ๅง‹ๆŒบๅฅฝ็”จใ€‚ไฝ†ๆ…ขๆ…ขๅœฐ๏ผš

  • ๆ–‡ไปถ่ถŠๅ†™่ถŠ้•ฟใ€‚ๆฏๆฌก AI ๆž้”™ไป€ไนˆ๏ผŒไฝ ๅฐฑๅŠ ไธ€ๆก่ง„ๅˆ™ใ€‚
  • ๆ—งๆŒ‡ไปคๅ’Œๆ–ฐๆŒ‡ไปคๆ‰“ๆžถ๏ผŒไฝ ๅพ—ๅ›žๅŽปๆ‰‹ๅŠจ็†้กบใ€‚
  • ไฝ ๅ‘็Žฐ่‡ชๅทฑ่Šฑๅœจ็ปดๆŠค AI ็š„่ฎฐๅฟ†ไธŠ็š„ๆ—ถ้—ดๆฏ”ๅนฒๆญฃไบ‹่ฟ˜ๅคšใ€‚
  • ไฝ ๆœ‰ๅคšไธช้กน็›ฎใ€ๅคšไธช Agentโ€”โ€”็Žฐๅœจ่ฟ˜ๅพ—ๅŒๆญฅๅคšไธชๆ–‡ไปถใ€‚

ไฝ ๅ˜ๆˆไบ† AI ็š„ๅ…จ่Œ่ฎฐๅฟ†็ฎก็†ๅ‘˜ใ€‚่ฟ™ๅฎŒๅ…จๆžๅไบ†ใ€‚

ๆ›ดๆทฑๅฑ‚็š„้—ฎ้ข˜ไธๅชๆ˜ฏ"AI ไผšๅฟ˜"๏ผŒ่€Œๆ˜ฏ่ฎฐๅฟ†็š„่ดŸๆ‹…ๅ…จๅŽ‹ๅœจไฝ ่บซไธŠใ€‚ ไฝ ๅœจๆ‰‹ๅŠจๅš่ฎฐๅฟ†็ณป็ปŸ่ฏฅ่‡ชๅŠจๅš็š„ไบ‹๏ผšๅˆคๆ–ญไป€ไนˆ้‡่ฆใ€ๅ˜ๅŒ–ๆ—ถๆ›ดๆ–ฐใ€่ฟ‡ๆ—ถไบ†ๅฐฑๆธ…ๆމใ€‚

Engram ๆŠŠ่ฟ™ไปถไบ‹็ฟป่ฝฌ่ฟ‡ๆฅใ€‚ไธๆ˜ฏไฝ ๆ›ฟ AI ็ปดๆŠคๆ–‡ไปถ๏ผŒ่€Œๆ˜ฏ AI ่‡ชๅทฑ็ปดๆŠค่‡ชๅทฑ็š„่ฎฐๅฟ†โ€”โ€”็ป“ๆž„ๅŒ–็š„ใ€ๅˆ†ๅŸŸ็š„ใ€่ƒฝ่‡ชๆˆ‘ๆธ…็†็š„ใ€‚ๅฎƒ่‡ชๅทฑๅˆคๆ–ญไป€ไนˆ่ฏฅ็•™๏ผŒ่‡ชๅŠจๅŽ‹็ผฉๆ—งไฟกๆฏ๏ผŒ่‡ชๅŠจๆทกๅ‡บไธๅ†็›ธๅ…ณ็š„ๅ†…ๅฎนใ€‚ไฝ ๅช็ฎก็”จใ€‚

็Žฐๅœจ:     ไฝ ๅ†™ rules.md โ†’ AI ่ฏปๅฎƒ โ†’ ไฝ ๆ›ดๆ–ฐ rules.md โ†’ ๆ— ้™ๅพช็Žฏ
Engram:   AI ่‡ชๅทฑ่ฎฐไฝ โ†’ ้šๆ—ถ้—ดๅŽ‹็ผฉ โ†’ ไฝ ๅ†ไนŸไธ็”จ็ปดๆŠคๆ–‡ไปถไบ†

่ฎพ่ฎก็†ๅฟต

1. ่ฎฉ AI ็ฎก็†่‡ชๅทฑ็š„่ฎฐๅฟ†

ไฝ ไธไผšๆ‰‹ๅŠจ็ป™ๆฏไธชๆ‰“ๅผ€่ฟ‡็š„็ฝ‘้กตๅญ˜ไนฆ็ญพ๏ผŒไฝ ็š„ๅคง่„‘ไผš่‡ชๅทฑๅˆคๆ–ญไป€ไนˆๅ€ผๅพ—่ฎฐไฝใ€‚Engram ๅŒ็†โ€”โ€”AI ่‡ชๅทฑๅ†ณๅฎšๅญ˜ไป€ไนˆใ€ไฝ•ๆ—ถๅ›žๅฟ†ใ€ๅฟฝ็•ฅไป€ไนˆใ€‚ไฝ ๅช็ฎกๆญฃๅธธไฝฟ็”จ๏ผŒ่ฎฐๅฟ†ๅœจๅŽๅฐ่‡ช็„ถๅ‘็”Ÿใ€‚

2. ๅฐ‘ๅณๆ˜ฏๅคš

ๆฏๆฌกๅฏน่ฏๅกž่ฟ›ๅŽป 50 ๆกๆ—ง่ฎฐๅฟ†ๅนถๆฒกๆœ‰ๅธฎๅŠฉโ€”โ€”ๅชไผšๆตช่ดน token ๅ’Œๅนฒๆ‰ฐๆจกๅž‹ใ€‚Engram ่ฎฉ่ฎฐๅฟ†ไฟๆŒ็ฒพ็ฎ€๏ผš้‡ๅค็š„ๅˆๅนถใ€ๆ—งๆ—ฅๅฟ—ๆต“็ผฉๆˆ็ฎ€ๆด็š„็Ÿฅ่ฏ†ใ€่ฟ‡ๆ—ถ็š„ๆก็›ฎ่‡ชๅŠจๆทกๅ‡บใ€‚ๆœ€็ปˆ็ป“ๆžœๆ˜ฏไธ€็ป„ๅฐ่€Œ้ซ˜่ดจ้‡็š„่ฎฐๅฟ†๏ผŒ็œŸๆญฃ่ƒฝๆ”นๅ–„ๅ›žๅค่ดจ้‡ใ€‚

3. ้‡่ฆ็š„ไธœ่ฅฟๅบ”่ฏฅๆŒไน…

ไธๆ˜ฏๆ‰€ๆœ‰่ฎฐๅฟ†้ƒฝๅŒ็ญ‰้‡่ฆใ€‚ไฝ ็š„ๅๅฅฝ๏ผˆ"ๆฐธ่ฟœ็”จ TypeScript"๏ผ‰ใ€ๅญฆๅˆฐ็š„ๆ•™่ฎญ๏ผˆ"้‚ฃไธช API ๆœ‰ 5 ็ง’่ถ…ๆ—ถ"๏ผ‰ใ€ๅ…ณ้”ฎๅ†ณ็ญ–๏ผˆ"ๆˆ‘ไปฌ็”จ PostgreSQL"๏ผ‰โ€”โ€”่ฟ™ไบ›ๆฐธ่ฟœไธ่ฏฅ่ขซๅฟ˜่ฎฐใ€‚ไฝ†ๆ˜จๅคฉ็š„้ƒจ็ฝฒๆ—ฅๅฟ—๏ผŸๅฎƒๅฏไปฅๆ…ขๆ…ขๆทกๅ‡บโ€”โ€”ๅœจ่ขซๆ็‚ผๆˆๆŒไน…็Ÿฅ่ฏ†ไน‹ๅŽใ€‚

MCP ๅทฅๅ…ท

Engram ้€š่ฟ‡ MCP ๅ่ฎฎๆšด้œฒ 5 ไธชๅทฅๅ…ทใ€‚ไปปไฝ• MCP ๅ…ผๅฎนๅฎขๆˆท็ซฏ๏ผˆCursorใ€Claude Desktopใ€่‡ชๅฎšไน‰ Agent๏ผ‰้ƒฝๅฏไปฅ่ฐƒ็”จ๏ผš

mem0_add โ€” ๅญ˜ๅ‚จ่ฎฐๅฟ†

ๅ‚ๆ•ฐ ็ฑปๅž‹ ๅฟ…ๅกซ ่ฏดๆ˜Ž
content string ๆ˜ฏ ่ฎฐๅฟ†ๅ†…ๅฎน
scope string ๆ˜ฏ globalใ€group:xxxใ€dmใ€agent:xxx
mem_type string ๅฆ preferenceใ€factใ€procedureใ€lessonใ€decisionใ€task_logใ€knowledge
source string ๅฆ user_directใ€agent_outputใ€tool_resultใ€inferred๏ผˆ้ป˜่ฎค๏ผšagent_output๏ผ‰
trust string ๅฆ highใ€mediumใ€low๏ผˆ้ป˜่ฎค๏ผšmedium๏ผ‰
context string ๅฆ ่พ…ๅŠฉๆฃ€็ดข็š„้™„ๅŠ ไธŠไธ‹ๆ–‡
agent string ๅฆ ่ฐƒ็”จ่€…่บซไปฝ๏ผŒ็”จไบŽๆƒ้™ๆ ก้ชŒ

่ฟ”ๅ›ž๏ผšๆˆๅŠŸ {"results": [...]}๏ผŒMem0 ไธๅฏ็”จๆ—ถ {"queued": true, "write_id": "..."}๏ผˆๅŽ็ปญ่‡ชๅŠจ้‡ๆ”พ๏ผ‰๏ผŒๆƒ้™/ๅฎ‰ๅ…จ่ฟ่ง„ {"error": "..."}ใ€‚

mem0_search โ€” ๅŒ่ทฏๆฃ€็ดข

ๅ‚ๆ•ฐ ็ฑปๅž‹ ๅฟ…ๅกซ ่ฏดๆ˜Ž
query string ๆ˜ฏ ่‡ช็„ถ่ฏญ่จ€ๆœ็ดข
scope string ๅฆ ็›ฎๆ ‡ scope๏ผˆ้ป˜่ฎค๏ผšglobal๏ผ‰ใ€‚็”จ cross:group_id ่ทจๅŸŸๆœ็ดข
mem_type string ๅฆ ๆŒ‰่ฎฐๅฟ†็ฑปๅž‹่ฟ‡ๆปค
trust_min string ๅฆ ๆœ€ไฝŽไฟกไปป็ญ‰็บง๏ผšhighใ€mediumใ€low
limit int ๅฆ ๆœ€ๅคง่ฟ”ๅ›žๆ•ฐ๏ผˆ้ป˜่ฎค๏ผš5๏ผ‰
agent string ๅฆ ่ฐƒ็”จ่€…่บซไปฝ

ๅŒ่ทฏๅˆๅนถ๏ผšๅฝ“ scope ๆ˜ฏ group:xxx ๆ—ถ๏ผŒEngram ๅนถ่กŒๆœ็ดข๏ผˆgroup + global๏ผ‰๏ผŒๆŒ‰็›ธๅ…ณๆ€งไบค้”™ๅˆๅนถใ€‚ไธ€ๆฌก่ฐƒ็”จๅŒๆ—ถ่Žทๅพ—ๆœฌๅœฐๅ’Œๅ…จๅฑ€ๆœ€ไฝณ็ป“ๆžœใ€‚

mem0_get_all โ€” ๅ…จ้‡ๅˆ—ไธพ

ๅ‚ๆ•ฐ ็ฑปๅž‹ ๅฟ…ๅกซ ่ฏดๆ˜Ž
user_id string ๅฆ ็”จๆˆท่ฟ‡ๆปค๏ผˆ้ป˜่ฎค๏ผšdefault๏ผ‰
scope string ๅฆ scope ่ฟ‡ๆปค
agent string ๅฆ ่ฐƒ็”จ่€…่บซไปฝ

mem0_status โ€” ๅฅๅบทๆฃ€ๆŸฅ

่ฟ”ๅ›žๅฎŒๆ•ด็ณป็ปŸ็Šถๆ€๏ผšๅŽ็ซฏๅฐฑ็ปชๆ€งใ€่ฎฐๅฟ†ๆ€ปๆ•ฐ/ๆดป่ทƒๆ•ฐ/ๅฝ’ๆกฃๆ•ฐใ€ๆŒ‰ scope/็ฑปๅž‹/ไฟกไปป็ญ‰็บง็š„ๅˆ†ๅธƒใ€ๅ†™ๅ…ฅ้˜Ÿๅˆ—ๅคงๅฐใ€embedding ๆจกๅž‹็‰ˆๆœฌใ€‚

mem0_maintenance โ€” ็ปดๆŠคๆŠฅๅ‘Š

MCP ๅทฅๅ…ทๆไพ›ๆŠฅๅ‘ŠๆŸฅ็œ‹ใ€‚ๅฎž้™…็ปดๆŠค๏ผˆOpus ้‡ๆๅ–ใ€ๅŽป้‡ใ€ๅทฉๅ›บใ€่กฐๅ‡๏ผ‰้€š่ฟ‡ python src/maintenance.py ็”ฑ cron ่ฐƒๅบฆๆ‰ง่กŒใ€‚

ๆžถๆž„

็ณป็ปŸๅˆ†ๅฑ‚

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  L1: Agent ๅฑ‚                                                    โ”‚
โ”‚                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
โ”‚  โ”‚  Main    โ”‚  โ”‚ Worker A โ”‚  โ”‚ Worker B โ”‚  โ”‚  DevOps  โ”‚       โ”‚
โ”‚  โ”‚  Agent   โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚  Agent   โ”‚       โ”‚
โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚          โ”‚       โ”‚
โ”‚  โ”‚ ่ฏป: ๅ…จๅŸŸ  โ”‚  โ”‚ ่ฏป: โ€”    โ”‚  โ”‚ ่ฏป: โ€”    โ”‚  โ”‚ ่ฏป: ๅ…จๅŸŸ  โ”‚       โ”‚
โ”‚  โ”‚ ๅ†™: globalโ”‚  โ”‚ ๅ†™: self โ”‚  โ”‚ ๅ†™: self โ”‚  โ”‚ ๅ†™: ๅ…จๅŸŸ  โ”‚       โ”‚
โ”‚  โ”‚   group  โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚          โ”‚       โ”‚
โ”‚  โ”‚   dm     โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚          โ”‚       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚ MCP (stdio)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  L2: Engram MCP Server      โ–ผ                                   โ”‚
โ”‚                                                                 โ”‚
โ”‚  5 ไธชๅทฅๅ…ท ยท ๆƒ้™ๅฎˆๅซ ยท never_store ๆญฃๅˆ™ ยท ๅ†™ๅ…ฅ้˜Ÿๅˆ—้™็บง            โ”‚
โ”‚                                                                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ–ผ                     โ–ผ                     โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚   Mem0 SDK   โ”‚   โ”‚   Qdrant     โ”‚   โ”‚   ็ปดๆŠค CLI (cron)    โ”‚
  โ”‚  infer=False โ”‚   โ”‚   ๅ‘้‡ๆŒไน…ๅŒ–  โ”‚   โ”‚                      โ”‚
  โ”‚  ไธป: Gemini  โ”‚   โ”‚              โ”‚   โ”‚  ๆฏๆ—ฅ: Opus + ๅŽป้‡    โ”‚
  โ”‚  ๅค‡: OpenAI  โ”‚   โ”‚              โ”‚   โ”‚  ๆฏๅ‘จ: +ๅ†ฒ็ช+ๅทฉๅ›บ+่กฐๅ‡ โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

่ฎฐๅฟ†็”Ÿๅ‘ฝๅ‘จๆœŸ

็ฑปๅž‹ ่กฐๅ‡ ๅฏฟๅ‘ฝ ไธพไพ‹
preference ๆฐธไธ ๆฐธไน… "็”จๆˆทๅ–œๆฌข็ฎ€็บฆ้ฃŽๆ ผ"
fact ๆฐธไธ ๆฐธไน… "้กน็›ฎไฝฟ็”จ PostgreSQL 16"
lesson ๆฐธไธ ๆฐธไน… "่ฟ™ไธช่กจไธ่ฆ็”จ้€’ๅฝ’ CTE"
decision ๆฐธไธ ๆฐธไน… "Dashboard ้€‰ไบ† React ่€Œ้ž Vue"
knowledge ๆฐธไธ ๆฐธไน… ไปŽ task_log ๅทฉๅ›บ่€Œๆฅ
procedure 90 ๅคฉๅŠ่กฐๆœŸ ๆ•ฐๆœˆ "้ƒจ็ฝฒๅ‘ฝไปค๏ผškubectl apply -f ..."
task_log 30 ๅคฉๅŠ่กฐๆœŸ ๆ•ฐๅ‘จ "้ƒจ็ฝฒไบ† v2.3 ๅˆฐ staging" โ†’ ่ฟ‡ๆœŸๅ‰ๅทฉๅ›บ

Bjork ่กฐๅ‡ๅ…ฌๅผ

effective_age = age_days / (1 + min(ln(1 + access_count), 3.0))
importance    = e^(-ln(2)/ๅŠ่กฐๆœŸ ร— effective_age)

่ขซๆฃ€็ดข่ถŠๅคš็š„่ฎฐๅฟ†่กฐๅ‡่ถŠๆ…ขใ€‚ๅฝ“ importance < 0.10 ๆ—ถ่‡ชๅŠจๅฝ’ๆกฃใ€‚

ๅฎ‰่ฃ…

็ฌฌ 1 ๆญฅ๏ผšๅ…‹้š†

git clone https://github.com/lofder/Engram.git
cd Engram

็ฌฌ 2 ๆญฅ๏ผš่ฟ่กŒๅฎ‰่ฃ…่„šๆœฌ

./setup.sh

่‡ชๅŠจ็”Ÿๆˆ config.yaml ๅ’Œ .env๏ผŒไบคไบ’้€‰ๆ‹ฉ Docker ๆˆ–ๆœฌๅœฐๆจกๅผใ€‚

็ฌฌ 3 ๆญฅ๏ผš่ฎพ็ฝฎ API Key

็ผ–่พ‘ .env๏ผš

GOOGLE_API_KEY=ไฝ ็š„-google-api-key          # ็”จไบŽ Gemini embedding
LLM_API_KEY=ไฝ ็š„-llm-api-key               # ็”จไบŽ Mem0 ๆŽจ็† + ็ปดๆŠค

GOOGLE_API_KEY ็”จไบŽ gemini-embedding-001 ๅ‘้‡ๅŒ–๏ผŒๅœจ Google AI Studio ่Žทๅ–ใ€‚ LLM_API_KEY๏ผˆๆˆ– OPENAI_API_KEY๏ผ‰็”จไบŽ Mem0 ็š„่ฎฐๅฟ†ๆ“ไฝœๅ’Œ็ปดๆŠค่„šๆœฌ็š„้‡ๆๅ–ใ€‚

็ฌฌ 4 ๆญฅ๏ผšๅฏๅŠจ

Docker ๆจกๅผ๏ผˆๅซ Qdrant๏ผ‰๏ผš

docker compose up -d

ๆœฌๅœฐๆจกๅผ๏ผš

docker run -d -p 6333:6333 qdrant/qdrant
python src/server.py

็ฌฌ 5 ๆญฅ๏ผš้ชŒ่ฏ

# ็œ‹ๅˆฐ "engram: initialized OK" ๅณๆˆๅŠŸ
docker compose logs engram | tail -5

็ฌฌ 6 ๆญฅ๏ผš่ฟžๆŽฅ MCP ๅฎขๆˆท็ซฏ

Cursor โ€” ๆทปๅŠ ๅˆฐ .cursor/mcp.json๏ผš

{
  "mcpServers": {
    "engram": {
      "command": "python",
      "args": ["/absolute/path/to/Engram/src/server.py"],
      "env": {
        "GOOGLE_API_KEY": "your-key",
        "LLM_API_KEY": "your-llm-key",
        "NO_PROXY": "localhost,127.0.0.1"
      }
    }
  }
}

็ฌฌ 7 ๆญฅ๏ผš้…็ฝฎ็ปดๆŠค๏ผˆๅฏ้€‰๏ผ‰

15 2 * * * /path/to/Engram/scripts/mem0-backup.sh
 0 3 * * * /path/to/Engram/scripts/run-maintenance.sh daily
 0 4 * * 0 /path/to/Engram/scripts/run-maintenance.sh weekly

ๅฎž้™…ไฝฟ็”จๅœบๆ™ฏ

ๅœบๆ™ฏ 1๏ผš่ทจไผš่ฏ็š„ไธชไบบๅๅฅฝ

Agent ๅญฆไธ€ๆฌก๏ผŒๆฐธ่ฟœ่ฎฐไฝ๏ผš

ไฝ :     "ๆˆ‘ๅ–œๆฌข็ฎ€ๆด็š„ๅ›žๅค๏ผŒไธ่ฆๅˆ—่กจ๏ผŒไธ€ๅฎš่ฆๅธฆไปฃ็ ็คบไพ‹"
Agent:  (่ฐƒ็”จ mem0_add, scope="global", mem_type="preference", trust="high")

--- ็ฌฌไบŒๅคฉ๏ผŒๆ–ฐไผš่ฏ ---

Agent:  (่ฐƒ็”จ mem0_search("ๅ›žๅค้ฃŽๆ ผๅๅฅฝ", scope="global"))
        โ†’ ่ฟ”ๅ›ž: "็”จๆˆทๅ–œๆฌข็ฎ€ๆดๅ›žๅค๏ผŒไธ่ฆๅˆ—่กจ๏ผŒไธ€ๅฎš่ฆๅธฆไปฃ็ ็คบไพ‹"
        โ†’ ่‡ชๅŠจๅบ”็”จๅˆฐๆ‰€ๆœ‰ๅŽ็ปญๅ›žๅค

ๅœบๆ™ฏ 2๏ผšๅคš Agent ๅ›ข้˜Ÿ้š”็ฆป

Main Agent ๅ่ฐƒ Worker๏ผŒๅ„ๆœ‰็‹ฌ็ซ‹่ฎฐๅฟ†็ฉบ้—ด๏ผš

Main Agent:     ๅ†™ global, group:team, dm
  โ”œโ”€โ”€ Writer:   ๅชๅ†™ agent:writer๏ผˆprocedure, task_log๏ผ‰
  โ”œโ”€โ”€ Analyst:  ๅชๅ†™ agent:analyst
  โ””โ”€โ”€ Browser:  ๅชๅ†™ agent:browser

Main ๅฏๆœ็ดขๆ‰€ๆœ‰ scopeใ€‚Worker ๅช็œ‹ๅˆฐ่‡ชๅทฑ็š„่ฎฐๅฟ†ใ€‚้›ถไบคๅ‰ๆฑกๆŸ“ใ€‚

ๅœบๆ™ฏ 3๏ผš่ทจ็พค่ฎฐๅฟ†ๅผ•็”จ

Agent:  (่ฐƒ็”จ mem0_search("็‰ฉๆตAPIๆ–‡ๆกฃ", scope="cross:team_backend"))
        โ†’ ๅŒๆ—ถๆœ็ดข team_backend ็š„่ฎฐๅฟ† + global ไธŠไธ‹ๆ–‡
        โ†’ ๆŒ‰็›ธๅ…ณๆ€งไบค้”™่ฟ”ๅ›žไธค่พน็š„็ป“ๆžœ

ๅœบๆ™ฏ 4๏ผšไผ˜้›…้™็บง

Mem0 ๆˆ– embedding API ๆŒ‚ไบ†๏ผš

Agent:  (่ฐƒ็”จ mem0_add(...))
        โ†’ Mem0 ไธๅฏ่พพ
        โ†’ Engram ๆŠŠๅ†™ๅ…ฅๆŽ’ๅ…ฅ write_queue.jsonl
        โ†’ ่ฟ”ๅ›ž: {"queued": true, "write_id": "abc-123"}
        โ†’ ไธ‹ๆฌกๆˆๅŠŸๅ†™ๅ…ฅๆ—ถ่‡ชๅŠจ้‡ๆ”พ้˜Ÿๅˆ—

้…็ฝฎ่ฏดๆ˜Ž

config.yaml ๆ ธๅฟƒๆฎต่ฝ๏ผš

# Agent ๆƒ้™ โ€” ่ฐๅฏไปฅๅœจๅ“ช้‡Œ่ฏปๅ†™
agents:
  main:
    read: [global, "group:*", dm, "agent:*", all, "cross:*"]
    write: [global, "group:*", dm]
  worker:
    read: []
    write: ["agent:worker"]
    allowed_types: [procedure, task_log]

# ่ฎฐๅฟ†็ฑปๅž‹ โ€” ๅ„ๆœ‰็‹ฌ็ซ‹็š„่กฐๅ‡ๅ’Œๅ†ฒ็ช็ญ–็•ฅ
memory_types:
  preference: {decay: never, conflict: update_latest}
  fact:       {decay: never, conflict: verify_source}
  task_log:   {decay: half_life_30d, conflict: no_dedup}

# ๅฎ‰ๅ…จ โ€” ๅŒน้…่ฟ™ไบ›ๆญฃๅˆ™็š„ๅ†…ๅฎนๆฐธ่ฟœไธไผš่ขซๅญ˜ๅ‚จ
never_store_patterns:
  - 'sk-[A-Za-z0-9]{20,}'
  - 'password\s*[:=]\s*\S+'

ๅฎŒๆ•ด้…็ฝฎๅ‚่€ƒ่ง docs/configuration.mdใ€‚

ๆ–‡ๆกฃ

ๅญฆๆœฏๅŸบ็ก€

่ฎบๆ–‡ ๆ ธๅฟƒๆดžๅฏŸ ๆœฌ้กน็›ฎ็š„ๅบ”็”จ
Hindsight (2512.12818) 4 ็ฝ‘็ปœ่ฎฐๅฟ†๏ผŒ91.4% ๅ‡†็กฎ็އ 7 ็ง่ฎฐๅฟ†็ฑปๅž‹ๅˆ†็ฑป
MAPLE (2602.13258) HOT/COLD ่ทฏๅพ„ๅˆ†็ฆป ็™ฝๅคฉ infer=False + ๅคœ้—ด Opus
FadeMem (2601.18642) ๅŸบไบŽ้‡่ฆๆ€ง็š„่กฐๅ‡๏ผŒ-45% ๅญ˜ๅ‚จ Bjork ๅขžๅผบ่กฐๅ‡ๅ…ฌๅผ
OWASP ASI06 (2026) ่ฎฐๅฟ†ๆŠ•ๆฏ’้ฃŽ้™ฉ 40%โ†’80% trust + never_store + scope ้š”็ฆป
Bjork (1992) ๅญ˜ๅ‚จ-ๆฃ€็ดขๅผบๅบฆ็†่ฎบ access_count ๆŠ‘ๅˆถ่กฐๅ‡
TierMem (2602.17913) ๆฅๆบ่ฟฝ่ธชๅ‡ๅฐ‘ token ๆฏๆก่ฎฐๅฟ†็š„็ป“ๆž„ๅŒ–ๅ…ƒๆ•ฐๆฎ

่ฎธๅฏ่ฏ

MIT โ€” ่ง LICENSE

่ดก็Œฎ

ๆฌข่ฟŽๆ Issue ๅ’Œ PRใ€‚่ฏทๅ…ˆ้˜…่ฏป docs/development.mdใ€‚

About

Scope-aware memory architecture for multi-agent AI assistants. Powered by Mem0 + Qdrant + MCP.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors