Skip to main content

KMA — Kleinian Memory Architecture

KMA · Kleinian Memory Architecture

Memory that has a shape.
Hyperbolic, hierarchy-aware agentic memory for LLMs — structured, navigable, and explainable.

license python tests status


The one-line pitch

Most agent memory is a flat bag of vectors retrieved by cosine similarity. KMA gives your agent a memory with structure — a hyperbolic concept tree it can drill down, roll up, and explain — and it provably beats cosine on the one thing flat memory can't do: hierarchy.

It plugs into what you already use — any embedding model (OpenAI, Gemma, MiniLM), any vector DB (Pinecone, Chroma), any LLM host (via MCP) — and adds the structural layer on top at near-zero compute.


Why this is different

Flat vector memory answers exactly one question: "what is most similar?" That's necessary but not sufficient for an agent that reasons over a growing, branching history.

Flat vector memory KMA
Similarity recall ✅ ✅ (keeps cosine where it wins)
Hierarchy (parent / child / subtree) ❌ structurally impossible ✅ native, in hyperbolic space
"More general than" (asymmetric) ❌ cosine is symmetric ✅ generality = distance from center
Explainability ("why recalled?") ❌ opaque nearest-neighbor ✅ every hit carries its concept path
Auto-organization ❌ undifferentiated pile ✅ new memories self-place into a tree

The key idea, stated plainly: hyperbolic space embeds trees with almost no distortion, where flat Euclidean space cannot. So instead of crushing meaning into a point, KMA places each memory by direction (what it's about) and radius (how general it is) — roots near the center, details toward the rim.


What we've achieved

A working, end-to-end hyperbolic memory system — not just a paper idea:

  • A trained projection (φ) that maps any embedding into a hyperbolic ball, supervised by the memory tree itself. In small, controlled tests it clearly improves hierarchical / "what's the parent concept" retrieval over flat cosine, while holding parity on ordinary similarity.
  • An early end-to-end run on a real stack — EmbeddingGemma embeddings + a live Pinecone index — reproduced the same pattern, suggesting the gain is structural rather than a quirk of one embedder.
  • A full agentic-memory layer — auto-placement, provenance ("why was this recalled"), and lifecycle ops — exposed over MCP, so an LLM can use it as live long-term memory.

Honest scope: these are small, controlled experiments. The advantage is specifically on hierarchical / asymmetric retrieval — not on flat semantic similarity, which is cosine's home turf and where we only aim for parity. Larger, real-world hierarchies are on the roadmap.


Quickstart

pip install kleinian-memory          # import as `kma`
# optional extras:
#   [embed] real sentence embeddings · [train] torch chart · [mcp] connector

As an agent's memory — memories auto-place into a hierarchy, recall comes with provenance:

from kma.memory import AgenticMemory

mem = AgenticMemory()
mem.add("the user is building a travel app for hikers", scope={"user_id": "alice"})
mem.add("they prefer python and fastapi", scope={"user_id": "alice"})  # auto-placed

print(mem.get_context("what backend should I scaffold?", scope={"user_id": "alice"}))
# -> a compact, prompt-ready memory block, rolled up with its ancestors

As an MCP server for Claude Desktop / Claude Code — drop into .mcp.json:

{ "mcpServers": { "kma-memory": { "command": "kma-mcp" } } }

Exposes memory.add · search · get_context · forget · explain_address.


How it works

text ─▶ embedding (any model) ─▶ φ chart ─▶ point in a Poincaré ball ─▶ memory tree ─▶ store (any DB)
                                    │                    │
                          direction = meaning    radius = generality
  1. Embed with any model (a deterministic hashing fallback keeps it dependency-free).
  2. Project into an n-D hyperbolic ball — semantics set the direction, hierarchy sets the radius.
  3. Place the memory under its nearest concept automatically (no manual parenting).
  4. Retrieve with a hybrid of cosine (similarity) + hyperbolic structure (branch / generality) + recency / importance — and return the why alongside the what.

What's inside

Module Role
kma/memory.py AgenticMemory — add / search / get_context / update / forget + auto-placement
kma/engine.py embed → place → hybrid retrieval
kma/geometry.py the math heart: Poincaré-ball ops with learnable curvature
kma/chart.py · train.py the trainable projection φ and its objective
kma/extract.py LLM fact extraction (distill turns into atomic memories)
kma/mcp_server.py MCP connector for LLM hosts

Honest scope

  • Use KMA when structure matters: agent memory, taxonomies, is-a retrieval, drill-down / roll-up, explainable recall.
  • Don't bother for flat RAG / dedup / FAQ — there, an embedding + cosine + a vector DB is the right tool, and KMA adds nothing.
  • KMA is a layer, not a replacement: it sits between your embedder and your store. It does not claim to be a faster embedding or a Pinecone competitor.

Roadmap

  • Train on large real hierarchies (WordNet, arXiv) with entailment-cone loss for unseen-concept generalization.
  • LLM-driven branch consolidation (summarize dense subtrees) and decay-based forgetting.
  • SQLite / pgvector / Pinecone storage backends behind the current interface.
  • REST + LangChain / LlamaIndex adapters alongside MCP.

License

KMA — Copyright © 2026 Abhijit S R (@abhijit-without-h, git now-im-inevitable). Released under GNU AGPL-3.0-or-later — see LICENSE.

Strong copyleft, chosen so credit is preserved and improvements stay open. Note AGPL §13: if you run a modified version as a network service (MCP server / hosted API), you must offer your users its complete source under the same license. For commercial or closed use, contact the author for a separate license.

Metadata

Release files for kleinian-memory 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kleinian-memory 0.1.0
File Size Uploaded Provenance Actions
kleinian_memory-0.1.0.tar.gz 39.0 kB With provenance Details for kleinian_memory-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kleinian-memory 0.1.0
File Interpreter ABI Platform Actions
kleinian_memory-0.1.0-py3-none-any.whl Python 3 none any Details for kleinian_memory-0.1.0-py3-none-any.whl

Total release size: 85.4 kB

Release files / kleinian_memory-0.1.0.tar.gz

Download URL kleinian_memory-0.1.0.tar.gz
Size 39.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ada51e0bccb5c54c3e1b1627ff3f9ddfbd82a7b84d369564c8d10e2c14c99aa2
BLAKE2b-256 checksum
How to use checksums
9fd03041af21146336efe9d0c29907d4db6d44fd48a3912eab2c50b268ff89bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

Release files / kleinian_memory-0.1.0-py3-none-any.whl

Download URL kleinian_memory-0.1.0-py3-none-any.whl
Size 46.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d5197d9f1815c17360b96798b7b971b89244d6068a46a951f6591fcf839984a
BLAKE2b-256 checksum
How to use checksums
8f743ce53171fdf8e8213e495ddeced20171a29feddd70b60e46b76ce28d72fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

Security for kleinian-memory 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kleinian_memory-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page