Skip to main content

WanYi Memory Core 万忆中枢

永不遗忘的全量记忆系统 — Event-sourced long-term memory for AI agents: process memory, mistake books, experience crystallization, confidence-based decision blocking, counterfactual branches, cross-domain analogy, trajectory replay, proactive partner, semantic vector retrieval, reranker, memory graph, time decay and metacognitive knowledge-gaps. Ships as a local-first MCP server with 23 tools. Your data never leaves your machine.

Python License Version MCP CI PyPI


Why

LLM agents forget. Every chat window is amnesia: preferences, lessons, and hard-won experience evaporate when the session ends. Existing memory systems either store in the cloud (privacy risk), require heavy infrastructure, or only do keyword search (missing semantic recall).

WanYi Memory Core is a local-first, full-quantity, self-evolving memory system:

  • Event sourcing — an append-only WAL is the single source of truth. Nothing is ever deleted; decay only affects retrieval ranking.
  • Semantic recall — hybrid retrieval: BM25 keywords + local Chinese embedding (BAAI/bge-small-zh-v1.5) + reranker (BAAI/bge-reranker-base) + knowledge-graph expansion + explicit time decay.
  • Metacognition — when recall is weak, the system admits it and records a knowledge-gap instead of hallucinating an answer.
  • Decision guardrails — high-risk actions (all-in, revenge-trading, force-push, rm -rf) trigger confidence-based blocking with counterfactual branches: you see what would have happened if you had listened.
  • Zero-participation evolution — no need to say "remember this"; the system decides what to store, consolidates overnight, and surfaces weekly trajectory reviews.

Install

pip install wanyimem            # core
pip install "wanyimem[all]"     # + vector & reranker models deps

Requires Python 3.10+. Models (embedding ~95MB, reranker ~1.1GB) are downloaded on first use from HuggingFace; set HF_ENDPOINT=https://hf-mirror.com if you are in mainland China.

Before the PyPI release lands, you can also install directly from GitHub (identical code):

pip install "git+https://github.com/17861102832/wanyimem.git"

Quick Start (MCP)

Add to your mcp.json (Claude Desktop, Cursor, Trae, etc.):

{
  "mcpServers": {
    "wanyi": {
      "command": "python",
      "args": ["-m", "wanyi.memory_core"],
      "env": {
        "WANYI_STORE_DIR": "C:/path/to/your/memory"
      }
    }
  }
}

Env keys are "Chinese-first, ASCII-fallback": the new WANYI_STORE_DIR (recommended, more portable) and the legacy 万忆中枢_STORE_DIR both work. Bare python depends on PATH and may fail; prefer an absolute interpreter path, or pip install wanyimem then use "command": "wanyi".

Then any agent can call the 23 tools, e.g.:

万忆记录见闻 → "2026年5月基金大跌时我死扛不止损,亏了18%才割肉。"
万忆召回记忆 → query "认赔离场到底对不对"   # semantic match even with zero shared keywords
万忆置信度决策检查 → "我要全仓梭哈"          # BLOCK if confidence is low, with historical mistakes

Quick Start (Library)

from wanyi import WanYiCore

engine = WanYiCore()
engine.tool_record_memory(
    content="止损纪律:亏损超过8%必须无条件卖出",
    layer="法", mem_type="principle",
)
resp = engine.tool_recall_memory("认赔离场到底对不对", limit=5)
for m in resp["memories"]:
    print(m["content"], m.get("_rerank_score"))

Features

Area Capability
Storage SQLite + append-only event WAL; 道/法/术 three-layer half-lives
Retrieval Keyword BM25 + vector (bge-small-zh) + reranker (bge-reranker-base) + graph expansion + time-decay fields
Metacognition knowledge-gap auto-record, stats self-check, honest "I don't know"
Guardrails confidence-based decision blocking, counterfactual branches with auto-settlement, cross-domain analogy bridging
Proactivity daily brief on LOAD, due-branch reminders, weekly trajectory replay, risk-keyword alert
Growth mistake book, experience crystallization, overnight consolidation, evolution queries
Privacy fully local, zero telemetry, no cloud dependency

Benchmark (mini LongMemEval, cross-session fact recall, 10 cases): Recall@5 = 90%, MRR = 0.900.

Docs

Contributing

See CONTRIBUTING.md. Report vulnerabilities privately via SECURITY.md.

License

MIT © 2026 Zhao Xikun

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wanyimem-1.0.1.tar.gz (93.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wanyimem-1.0.1-py3-none-any.whl (87.5 kB view details)

Uploaded Python 3

File details

Details for the file wanyimem-1.0.1.tar.gz.

File metadata

  • Download URL: wanyimem-1.0.1.tar.gz
  • Upload date:
  • Size: 93.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wanyimem-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ade31aad8413b20aab69c98566aa4b19a10d7e923db55670b63a0fefe6b9bef0
MD5 9b580a8088347c29ded477f3b556fd8d
BLAKE2b-256 851490f291da67a04738d887db1aac60a131114880c84c721b0e7def089e033e

See more details on using hashes here.

Provenance

The following attestation bundles were made for wanyimem-1.0.1.tar.gz:

Publisher: publish.yml on 17861102832/wanyimem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wanyimem-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: wanyimem-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 87.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wanyimem-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b263e1af150530b88e29fe81ce6388aebbf8efc1840bd214a88c29fd5544ab4d
MD5 fd0af65fdf404f4f64f1902f0d7c829a
BLAKE2b-256 729ae873b8090779539db0b6f56ec2f68dc19f4080a2c2a9b4d1a27304244a95

See more details on using hashes here.

Provenance

The following attestation bundles were made for wanyimem-1.0.1-py3-none-any.whl:

Publisher: publish.yml on 17861102832/wanyimem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

This release

1.0.1 This release

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page