
Kairn
io.github.primeline-ai由 GitHub 账号 primeline-ai 发布v0.3.2更新于 Nov 7, 2026
Local-first knowledge engine for AI agents: memory, graph, and recall over MCP.
概览
本地优先的知识引擎,通过 MCP 为 AI 助手提供持久知识图谱、带衰减的经验记忆与上下文召回。
- 可以做什么
- 存储与召回知识:按置信度路由学习事实、召回过往知识、查找相似的历史解决方案,并根据关键词加载相关子图。
- 管理知识图谱:添加节点、建立带类型的边、记录关系判断、按文本/类型/标签/命名空间查询、遍历关联节点,以及软删除。
- 处理经验记忆:保存带衰减的经验、记录用户偏好、按衰减搜索记忆、清理过期经验,并把高频访问的经验提升为永久节点。
- 跟踪项目与想法:创建或更新项目、切换当前项目、记录进展或失败,以及创建或列出想法。
- 检查健康状况:只读诊断与图谱统计,并提供只读资源和会话启动、回顾用的提示词。
- 适用场景
- 适合希望助手跨会话、跨项目记住决策、坑点、模式和偏好,无需反复解释,并能取回恰当上下文而非平铺笔记的场景。也适合在 Claude Code、Codex、Cursor、VS Code 或 Claude Desktop 中工作、希望记忆完全留在本机的开发者。
- 运行要求
- 以本地进程运行:安装 kairn-ai Python 包,或使用一键安装包(通过 uv 解析同一个包)。需要一个工作区目录存放 SQLite 数据库;KAIRN_WORKSPACE 决定配置读取位置,serve 命令默认使用 ~/.kairn。可选的语义召回需要本地 Ollama 服务器和嵌入模型。团队功能需要 KAIRN_JWT_SECRET。
安装
在 SourceWeft 中
- 打开 控制台中的 Kairn,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
Kairn
Watch the 30-second tour on GitHub.
Context-aware knowledge engine for AI assistants.
Status: pre-1.0. In daily use since February 2026, with a test suite that runs on Linux, macOS and Windows (see Development) and a published LongMemEval-S benchmark (measured before 0.3.0). Interfaces may still change between releases until 1.0. Feedback and issues welcome.
Other tools give your AI a memory. Kairn gives it a knowledge graph with intelligent context routing. It knows what to load, when to load it, and how much - so your AI stays focused, not overwhelmed.
Claude Code and Codex each take one line; --init creates ~/brain and its database on first start, so this works even without kairn init:
Or install it as a one-click bundle, no Python setup required: download the
.mcpb file from the latest release
and open it with a bundle-aware app such as Claude Desktop.
For other clients, see Quick Start below. New to Kairn? Jump to First 5 Minutes.
Install routes
The bundle carries no Kairn source of its own. It declares kairn-ai as a
dependency and the host resolves it with uv, so a bundle install and a
pip install run identical code. Where the database lives is configurable when
you install the bundle; it defaults to ~/.kairn and never leaves your machine.
Why Kairn?
Every AI conversation starts from scratch. Previous insights, decisions, and patterns - gone. Existing memory tools store flat key-value pairs that can't represent relationships or surface the right context at the right time.
Kairn is different:
- Context Router + Progressive Disclosure - Automatically loads relevant subgraphs based on keywords, starting with summaries and drilling into details only when needed. No other tool does this.
- Knowledge Graph with FTS5 - Not flat storage. Typed relationships (
depends-on,resolves,causes) between nodes with provenance tracking and full-text search across everything. - Experience Decay + Auto-Promotion - Experiences lose relevance over time (biological decay model). Frequently-accessed experiences auto-promote to permanent knowledge. Your AI naturally forgets what doesn't matter.
- 22 MCP Tools - Works with Claude Code, Codex, Claude Desktop, Cursor, VS Code, Windsurf, and any MCP client. Includes
kn_judgefor 5-verb relationship judgments andkn_doctorfor read-only health diagnostics. - Per-Workspace Isolation - Each workspace is its own isolated SQLite store. JWT auth and role-based access control (owner / maintainer / contributor / reader) ship for team deployments.
Quick Start
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows:
Cursor
Add to .cursor/mcp.json:
VS Code
Add to .vscode/mcp.json:
Windsurf
Add to ~/.codeium/windsurf/mcp_config.json:
Restart your editor. Kairn's 22 tools appear in the MCP section.
First 5 Minutes
A guided first run, end to end:
Add the one-liner from above (or your client's Quick Start snippet), then restart the client. Once connected, ask your assistant to remember something:
"Remember that we chose Postgres over SQLite for the analytics service because we needed concurrent writers."
That calls kn_learn under the hood and returns a JSON envelope like this (captured from a real run, via kairn learn, the CLI mirror of the tool):
Start a new session and ask it to recall the same thing - that calls kn_recall and surfaces what you just stored, no re-explaining required:
kn_learn stored both a permanent graph node and a decaying experience (high confidence does both, see Confidence routing); kn_recall found both from a three-word topic.
Read relevance_kind before you read relevance. match is lexical match strength (bm25). match_recency is match strength with a small recency nudge, a factor between 0.9 and 1.1, on an experience found by a text search. recency is pure time-decay on an experience listed with no search text: it says how old the row is, not whether it matched. similarity is embedding cosine on the semantic-recall path, and unscored marks a row the surface had no ranking for and filled in with a constant, from crossref or a text-less browse query. Both rows above show 1e-06 because SQLite's bm25 gives almost no weight to a word that appears in most entries. On a store with one fact every word does, so the score sits at SQLite's floor. It is not a bad match. After eight more unrelated facts, the same recall measured about 0.5 for both rows. On a store this small, a topic with a word the fact does not contain can score 0.0, and the row is still returned. Scores are only comparable within one result set and are not comparable across kinds, so do not sort a mixed result set on relevance alone. Same caution for min_relevance on kn_recall: it gates nodes on match strength and experiences on recency, one number against two scales. On a small store, a value such as 0.1 drops the node and keeps the experience (measured). On kn_memories and kn_prune, which see experiences only, it is recency - and on kn_prune it deletes.
Run kairn status ~/brain any time as a smoke test - if it prints a JSON stats block (nodes/edges/experiences counts), the workspace is healthy. For a scripted tour, kairn demo adds sample data (two nodes, one edge and two experiences, measured) to the workspace it is given, so give it a throwaway one: kairn init ~/kairn-tour && kairn demo ~/kairn-tour.
Which tool when
22 tools is a lot to hold in your head on day one. Most sessions only need these:
Everything else (kn_crossref, kn_related, kn_connect, kn_judge, kn_project/kn_projects/kn_log, kn_idea/kn_ideas, kn_promote_pending, kn_prune, kn_remove, kn_status, kn_doctor) is advanced usage - see the full 22 Tools reference below once you're past the basics.
22 Tools (kn_ prefix)
All tools follow MCP protocol with JSON responses.
Graph (6)
Project Memory (3)
Experience Memory (5)
Ideas (2)
Intelligence (5)
Diagnostic (1)
Resources & Prompts
Resources (read-only context for MCP clients):
kn://status- Graph overview, active projectkn://projects- All projects with recent progresskn://memories- Recent high-relevance experiences
Prompts (session management):
kn_bootup- Load active project, recent progress, and top memories (session start)kn_review- Summarize session and suggest next steps (session end)
How It Works
Architecture
Decay Model
Experiences decrease in relevance exponentially:
Half-lives are calibrated against the real access tail of a production experience store, not guessed (one exception: preference is a new type with no access history yet, so its value is a documented initial estimate until real data accumulates).
Confidence routing via kn_learn:
high→ Permanent node + experience (no decay)medium→ Experience with 2× decaylow→ Experience with 4× decay- Auto-promotion: 5+ accesses → permanent node
- Node access tracking:
kn_recall,kn_context, andkn_crossreflog which nodes were accessed, feeding the decay and promotion pipeline
Benchmarks
Kairn scored 56.2% overall on LongMemEval-S in the 2026-06-12 run (500/500 questions scored, GPT-4o reader + judge, single run, 0 errors). These are the real per-category numbers, including the bad ones - each red cell links to its diagnosis:
The 500 questions include 30 abstention variants (the right answer is to decline); they are counted inside their categories above and scored separately: Kairn declines correctly on 96.7% of them.
Recall latency was ~1.4 ms per query in that run (FTS5, in-process, no network). Protocol, honesty notes, and reproduction steps: BENCHMARKS.md.
These numbers were measured on 2026-06-12, before the recall changes in 0.3.0 (match-aware experience scoring, coverage-weighted node relevance), and have not been re-measured on 0.3.0 yet. A weak cell stays on the board until the number actually moves. No cherry-picked runs, no hidden categories.
CLI
Run kairn <command> --help for every option.
Importing your history
kairn import git <workspace> <repo>... backfills a Kairn store from one or
more local git repositories at $0 - no LLM calls, no network calls. Conventional-commit
prefixes map to experience types (fix: -> solution, feat:/refactor:/perf: -> pattern,
everything else -> decision); merge commits are skipped. Imported experiences land in a
dedicated imported-git namespace, separate from your organic knowledge, so they're always
distinguishable and a bad import is fully reversible.
Idempotent - re-running only imports commits that weren't already imported, so it's safe to run again as a repo's history grows.
Claude Code transcripts
kairn import claude-code <workspace> backfills your Kairn store from your existing
Claude Code session history, also at $0 and fully offline. With no --root given it scans
~/.claude/projects; --root PATH is a repeatable override for any other folder. Imported experiences land in their own
imported-claude-code namespace, so they stay distinct from your organic knowledge and a
bad import is reversible.
What gets stored (coarse mode): one experience per session - the session's title plus
your first prompt of that session. This is deliberately a low-detail, high-precision summary
rather than a fine-grained per-decision extraction: a zero-LLM rule-based extractor cannot
reliably tell a captured decision from ordinary planning chatter, so import claude-code
imports a clean session-level pointer instead of noisy fragments. It is not a full transcript
archive, and it is not a one-time migration - it is idempotent and meant to be re-run as your
history grows.
Privacy. Every stored string is passed through a deterministic secret redactor first
(API keys, Authorization/Bearer headers, password=/token=/secret= assignments,
common vendor key shapes, private-key blocks, URL-embedded credentials). Tool outputs and
tool-call blocks are never read, only your own prompt text. The redactor is defense in depth,
not the only control: a real (non-dry-run) run is gated behind an explicit confirmation, and
--dry-run shows you the exact post-redaction text before anything is written. Redaction is
bounded by its rule set, so --dry-run review before a first real import is recommended;
nothing ever leaves your machine.
Install as a plugin
The plugin needs uv.
Claude Code:
Codex:
If you already added Kairn with claude mcp add kairn or codex mcp add kairn, remove that entry first with claude mcp remove kairn or codex mcp remove kairn, or keep only one installation route, because both use the name kairn.
See the plugin README for what it does and the codex exec approval note.
Configuration
Settings live in <workspace>/config.yaml; kairn init writes it and serve --init does not, so create it by hand if you started with serve --init. Without it the defaults apply. Semantic recall is opt-in and off by default. It reranks recall with embeddings from a local Ollama server, so stored content never leaves your machine.
Development
Cutting a release: see RELEASING.md.
Project Structure
Performance
Measure it yourself rather than trusting this table:
It runs in a temporary workspace that it removes afterwards, so your data is not touched. The numbers come from a fresh, empty store in the system temp folder, so they show the shape of Kairn's speed, not the speed of your own store or disk.
One run of that command, 100 nodes, on an Apple M4 Pro:
Single run on one machine, so treat it as a shape rather than a spec - which is
why the command is above the table. kn_connect and kn_crossref used to
appear here with figures the benchmark does not produce; they have been removed
rather than estimated.
Used By
License
MIT
Part of the PrimeLine Ecosystem
来源:README.md,提交 435753e
工具
0版本历史
4- v0.3.2最新Nov 7, 2026
- v0.3.1Oct 11, 2026
- v0.3.0Oct 11, 2026
- v0.2.1Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分