Lmemory 本機 AI 記憶與 Obsidian 檢索 Skill

將 AI 程式開發助手接入本機 Markdown / Obsidian 知識庫,基於 SQLite FTS5 全文索引與 MCP 返回帶檔案路徑和行號的證據回執,區分已取代決定與參考資料,無依據時誠實返回 none。

Tink2.1.32026年11月23日MIT原始碼儲存庫
取得 Skill

使用需求

  • Python 3.9 及以上版本,支援 SQLite FTS5
  • 本機 Markdown 或 Obsidian 知識庫目錄(OBSIDIAN_VAULT)
  • 支援 Skill 或 MCP 的宿主:Codex、Claude Code、Claude Desktop、Antigravity 等

快速開始

1. 複製並安裝 Lmemory

git clone https://github.com/TinkCarlos/Lmemory.git
cd Lmemory
python3 -m venv .venv
. .venv/bin/activate
python -m pip install .
lmemory demo --lang zh

也可直接執行 v2.1.3 固定版本示範:

uvx --from git+https://github.com/TinkCarlos/[email protected] lmemory demo --lang zh

2. 安裝 Skill 套件

將壓縮檔內的 lmemory/ 目錄解壓至 ~/.agents/skills/lmemory(或對應宿主 Skills 目錄),並將 OBSIDIAN_VAULT 指向你的 Markdown 知識庫根目錄。

3. 透過 MCP 接入 Codex

[mcp_servers.lmemory]
command = "/absolute/path/to/Lmemory/.venv/bin/lmemory"
args = ["--vault", "/筆記目錄的絕對路徑", "mcp"]

[mcp_servers.lmemory.env]
LMEMORY_NO_QUERY_LOG = "1"

為什麼做可核對出處的本機記憶

Lmemory 基於開源專案 KRouter 改造並依 MIT 授權獨立維護,讓 Codex、Claude Code、Cursor 與 Antigravity 共享同一份本機 Markdown 規則、糾錯紀錄與對話摘要,不依賴雲端黑盒、圖資料庫或個人檢索 API 金鑰。

Skill 核心工作流

  1. 每次開工前呼叫 route_knowledge.sh status(或 lmemory_status)確認知識庫與夜間維護健康狀態。
  2. 依查詢意圖分流路由:preference、correction、memory、project 或 search。
  3. 嚴格遵守回執的三檔記憶狀態:
  • memory: direct:現行生效原文存在完整支撐句或精確環境變數/識別碼命中;
  • memory: related:返回候選路徑與段落行號(如 L8 (passage L6-L8)),助手必須開啟原文核對後才能作答;
  • memory: none:庫裡沒有依據,直接說明不知道,禁止順著相似詞編造。
  1. 自動壓制已標註 superseded 的舊規則,並將剪藏與外部調研隔離在 knowledge_base: 參考資料層。
  2. 金鑰/憑證頁僅返回路徑或遮罩標記,絕不將明文秘密印進對話。

v2.1.3 實測指標

  • 1,801 頁 Markdown 庫冷啟動首問中位數由 7.334s 降至 5.818s(提速 20.7%),跨專案出處命中率 99.80%(1,012 / 1,014);
  • 24 題合成樣本上下文載荷從整篇原文 72,864 tokens 降至結構化回執 14,644 tokens,節省 79.9% 上下文開銷。
Skill 內部
SKILL.md
---
name: lmemory
description: Lmemory Obsidian — route knowledge-dependent tasks to the smallest current evidence set in an Obsidian vault using deterministic local search. Use when a request depends on durable user preferences, prior corrections or superseded claims, long-term project history or results, reusable methods or evidence, or the current vault and automation state. Return evidence in-process; do not spawn a retrieval model or add embeddings.
---

# Lmemory Obsidian

Set `OBSIDIAN_VAULT` to the vault root. Run retrieval in the current process. Do not spawn a retrieval agent. Do not add vector storage.

Router script (after install): `$HOME/.agents/skills/lmemory/scripts/route_knowledge.sh`. On Windows use `python3 route_knowledge.py` (same routes).

## Workflow

1. Run `route_knowledge.sh status`. If the receipt has `host_action:`, tell the host that line (paste `*_API_KEY` on `90 系统文件/自动化/自进化钥匙.md`, or log in `grok` / official Codex / `claude` once; or the nightly upkeep is skipped / failing — `nightly:` says which, `90 系统文件/自动化/夜间维护.md` says why). Do not print secrets. Then continue the user's question.
2. Choose one route: `status` for current system state; otherwise `preference`, `correction`, `memory`, `project`, or `search`.
3. Send one distinguishing noun, or a short question (a few words). Do not paste the whole conversation. Do not string unrelated keywords together as if they were AND.
包含檔案 · 39
lmemory/SKILL.md
lmemory/scripts/answer_cards.py
lmemory/scripts/ask_product.py
lmemory/scripts/associate.py
lmemory/scripts/backup.py
lmemory/scripts/canonical_lookup.py
lmemory/scripts/canonical_sources.psv
lmemory/scripts/capture_ledger.py
…