MemPalace JS

MemPalace JS

A local-first, zero-LLM memory system and MCP server that gives AI assistants a searchable, structured persistent memory using a spatial metaphor.

Category
访问服务器

README

MemPalace JS

NPM Version License TypeScript Recall Accuracy Node Version

Ingestion Speed Startup Latency Fluidity Search Latency

Give your AI a perfect, infinite memory. A local-first, zero-LLM memory system and Model Context Protocol (MCP) server designed to give AI assistants (like Claude, ChatGPT, and custom agents) a searchable, structured "Memory Palace."

Jump to Quick Start 🚀

This is a native Node.js / TypeScript port of the original Python MemPalace architecture, achieving full feature parity and benchmark validation while running seamlessly in JS-native environments.


🏛️ How it Works

MemPalace organizes information using a spatial metaphor to maximize context efficiency:

  [ USER AGENT ] <──( MCP )──> [ MEMPALACE ENGINE ]
                                       │
      ┌────────────────────────────────┼────────────────────────────────┐
      │ Layer 0: Identity (Loci)       │ Layer 1: Essential Story (AAAK) │
      │ "Who am I? What's my role?"    │ "The core project milestones"   │
      └────────────────────────────────┼────────────────────────────────┘
                                       │
      ┌────────────────────────────────┼────────────────────────────────┐
      │ Layer 2: On-Demand (Rooms)     │ Layer 3: Deep Search (Vector)   │
      │ "Specific topics (e.g. Auth)"  │ "Semantic match for current Q"  │
      └────────────────────────────────┼────────────────────────────────┘
                                       │
                         [ LanceDB ] [ SQLite ] [ Filesystem ]
  • Wings: High-level domains (e.g., wing_projectA, wing_personal).
  • Rooms: Topics within a wing (e.g., room_architecture, room_decisions).
  • Drawers: The actual text chunks (vectors) stored in LanceDB.
  • Tunnels: Cross-wing connections dynamically built when a Room appears in multiple Wings.

Why MemPalace JS? (Industrial-Grade Memory)

While most local RAG implementations use simple file buffers or basic SQLite extensions, MemPalace JS is engineered for high-scale, production agentic workflows.

  • Rust-Powered Vector Engine: Powered by LanceDB. Unlike standard SQLite-based search, our engine is IOPS-optimized and scales to millions of memories with sub-millisecond retrieval.
  • Zero-Lag UI & Heartbeats: CPU-intensive embedding math is offloaded to background Worker Threads. This keeps the MCP server 100% responsive, preventing the "hanging" heartbeats and timeouts common in single-threaded AI tools.
  • O(1) Context Streaming: Our Async Generator retrieval treats memory like a pipeline, not a buffer. Recalling a massive "room" of context consumes minimal RAM, regardless of the dataset size.
  • Self-Contained Stability: By internalizing all pure-JS dependencies, we provide a Zero-Config bundle that eliminates node_modules bloat and version conflicts with other CLI tools.

Features

  • Full Feature Parity: Includes all 19 tools from the original Python implementation (Status, Graph Nav, Knowledge Graph, Diary).
  • Zero-LLM Storage Pipeline: Fast, pure regex heuristics for fact extraction—zero API costs and instant processing.
  • Embedded Hybrid Search: Combines LanceDB vectors with a Temporal Knowledge Graph (better-sqlite3).
  • AAAK Dialect Compression: High-density, LLM-readable memory storage that saves 80% on tokens while preserving context.
  • Native MCP Server: Seamless integration with Claude Code and Claude Desktop.

⚡ AAAK at a glance (Lossy Memory Compression)

MemPalace JS automatically compresses long project histories into high-density AAAK (Asynchronous AI Abbreviated Knowledge) dialect. This saves tokens while preserving the "who, what, and why" for the LLM.

Original Text:

Jordan decided to switch the database to PostgreSQL because of the complex join requirements. This was a major milestone for the backend team.

AAAK Output:

PROJ: backend | fierce JOR→switch DB to Postgres (joins) | ★★★★ | MIL: backend-db-switch


Documentation


Benchmark Validation

MemPalace JS has been rigorously evaluated against the LongMemEval dataset (500 questions, ~53 conversation sessions per question) to ensure mathematical parity with the original Python research.

Metric Python (Original) MemPalace JS (Node.js)
Recall@5 96.6% 96.4%
NDCG@5 0.889 0.885

Validation run on April 9th, 2026. Differences are within statistical variance for embedding pipeline implementations.

Quick Start: Plug-and-Play MCP or Full Memory Journey

MemPalace JS is designed to be Plug-and-Play. You can connect it to your AI agent immediately without any preconfiguration. It will start with a fresh, empty palace that grows as you chat.

For a more comprehensive experience, follow the structured journey below.

🚀 Step 0: Immediate Start (Plug-and-Play MCP)

If you want to start right away, just add the MCP server to your agent's configuration (see Step 3). The server will automatically initialize your local environment (~/.mempalace) and be ready to save your first memory.


Step 1: Prepare the Engine

Install the package and pre-download the 90MB AI model weights. This ensures your first memory recall is instantaneous.

# 1. Global Installation
npm install -g @mempalace/core

# 2. Pre-download AI models
mempalace setup

Step 2: Fuel the Palace (Mine & Initialize)

A palace is only as good as what's inside. Define who you are and index your first project.

# 1. Define your Identity (L0 context)
mempalace init

# 2. Mine your project codebase into a Wing
mempalace mine ./my-project --wing my-project

Step 3: Connect your Agent

Now that the palace has "fuel," connect it to your favorite assistant.

For Claude Desktop (~/.claude/claude_desktop_config.json):

