Skip to main content

cortex-ai

Four-layer cognitive memory for AI agents. Persistent recall across sessions, semantic search, a knowledge graph, and a learning system that evolves from your corrections. No API key required — runs locally on CPU.

pip install cortex-recall
cortex init

What it does

AI agents have amnesia. Every new conversation starts blank. cortex-ai gives them memory that works like a brain — organized, searchable, and self-maintaining.

Layer Name What it does
L1 Identity Who the agent is, rules, personality (always loaded)
L2 Recall 72h deterministic short-term log + semantic search across history (on demand)
L3 Knowledge External docs, vendor manuals, reference material (RAG)
L4 Evolution Learns from corrections, promotes patterns to permanent rules
L5 Pattern Detection Clusters correction events using sentence-transformers, auto-promotes to feedback files

Plus Dream (Default Mode Network): background maintenance that prunes the 72h log, consolidates memories, applies half-life decay, and runs L5 pattern clustering. Runs on cron. Zero token cost.


How it works

cortex-ai stores memories in a local "palace" — a ChromaDB vector store plus a SQLite knowledge graph. Memories are organized into wings (top-level topics) and rooms (aspects within a topic), then auto-classified by content. Search is semantic, not keyword: ask the meaning of a thing and get matches even if the words don't line up.

The architecture is designed around how the human brain actually organizes memory — separate systems for identity, episodic recall, semantic knowledge, and procedural learning. You can read each layer independently, or combine them via the unified search interface.


Quickstart

# Install
pip install cortex-recall

# One-time setup (creates ~/.cortex/ palace)
cortex init

# Mine an existing project directory into memories
cortex mine /path/to/project

# Search semantically
cortex search "how did we handle authentication?"

# See palace status
cortex status

MCP server (for Claude Code, etc.)

cortex-ai ships an MCP (Model Context Protocol) server so AI agents can query the palace as a tool:

# Register with Claude Code
claude mcp add cortex -s user -- python -m cortex.mcp_server

Available tools:

  • cortex_search — semantic search across all memories
  • cortex_status — palace overview
  • cortex_list_wings — top-level topics
  • cortex_list_rooms — aspects within a wing
  • cortex_get_taxonomy — full wing → room tree
  • cortex_check_duplicate — avoid filing the same memory twice
  • cortex_add — file a new memory
  • cortex_kg_add — add a fact to the knowledge graph
  • cortex_kg_query — query relationships
  • cortex_stm_log — log an event to the 72h short-term memory
  • cortex_stm_fetch — fetch and filter the 72h event log
  • cortex_dream_run — run full nightly maintenance sweep
  • cortex_dream_consolidate — deduplicate and compact palace memories
  • cortex_dream_decay — apply half-life decay to memories
  • cortex_dream_patterns — L5 pattern detection and promotion

Tech stack

  • Python 3.9+
  • ChromaDB — vector embeddings, semantic search, local-first
  • SQLite — knowledge graph with temporal triples
  • sentence-transformers — all-MiniLM-L6-v2 (runs on CPU, ~80MB model)
  • No external APIs — everything runs on your machine

What's new in v0.6.1 — Completed VectorBackend write API + thread-safe memory backends

v0.6.1 closes gaps for external adapter authors.

  • VectorBackend.add(), delete(), upsert() -- the write API is now part of the ABC, so custom vector adapters (DynamoDB+OpenSearch, Postgres+pgvector) can implement the full storage contract
  • Thread-safe Memory*Backend -- all memory backends use threading.Lock, safe for concurrent Lambda warm-container invocations
  • Logged plugin discovery -- broken entry-point plugins log a warning to stderr instead of silently being ignored
  • Zero breaking changes -- all v0.6.0 and v0.5.0 code works identically

What's new in v0.6.0 — Pluggable Backends (Lambda-ready)

v0.6.0 cuts a storage abstraction layer so cortex-recall works on serverless runtimes like AWS Lambda, not just local machines.

Three new interfaces (STMBackend, VectorBackend, KVBackend) with built-in filesystem and in-memory implementations. External packages can register custom backends (DynamoDB, Postgres, etc.) via Python entry_points or direct call.

# Works on Lambda -- no filesystem, no ChromaDB cold-start
from cortex.stm import STM
from cortex.backends.memory import MemorySTMBackend

stm = STM(backend=MemorySTMBackend())
stm.log({"epoch": 1234567890, "project": "my-lambda", "query_head": "hi"})

# Dream nightly maintenance with memory backends
from cortex.dream import Dream
from cortex.backends.memory import MemoryVectorBackend, MemorySTMBackend, MemoryKVBackend

dream = Dream(
    vector_backend=MemoryVectorBackend(),
    stm_backend=MemorySTMBackend(),
    kv_backend=MemoryKVBackend(),
)
result = dream.run()

Zero breaking changes -- all v0.5.0 code works identically. See docs/DEPLOYMENT.md for full guide.


License & attribution

MIT License. See LICENSE and NOTICE.

cortex-ai is a fork of MemPalace by milla-jovovich. The MemPalace engine — ChromaDB-backed search, knowledge graph, palace structure, miner system — is the foundation. cortex-ai adds the four-layer cognitive architecture, MCP server interface, hooks integration, and onboarding flow on top.


Status

cortex-ai v0.6.1 is in beta. Issues welcome at https://github.com/jdomian/cortex-ai/issues.

Metadata

Release files for cortex-recall 0.6.1

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

Source distribution (sdist)

Source distribution for cortex-recall 0.6.1
File Size Uploaded
cortex_recall-0.6.1.tar.gz 130.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cortex-recall 0.6.1
File Interpreter ABI Platform
cortex_recall-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 275.0 kB

Release files / cortex_recall-0.6.1.tar.gz

Download URL cortex_recall-0.6.1.tar.gz
Size 130.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0abca50ab5d6494c0ace1b67206770fca88089879167c058fc58bb8a23643918
BLAKE2b-256 checksum
How to use checksums
3e90affcd1004fda2fac12eafb69faf8b0c3e5bf5660cfeab6f661af6f6874e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / cortex_recall-0.6.1-py3-none-any.whl

Download URL cortex_recall-0.6.1-py3-none-any.whl
Size 144.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
adbd6f09898413da33984482ba7b1fc7ca21e19713afdb07eadbbd23fe800c3f
BLAKE2b-256 checksum
How to use checksums
372c821e6d13a7c265f75f2d2a2bc30c3a30a0e2d18ea422053953be06f394ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

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