Skip to main content

lm-mem

本地语义记忆 MCP Server — 跨会话持久化,语义检索。

安装

pip install lm-mem

使用

# 启动后端
lm-mem backend start

# MCP Server (stdio)
lm-mem mcp

# Web 台(浏览器查看/检索/删除记忆,默认只绑 127.0.0.1)
lm-mem web start

装入 agent 规则文件

lm-mem skill install 把一段常驻触发规则写进已安装 agent 的规则文件, 让 agent 知道何时该调用记忆工具(完整策略见 skill 的 SKILL.md)。

自动检测下列 agent 的配置目录,装了几个写几个:

agent --platform 取值 检测目录 写入文件
Claude Code claude ~/.claude/ CLAUDE.md
Codex codex ~/.codex/ AGENTS.md
opencode opencode ~/.config/opencode/ AGENTS.md
OpenClaw openclaw ~/.openclaw/ AGENTS.md
lm-mem skill install      # 检测并写入(幂等,可重复执行以同步最新版本)
lm-mem skill status       # 查看各文件安装状态
lm-mem skill uninstall    # 移除写入的段落

只想操作某几个 agent 时用 --platform(可重复):

lm-mem skill install --platform claude                     # 只写 Claude Code
lm-mem skill install --platform codex --platform openclaw  # 写这两个
lm-mem skill uninstall --platform claude                   # 只从 Claude 移除

显式指定的 platform 优先于自动检测 —— 配置目录还不存在也会照写并新建 (适合先把规则配好、之后再装那个 agent)。

写入内容用 <!-- lm-mem:begin -->…<!-- lm-mem:end --> 包裹,不影响文件其余部分。

MCP 客户端配置

{
  "mcpServers": {
    "memory": {
      "command": "uvx",
      "args": ["lm-mem", "mcp"],
      "env": {
        "LM_MEM_BACKEND_URL": "http://127.0.0.1:8901"
      }
    }
  }
}

环境变量

变量 默认值 说明
LM_MEM_BACKEND_URL http://$LM_MEM_BACKEND_HOST:$LM_MEM_BACKEND_PORT 后端地址;显式设置时优先于下面两项
LM_MEM_BACKEND_HOST 127.0.0.1 后端地址,backend/web/mcp 共用
LM_MEM_BACKEND_PORT 8901 后端端口,backend/web/mcp 共用
LM_MEM_EMBEDDED (关) =1 时进程内嵌 Chroma 直读 LM_MEM_DB_PATH,不需要常驻后端
LM_MEM_AUTO_PURGE 1 lm-mem mcp 启动时清一次过期记忆;=0 关闭(仍可手动调 purge_expired)
LM_MEM_DATA_DIR ~/.lm-mem 数据根目录
LM_MEM_DB_PATH $LM_MEM_DATA_DIR/chroma 数据库路径
LM_MEM_WEB_HOST 127.0.0.1 Web UI 绑定地址
LM_MEM_WEB_PORT 7531 Web UI 端口

改后端端口要用环境变量(三个进程都得看到同一个值),别只给 backend start --port:

export LM_MEM_BACKEND_PORT=9000
lm-mem backend start && lm-mem web start   # web 会连到 9000

作为库使用

from lm_mem import MemoryClient

client = MemoryClient()                 # 用共享后端(由 LM_MEM_BACKEND_URL 决定)
# client = MemoryClient(url="http://127.0.0.1:8901")  # 或显式指定后端

# 保存(同作用域内内容高度相似会自动查重;force=True 跳过)
client.add("用户偏好 pytest", user_id="u1")
client.add(messages=[{"role": "user", "content": "I like cats"}], user_id="u1")

# 语义检索
for r in client.search("测试框架偏好", user_id="u1")["items"]:
    print(r["content"], r["similarity"])

# 查看 / 更新 / 删除
client.get("mem-id-xxx")
client.update("mem-id-xxx", content="新内容")
client.delete("mem-id-xxx")

Metadata

Release files for lm-mem 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lm-mem 0.8.0
File Size Uploaded
lm_mem-0.8.0.tar.gz 47.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lm-mem 0.8.0
File Interpreter ABI Platform
lm_mem-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 86.0 kB

Release files / lm_mem-0.8.0.tar.gz

Download URL lm_mem-0.8.0.tar.gz
Size 47.9 kB
Tags Source
SHA-256 checksum
How to use checksums
544d5823edf20829fa08071463f569fdc7647ff9546d7012b00e6e2f4d0a5f9c
BLAKE2b-256 checksum
How to use checksums
ac2526f292ba950280f91a0969d1750454fdc5a6bab017de0b086a313516a7dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Release files / lm_mem-0.8.0-py3-none-any.whl

Download URL lm_mem-0.8.0-py3-none-any.whl
Size 38.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee1e0176a4df689a3459102b331eca3a38e96704731da8687bd1eb7e3546352d
BLAKE2b-256 checksum
How to use checksums
7a478aa42749fcf93dcfceab618a16c5ff2f95fd5cab33a423dcfa9d60b3bb65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.1

2 release files

This release

0.8.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page