Skip to main content

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

Upgrade

pip install --upgrade swafra

Or with Node.js:

npm update -g swafra

CLI

After installing, run swafra in your terminal to see your knowledge graph stats:

swafra

Shows: sources, chunks, edges, communities, entities, facts, storage size, and more.

Command What it does
swafra Show knowledge graph stats dashboard
swafra stats Same as above
swafra serve Start the MCP server
swafra help Show usage

Connect to Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "swafra": {
      "command": "swafra"
    }
  }
}

Restart Claude Desktop — the tools appear automatically.


Connect to Claude Code

claude mcp add swafra swafra

Connect to VS Code (Copilot)

Add to .vscode/mcp.json in your project:

{
  "servers": {
    "swafra": {
      "command": "swafra"
    }
  }
}

What you can do

Once connected, Claude can use swafra to remember and retrieve anything:

"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 (Python 3.13+).

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 so you get diverse, non-redundant context.

4. Knowledge graph Chunks are connected with sequential (next/prev), similarity, and entity co-occurrence edges. Graph walk expands retrieval beyond what search alone finds.

5. Storage JSON files in ~/.scimap/. No database, no server, no cloud.


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 →


Environment variables

Variable Default Description
SCIMAP_DATA_DIR ~/.scimap Where knowledge is stored
SCIMAP_EMBED_MODEL BAAI/bge-small-en-v1.5 Embedding model

License

MIT — github.com/kunal12203/swafra

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swafra-0.2.6.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swafra-0.2.6-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file swafra-0.2.6.tar.gz.

File metadata

  • Download URL: swafra-0.2.6.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for swafra-0.2.6.tar.gz
Algorithm Hash digest
SHA256 f5366f28254c53dfa6870d119da334fab3409cfeec0ee1e00b9fc4dc7fe82932
MD5 ad3247220202440605b7535b84bc7754
BLAKE2b-256 bfe044b6d18377491bbd459336698526f9ac0fd9e24922059ea332cd004749d0

See more details on using hashes here.

File details

Details for the file swafra-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: swafra-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for swafra-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4835f7f4f5b67f8cd4161abc47f6c94d7abecc0b96e0e8d5e6c92dd43e4b5987
MD5 10f57fcefecf115ab7d48dbad2e11921
BLAKE2b-256 9fd7ec072c33f307c40fd383cb00a0032280ab7b3483c5c23d643bb972933974

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page