{
  "mcpServers": {
    "mempalace": {
      "command": "npx",
      "args": ["-y", "@mempalace/core", "mcp"]
    }
  }
}

🔄 The Two-Way Connection

MemPalace JS isn't just a "read-only" database; it's a living extension of your AI.

  1. System-to-Agent: Use the CLI (mempalace mine) to index documentation, code, and legacy logs. The agent immediately "remembers" these via MCP tools.
  2. Agent-to-System: As you chat, the agent can use mempalace_add_drawer or mempalace_kg_add to proactively save new facts about your preferences, decisions, or project status.
  3. Universal Sync: Because they share the same local vault (~/.mempalace), any memory saved by the agent in Claude is immediately searchable in your terminal.

Claude Code Integration

MemPalace JS includes hooks designed for Claude Code to automatically capture memories during your sessions.

  • Auto-Save Hook: Triggers a memory save every 15 exchanges.
  • Pre-Compact Hook: Ensures a full memory save before Claude compresses the conversation context.

Installation

You can install the hooks to your local .mempalace directory automatically:

mempalace install-hooks

Follow the on-screen instructions to add them to your Claude configuration.

Model Context Protocol (MCP) Integration

MemPalace JS acts as a high-performance memory backend for AI agents.

Common Tools for Agents

When connected, your agent can call tools such as:

  • mempalace_search: Semantic search across all memories.
  • mempalace_wake_up: Load the Identity (L0) and project milestones (L1).
  • mempalace_kg_query: Query the temporal relationship graph for entities.
  • mempalace_diary_write: Allow the agent to record its own observations.
  • mempalace_traverse_graph: Navigate between connected topics and wings.

For Claude Desktop (~/.claude/claude_desktop_config.json):

{
  "mcpServers": {
    "mempalace": {
      "command": "npx",
      "args": ["-y", "@mempalace/core", "mcp"]
    }
  }
}

Architecture

MemPalace organizes memories using a spatial metaphor:

  • Wings: High-level domains (e.g., wing_projectA, wing_personal).
  • Rooms: Topics within a wing (e.g., room_architecture, room_decisions).
  • Drawers: The actual text chunks (vectors) stored in LanceDB.
  • Halls (Tunnels): Cross-wing connections dynamically built when a Room appears in multiple Wings.

Tech Stack

  • Vector Storage: LanceDB (Serverless, embedded vector DB)
  • Embeddings: Transformers.js (Xenova/all-MiniLM-L6-v2)
  • Relational DB: better-sqlite3 (Knowledge graph & triples)
  • Tooling: Model Context Protocol (MCP) SDK, Commander.js

Node.js Architecture & Performance

The @mempalace/core architecture is designed to leverage Node.js's strengths in asynchronous I/O and multi-threaded processing to provide a high-performance, local-first memory system.

  • Batched Embedding Pipeline: Utilizes worker_threads to offload CPU-intensive embedding generation (via Transformers.js) to background threads. The system implements Request Coalescing, bundling multiple simultaneous embedding requests into a single worker pass to minimize IPC overhead and maximize ONNX runtime efficiency.

  • Memory-Efficient Context Streaming: The context generation layers (L1-L3) are built on AsyncGenerators. Instead of buffering massive memory blocks in RAM, MemPalace yields context chunks as they are retrieved and processed, significantly reducing peak memory (RSS) and improving "Time to First Byte" for the AI agent.

  • Blazing-Fast Serialization: Uses fast-json-stringify for MCP tool responses. By employing pre-compiled, schema-aware serialization for core memory fields, the server can deliver large context windows up to 10x faster than standard JSON.stringify while maintaining dynamic flexibility for user metadata.

  • Atomic SQLite Transaction Batching: Ingestion for the Knowledge Graph utilizes better-sqlite3's native atomic transactions, enabling high-throughput data mining (~23,800 triples/sec) while ensuring strict data integrity.

  • Self-Contained & Lazy-Loaded: To ensure the snappiest CLI experience, MemPalace bundles all pure-JS dependencies into a single distribution and implements true lazy-loading for heavy math libraries. The Transformers.js engine is only initialized when a command specifically requires semantic math, allowing status and navigation commands to start in <150ms.

Performance Delta & Optimization Results

The recent optimization pass focused on parallelizing the embedding pipeline and streamlining memory transport.

Component Metric Performance vs. Python / Baseline
Ingestion Throughput 28.3 drawers / sec 2.5x Faster
UX Fluidity Main Thread Responsiveness 90.1% Fluid during load
Serialization Tool Response Speed ~17ms / 100 results Up to 10x Faster
Memory usage Peak RSS Footprint O(1) Streaming 90% lower peak

Benchmarks captured during 500-drawer ingestion on a standard development machine. "Fluidity" measures event loop responsiveness via a concurrent heartbeat monitor during heavy background CPU/IO load.

Testing & Development

This project maintains strict test parity with the Python original.

  • 44 Tests Passed: Covering normalization, AAAK compression, Knowledge Graph logic, project mining, and vector search.
  • Test Command: npm run test (Powered by vitest).

Running Benchmarks

To reproduce the LongMemEval results:

# 1. Download the dataset
mkdir -p benchmarks/data
curl -fsSL -o benchmarks/data/longmemeval_s_cleaned.json https://huggingface.co/datasets/xiaowu0162/longmemeval-cleaned/resolve/main/longmemeval_s_cleaned.json

# 2. Run the runner
npx tsx src/benchmarks/longmemeval_bench.ts benchmarks/data/longmemeval_s_cleaned.json

Contributing & Issues

We welcome contributions! Please feel free to open an issue or submit a pull request on GitHub.


License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选