Skip to main content

Persistent memory for AI agents. Three methods. Zero infra.

Project description

kemi

Persistent memory for AI agents. Three methods. Zero infra.

asciicast

from kemi import Memory

memory = Memory()  # SQLite + local embeddings, no API keys needed

memory.remember("user123", "User prefers dark mode")
memory.remember("user123", "User is vegetarian")

results = memory.recall("user123", "what are the user's preferences?")
# Returns ranked, deduplicated memories

memory.forget("user123")  # GDPR-compliant deletion

Install

# Zero dependencies — SQLite storage, no embedding (bring your own)
pip install kemi

# With local embeddings (no API key needed, ~130MB model download)
pip install kemi[local]

# With OpenAI embeddings
pip install kemi[openai]

Why kemi

Every existing memory library either hosts your data on their servers, requires Docker and 4 services to run, or locks you into a specific framework.

kemi is different:

  • Zero infrastructure — runs on your machine, single pip install
  • Your data — never leaves your machine, stored in SQLite by default
  • Bring your own embedding — OpenAI, local models, or any function
  • Framework agnostic — works with LangChain, CrewAI, AutoGen, or plain Python
  • 100% free — MIT license, no paid tiers, no cloud lock-in

Usage

Zero-config (local embeddings)

from kemi import Memory

memory = Memory()
memory.remember("user123", "User is vegetarian", importance=0.9)
results = memory.recall("user123", "food preferences")

With OpenAI embeddings

from kemi import Memory
from kemi.adapters.embedding.openai import OpenAIEmbedAdapter

memory = Memory(embed=OpenAIEmbedAdapter())
memory.remember("user123", "User prefers concise responses")
results = memory.recall("user123", "communication style")

Async usage (FastAPI, asyncio)

from fastapi import FastAPI
from kemi import Memory

app = FastAPI()
memory = Memory()

@app.post("/chat")
async def chat(user_id: str, message: str):
    await memory.aremember(user_id, message)
    context = await memory.acontext_block(user_id, message)
    return {"context": context}

Inject into system prompt

context = memory.context_block("user123", query="user preferences", max_tokens=500)
# Returns formatted string ready for system prompt injection

GDPR-compliant deletion

memory.forget("user123")               # Delete all memories for user
memory.forget("user123", memory_id)    # Delete one specific memory

How it works

kemi sits between your agent and your storage. It handles:

  • Semantic deduplication — "I'm vegetarian" and "I don't eat meat" are the same memory
  • Importance-weighted scoring — recent, important memories rank higher
  • Temporal decay — memories fade if never recalled
  • Conflict detection — flags contradictory memories for review
  • Lifecycle management — active → decaying → archived → deleted

Adapters

Type Default Available
Embedding fastembed (local) OpenAI, custom
Storage SQLite JSON, custom

Integrations

MCP Server

Any MCP-compatible agent (Claude, Cursor, Continue) can use kemi as memory:

pip install kemi[mcp]
python -m kemi.mcp_server

LangChain

from kemi import Memory
from kemi.integrations.langchain import KemiMemory
memory = Memory()
chat_memory = KemiMemory(user_id="alice", memory=memory)

Export / Import

memory.export("backup.json")  # backup all memories
memory.import_from("backup.json")  # restore from backup

Documentation

License

MIT — free forever, no exceptions.

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

kemi-0.3.0.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

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

kemi-0.3.0-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file kemi-0.3.0.tar.gz.

File metadata

  • Download URL: kemi-0.3.0.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for kemi-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d0456b81f9f92e013cc8c3542d79e0175a98cb70b4c38cc6a87bc426826091e2
MD5 9e672c3c87e619e99dd452707ce1e1e5
BLAKE2b-256 661859ef5f7056e86b5a41ef581c905adb9f7aa0ddfde53a2e6df1faeb11337c

See more details on using hashes here.

File details

Details for the file kemi-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: kemi-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for kemi-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf366c92db0d37de544c8011be0bdfb92bda677bb9aaa24264bf867f15015116
MD5 f4eb8e92838cc1d92d2669e4da26fd64
BLAKE2b-256 c692a2ec9d6d5ee8bdb92d12c28e25692a758971ec5c369b53b0a4dfe2a5820e

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