Leiden-chunked, graph-linked semantic memory as an MCP server for Claude, Copilot, and any MCP-compatible AI
Project description
swafra
Semantic memory for AI — ingest anything, retrieve what matters.
94.7% recall_all@10 on LongMemEval — the standard benchmark for long-term memory in AI assistants.
Works as an MCP server with Claude Desktop, Claude Code, VS Code Copilot, and any MCP-compatible AI.
Install
pip install swafra
Or with Node.js:
npm install -g swafra
Both work independently — install one or both, no conflicts.
Upgrade
pip install --upgrade swafra
Or:
npm update -g swafra
Quick start
# 1. Install
pip install swafra
# 2. Connect to Claude Code
claude mcp add swafra -- swafra serve
# 3. Install enforcement hooks (ensures Claude always uses memory)
swafra setup
# Done — Claude will now remember across sessions
CLI
swafra
Shows your full knowledge graph dashboard — sources, chunks, edges, communities, entities, facts, storage size.
| Command | What it does |
|---|---|
swafra |
Show knowledge graph stats dashboard |
swafra stats |
Same as above |
swafra serve |
Start the MCP server |
swafra setup |
Install enforcement hooks for Claude Code |
swafra remove |
Disable hooks (keeps all data) |
swafra remove global |
Remove hooks + delete all stored knowledge |
swafra help |
Show usage |
Connect to Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"swafra": {
"command": "swafra",
"args": ["serve"]
}
}
}
Restart Claude Desktop — the tools appear automatically.
Connect to Claude Code
claude mcp add swafra -- swafra serve
Then install enforcement hooks so Claude always retrieves memory:
swafra setup
Connect to VS Code (Copilot)
Add to .vscode/mcp.json in your project:
{
"servers": {
"swafra": {
"command": "swafra",
"args": ["serve"]
}
}
}
Enforcement hooks
Running swafra setup installs Claude Code hooks that ensure Claude:
- Always calls
get_contextat the start of every session (Stop hook wakes Claude back up if it forgets) - Proactively stores knowledge without waiting to be asked
- Never says "I don't have context" without checking memory first
Three layers of enforcement:
| Layer | Mechanism | Reliability |
|---|---|---|
| Tool descriptions | "MANDATORY: call before first response" | High — visible every turn |
| CLAUDE.md | Rules injected into ~/.claude/CLAUDE.md |
Medium — system prompt |
| Stop hook | Wakes Claude back up if it skips memory | Guaranteed |
To disable: swafra remove
What you can do
Once connected, Claude remembers and retrieves automatically:
"Remember this meeting transcript: ..."
"What did we decide about the API design?"
"What are my editor preferences?"
"Forget everything from the project X sessions"
Tools
| Tool | What it does |
|---|---|
add_knowledge |
Store text — chunked, embedded, and graph-linked |
search_knowledge |
Find relevant chunks by natural language query |
get_context |
Search + graph walk combined (recommended) |
graph_walk |
Explore connected chunks from a starting point |
list_sources |
See everything stored |
delete_source |
Remove a source and all its data |
How it works
1. Chunking Text is split into semantically coherent chunks using Leiden community detection — a graph algorithm that groups sentences by topic. Falls back to conversation-aware chunking if Leiden deps aren't available.
2. Local embeddings
Uses fastembed (ONNX, CPU-only, no API key) with BAAI/bge-small-en-v1.5. Falls back to deterministic hash vectors if fastembed isn't installed.
3. Hybrid retrieval 4-signal fused scoring: BM25 + vector cosine + entity/date overlap + character n-gram. Returns the best chunk per source for diverse, non-redundant context.
4. Knowledge graph Chunks are connected with sequential (next/prev), similarity, entity co-occurrence, and cross-session edges. Graph walk expands retrieval beyond what search alone finds.
5. Fact lifecycle Structured facts are extracted from chunks. When a new fact conflicts with an old one (e.g. "favorite editor" changes), the old fact is superseded — stale chunks get penalized in search.
6. Storage
JSON files in ~/.scimap/. No database, no server, no cloud. Everything runs locally.
Benchmark
94.7% recall_all@10 on LongMemEval-S — 500 questions across 6 categories, 53 sessions each.
| Category | recall_all@10 |
|---|---|
| knowledge-update | 100.0% |
| single-session-user | 100.0% |
| single-session-preference | 100.0% |
| single-session-assistant | 100.0% |
| temporal-reasoning | 99.2% |
| multi-session | 93.3% |
Full benchmark details and reproduction steps →
Platform support
| Feature | macOS | Linux | Windows |
|---|---|---|---|
| Stats dashboard | ✓ | ✓ | ✓ |
| MCP server | ✓ | ✓ | ✓ |
| Enforcement hooks | ✓ | ✓ | WSL / Git Bash |
Environment variables
| Variable | Default | Description |
|---|---|---|
SCIMAP_DATA_DIR |
~/.scimap |
Where knowledge is stored |
SCIMAP_EMBED_MODEL |
BAAI/bge-small-en-v1.5 |
Embedding model |
Uninstall
# Remove hooks only (keep data)
swafra remove
# Remove everything (hooks + data)
swafra remove global
# Remove MCP registration
claude mcp remove swafra
# Uninstall package
pip uninstall swafra
# or
npm uninstall -g swafra
License
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 swafra-0.2.7.tar.gz.
File metadata
- Download URL: swafra-0.2.7.tar.gz
- Upload date:
- Size: 32.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49a55af3c7a0c9869f7ad636b07dc4f827b6ef1a62d3a4a04603e20ff9ba82ee
|
|
| MD5 |
f11215d95282cce1c34e6c78e3c892f0
|
|
| BLAKE2b-256 |
7d87793bf1b45f280eae6543b0a7ce4ddbaa01cba9e68401ac6c1bdd30a543ab
|
File details
Details for the file swafra-0.2.7-py3-none-any.whl.
File metadata
- Download URL: swafra-0.2.7-py3-none-any.whl
- Upload date:
- Size: 32.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d6bbc406c70fee74bc153a7adf9b9b4fdb89bee5b17340c38b4be21021b28cf
|
|
| MD5 |
037cbff276261d5a54c7277f0ece6080
|
|
| BLAKE2b-256 |
eed6758722f451701d4fd11aeb67bad1b636440013f39f1078c15561ac4fac94
|