Long-term memory for your agents — MCP server backed by SQLite FTS5.
Project description
KraangLong-term memory for your agents. |
Kraang is an MCP (Model Context Protocol) server that gives AI assistants persistent memory and session indexing, backed by SQLite with FTS5 full-text search and optional hybrid semantic search. It stores knowledge notes, indexes conversation transcripts, and surfaces what matters via search.
Why?
AI assistants forget everything between sessions. Kraang gives them persistent memory — decisions, debugging breakthroughs, patterns — so your next conversation picks up where the last one left off.
Requires Python 3.11+
Quick Start
The fastest way to get started is with kraang init:
uvx kraang init # ephemeral — downloads on each run
uv tool install kraang # persistent — install once, use everywhere
kraang init
This creates a .kraang/ directory, initializes the database, configures .mcp.json, adds .kraang/ to .gitignore, sets up a SessionEnd hook for automatic session indexing, creates .claude/rules/kraang.md with agent usage guidelines, and indexes any existing sessions.
Manual Configuration
Add to your MCP client configuration (e.g. Claude Code, Claude Desktop):
{
"mcpServers": {
"kraang": {
"command": "uvx",
"args": ["kraang", "serve"],
"env": { "KRAANG_DB_PATH": ".kraang/kraang.db" }
}
}
}
MCP Tools
| Tool | Description |
|---|---|
remember |
Save a note. Updates in place if the title exists, otherwise creates a new one. |
recall |
Search notes and conversation sessions. Scope to "notes", "sessions", or "all". |
read_session |
Load a full conversation transcript by session ID (use recall to find sessions first). |
forget |
Downweight or hide a note by adjusting its relevance score (0.0 = hidden, 1.0 = full). |
context |
Auto-recall relevant memories and return safety-framed XML for context injection. |
status |
Get a knowledge base overview: note/session counts, recent activity, top tags. |
CLI Commands
| Command | Description |
|---|---|
kraang init [PATH] |
Set up kraang for the current project (database, .gitignore, config, hooks, rules, initial index). |
kraang serve |
Run the MCP server (invoked by Claude Code). |
kraang index [PATH] [--from-hook] |
Index or re-index conversation sessions for the project. |
kraang sessions [-n LIMIT] [PATH] |
List recent conversation sessions (default: 20). |
kraang session <id> [-n MAX_TURNS] |
View a session transcript in detail. |
kraang search <query> [-n LIMIT] |
Search notes and sessions (default: 10). |
kraang notes [-a] [-n LIMIT] |
List notes in the knowledge base (-a includes forgotten). |
kraang status |
Show knowledge base health and statistics. |
Architecture
Kraang uses a layered architecture:
- Models (
models.py) -- Pydantic schemas for notes, sessions, and search results. - Store (
store.py) -- SQLite backend with FTS5 full-text search, BM25 ranking, vector storage, and brute-force cosine fallback. - Search (
search.py) -- Query parsing and FTS5 expression building. - Hybrid (
hybrid.py) -- Hybrid vector + keyword search with weighted merge and FTS fallback. - Embeddings (
embeddings.py) -- Embedding provider abstraction with OpenAI and local (fastembed) implementations, retry logic, and L2 normalization. - Safety (
safety.py) -- Prompt injection detection and safe context formatting for LLM consumption. - Indexer (
indexer.py) -- Reads Claude Code JSONL transcripts and indexes sessions. - Server (
server.py) -- MCP server exposing 6 tools over stdio. - CLI (
cli.py) -- Typer CLI for init, serve, index, and local queries. - Formatter (
formatter.py) -- Markdown formatting for MCP tool responses. - Display (
display.py) -- Rich console rendering for CLI commands. - Config (
config.py) -- Project root detection, database path resolution, and title normalization.
Semantic Search (optional)
Kraang supports hybrid semantic + keyword search for more intelligent recall. Queries like "that debugging trick from last week" work alongside exact keyword matches.
Semantic search works out of the box using local embeddings via fastembed (ONNX-based, runs on CPU). No API key required.
Providers
| Provider | Model | Dims | Setup |
|---|---|---|---|
| Local (default) | nomic-ai/nomic-embed-text-v1.5-Q |
768 | Works automatically |
| OpenAI | text-embedding-3-small |
1536 | Set OPENAI_API_KEY |
How it works
- Hybrid search: Combines vector similarity (70%) with keyword matching (30%)
- Zero config: Local embeddings are used by default — no API key needed
- Graceful degradation: If both providers fail, keyword search still works
- Embedding cache: Content-addressed cache avoids redundant computation/API calls
- Safety framing: The
contexttool wraps recalled memories with prompt injection protection
Environment variables
| Variable | Required | Default | Purpose |
|---|---|---|---|
KRAANG_EMBEDDING_PROVIDER |
No | auto-detect | Force "openai" or "local" |
KRAANG_EMBEDDING_MODEL |
No | — | Override the local model name |
OPENAI_API_KEY |
No | — | Enables OpenAI embeddings (auto-detected when set) |
KRAANG_DB_PATH |
No | <project_root>/.kraang/kraang.db |
Override database location |
Claude Code integration
When using kraang init, optionally add OPENAI_API_KEY to the generated .mcp.json to use OpenAI embeddings instead of local:
{
"mcpServers": {
"kraang": {
"command": "uvx",
"args": ["kraang", "serve"],
"env": {
"KRAANG_DB_PATH": ".kraang/kraang.db",
"OPENAI_API_KEY": "sk-..."
}
}
}
}
Development
git clone https://github.com/johnnygreco/kraang.git && cd kraang
uv sync --extra dev
make install-hooks # install pre-commit hooks (run once)
make test
make lint
Pre-commit hooks run automatically before each commit (ruff format, ruff check --fix, ty). Run manually:
uv run pre-commit run --all-files
Run the full check suite:
make coverage # tests + coverage report
make format # auto-format with ruff
Troubleshooting
| Problem | Fix |
|---|---|
| Kraang tools not showing up in Claude Code | Restart Claude Code after running kraang init |
| Sessions not being indexed automatically | Check that .claude/settings.json has the SessionEnd hook |
| Search returns nothing | Run kraang status to check counts, then kraang index to re-index |
| Need a fresh start | Delete .kraang/ and re-run kraang init |
License
Apache 2.0
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
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 kraang-0.2.3.tar.gz.
File metadata
- Download URL: kraang-0.2.3.tar.gz
- Upload date:
- Size: 263.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5898e2bf92ca33ac0504a0e3603cab64229d3e0306f564c5e6c3c0ff9270944
|
|
| MD5 |
c7f0064ce78dda37d6644cbc134aedf4
|
|
| BLAKE2b-256 |
209a5b5ce9891faead3d2992cb19f4af316e368abfac900a5d4bf847b88d3ec8
|
File details
Details for the file kraang-0.2.3-py3-none-any.whl.
File metadata
- Download URL: kraang-0.2.3-py3-none-any.whl
- Upload date:
- Size: 44.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34f0298a90c617fdb896e73e7247ce8b1d6672fbb0d6279b5bfd40a15ccb3aa6
|
|
| MD5 |
8113128109b80c8f6cb67ea1af89b31f
|
|
| BLAKE2b-256 |
59336d361840fedf146d0f6fdd426ac9f8095129f7f9ba627e3dad17ab5b39b1
|