Context-aware knowledge engine for AI — memory, graph, intelligent routing
Project description
Kairn
Context-aware knowledge engine for AI assistants.
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.
pip install kairn-ai
kairn init ~/brain
kairn serve ~/brain
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 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.
- 18 MCP Tools — Works with Claude Desktop, Cursor, VS Code, Windsurf, and any MCP client.
- Team Workspaces with RBAC — Per-workspace isolation with JWT auth and role-based access control.
Quick Start
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"kairn": {
"command": "kairn",
"args": ["serve", "~/brain"]
}
}
}
Cursor
Add to .cursor/mcp-servers.json:
{
"mcpServers": {
"kairn": {
"command": "kairn",
"args": ["serve", "~/brain"],
"env": {
"KAIRN_LOG_LEVEL": "WARNING"
}
}
}
}
Restart your editor. Kairn's 18 tools appear in the MCP section.
18 Tools (kn_ prefix)
All tools follow MCP protocol with JSON responses.
Graph (5)
| Tool | Description |
|---|---|
kn_add |
Add node to knowledge graph |
kn_connect |
Create typed edge between nodes |
kn_query |
Search by text, type, tags, namespace |
kn_remove |
Soft-delete node or edge (undo-safe) |
kn_status |
Graph stats, health, system overview |
Project Memory (3)
| Tool | Description |
|---|---|
kn_project |
Create or update project |
kn_projects |
List projects, switch active |
kn_log |
Log progress or failure entry |
Experience Memory (3)
| Tool | Description |
|---|---|
kn_save |
Save experience with decay |
kn_memories |
Decay-aware experience search |
kn_prune |
Remove expired experiences |
Ideas (2)
| Tool | Description |
|---|---|
kn_idea |
Create or update idea |
kn_ideas |
List/filter ideas by status, category |
Intelligence (5)
| Tool | Description |
|---|---|
kn_learn |
Store knowledge with confidence routing |
kn_recall |
Surface relevant past knowledge |
kn_crossref |
Find similar solutions across workspaces |
kn_context |
Keywords → relevant subgraph with progressive disclosure |
kn_related |
Graph traversal (BFS/DFS) to find connected ideas |
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
Any MCP Client (Claude, Cursor, VS Code)
│
▼ MCP Protocol (stdio)
FastMCP Server (18 tools)
│
┌────┼────┐
▼ ▼ ▼
Graph Memory Intelligence
Engine Engine Layer
│ │ │
└────┼──────┘
▼
SQLite + FTS5
(per-workspace)
Decay Model
Experiences decrease in relevance exponentially:
relevance(t) = initial_score × e^(-decay_rate × days)
| Type | Half-life | Notes |
|---|---|---|
| solution | 200 days | Stable, durable |
| pattern | 300 days | Architectural knowledge |
| decision | 100 days | Context-dependent |
| workaround | 50 days | Temporary fixes fade fast |
| gotcha | 200 days | Tricky pitfalls stay relevant |
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
CLI
kairn init <path> # Initialize workspace
kairn serve <path> # Start MCP server (stdio)
kairn status <path> # Graph stats
kairn demo <path> # Interactive tutorial
kairn benchmark <path> # Performance benchmarks
kairn token-audit <path> # Audit tool token usage
Configuration
KAIRN_LOG_LEVEL=INFO|DEBUG|WARNING # Default: WARNING
KAIRN_DB_PATH=~/brain/.kairn # Default: {workspace}/.kairn
KAIRN_CACHE_SIZE=100 # LRU cache entries
KAIRN_JWT_SECRET=<your-secret> # Required for team features
Development
git clone https://github.com/kairn-ai/kairn
cd kairn
pip install -e ".[dev,team]"
pytest tests/ -v --cov
ruff check src/ && ruff format src/
Project Structure
src/kairn/
├── server.py # FastMCP server + 18 tools
├── cli.py # CLI commands
├── config.py # Configuration
├── core/
│ ├── graph.py # GraphEngine (5 tools)
│ ├── memory.py # ProjectMemory (3 tools)
│ ├── experience.py # ExperienceEngine (3 tools)
│ ├── ideas.py # IdeaEngine (2 tools)
│ ├── intelligence.py # IntelligenceLayer (5 tools)
│ └── router.py # ContextRouter
├── storage/
│ ├── base.py # Storage interface
│ └── sqlite_store.py # SQLite + FTS5 implementation
├── models/ # Data models
├── events/ # Event bus
└── auth/ # JWT + RBAC (team feature)
Performance
Typical operation times on modern hardware:
| Operation | Time |
|---|---|
kn_add |
2-5ms |
kn_query (100 nodes) |
5-15ms |
kn_connect |
1-3ms |
kn_recall (graph traversal) |
10-50ms |
kn_crossref (cross-workspace) |
20-100ms |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kairn_ai-0.1.0.tar.gz.
File metadata
- Download URL: kairn_ai-0.1.0.tar.gz
- Upload date:
- Size: 82.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1221a53688feee761ec1b4e3cf5813ea8061669d1c756c5b3cc01125a0db707
|
|
| MD5 |
204f03566f6b591222bea2a8e80fa6a0
|
|
| BLAKE2b-256 |
f061fde3758c108f3b473780b0d840f5a2795f8c940d7ae293d978d4e1106806
|
File details
Details for the file kairn_ai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kairn_ai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 50.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a769168f5982247a71457f543adc7869d094840770444e46cb5a8f2532b0f1e3
|
|
| MD5 |
5af5e7fb6ff56a6527e2cc1d8e5d4917
|
|
| BLAKE2b-256 |
5839ab96a47771abbd7f5877a28240ad6cff19e40cc4f8e0501fd751591d5d53
|