Cortex
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Cortexsearch my learnings about TypeScript"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Cortex π§
Local-first AI memory layer with hybrid retrieval and brain-inspired namespaces. No API keys needed.
Give your AI agent persistent memory that runs entirely on your machine. Cortex combines vector similarity, full-text search, recency, and importance scoring into a single embedded database β no cloud services, no API keys, no monthly bills.
v0.4.0: L0/L1/L2 tiered context loading, hierarchical namespace subtrees, auto-session extraction (cortex extract).
v0.3.0: Namespaced collections (brain regions), memory decay, consolidation, audit & health commands.
Quick Start (2 minutes)
# Install globally
npm install -g cortex-memory
# Save memories to brain regions
cortex save "I prefer TypeScript over JavaScript" --namespace learnings
cortex save "Ran 5k in 24:30" --namespace health
cortex save "Sarah prefers async communication" --namespace people
# Search within a namespace
cortex search "programming languages" --namespace learnings
# Search everything
cortex search "programming languages"
# Ingest a folder of notes
cortex ingest ~/notes --recursive --namespace daily
# Check brain health
cortex health
cortex statusThat's it. Memories are stored locally at ~/.cortex/lance_db/.
Related MCP server: M3 Memory
Why Cortex?
Feature | Cortex | Plain vector DB | Cloud memory APIs |
100% local | β | β | β |
Hybrid retrieval (vector + BM25 + recency + importance) | β | β | Sometimes |
Zero config | β | β | β |
MCP server built-in | β | β | Sometimes |
No API keys | β | β | β |
Free forever | β | β | β |
Install
npm install -g cortex-memoryRequires Node.js 18+. First run downloads the embedding model (~30MB) automatically.
Tiered Context Loading (L0/L1/L2)
Every memory is automatically indexed at three depth levels β no LLM needed:
Level | Size | Content | Flag |
L0 | ~100 tokens | First sentence + key terms (abstract) |
|
L1 | ~500 tokens | First paragraph + structure |
|
L2 | Full | Original content |
|
# Default: L0 abstracts β fastest, saves tokens
cortex search "vector search"
# L1 overviews β good balance
cortex search "vector search" --depth 1
# L2 full β when you need every detail
cortex search "vector search" --depth 2This is huge for agents: retrieve 10 L0 abstracts to scan what's relevant, then fetch full content only for the 1-2 memories you actually need.
Namespaces (Brain Regions)
Organize memories into hierarchical namespaces β like a filesystem for knowledge:
Namespace | Purpose |
| Food, workouts, sleep, body metrics |
| App-specific memories |
| Trading-specific memories |
| Personal settings and preferences |
| Info about specific people |
| Relationships, reflections, plans |
| Raw daily logs |
| Mistakes, corrections, patterns |
| Default / uncategorized (backward compatible) |
cortex save "Ran 5k in 24:30" --namespace health
cortex save "MyApp uses React" --namespace projects/myapp
# Exact namespace match
cortex search "running times" --namespace health
# Subtree search β matches all projects/* namespaces
cortex search "project decisions" --namespace projects/ --namespace-prefixMemory Maintenance
Decay
Memories that haven't been accessed lose importance over time (configurable half-life):
cortex decay --dry-run # Preview what would decay
cortex decay --apply --half-life 30 # Apply with 30-day half-lifeConsolidation
Merge similar memories into summaries (like sleep consolidating episodic β semantic memory):
cortex consolidate --dry-run # Find clusters
cortex consolidate --apply # Merge and summarizeAudit & Health
cortex audit # Find duplicates (cosine sim > 0.95), stale memories, namespace distribution
cortex health # Overall brain health: namespace balance, avg importance, stalenessCLI Reference
Save Memories
cortex save "I prefer TypeScript over JavaScript" --namespace learnings
cortex save "Deploy with Vercel" --type procedural --tags "deploy,vercel"
cortex save "Had a great meeting with the team" --type episodic -i 0.8
cortex save "Use pnpm for monorepos" --project myapp --namespace projects/myappSearch (Hybrid Retrieval)
cortex search "what programming languages"
cortex search "deployment" --type procedural --limit 3
cortex search "meeting notes" --min-importance 0.7
cortex search "database setup" --project myapp --namespace projects/myapp
# Tiered depth (token-efficient retrieval)
cortex search "decisions" --depth 0 # L0 abstracts (default)
cortex search "decisions" --depth 1 # L1 overviews
cortex search "decisions" --depth 2 # L2 full content
# Hierarchical namespace prefix (subtree search)
cortex search "deployment" --namespace projects/ --namespace-prefix
cortex search "who is" --namespace user/ --namespace-prefixExtract Memories from a Transcript
# Dry run β preview what would be extracted
cortex extract transcript.md --dry-run
# Save to a specific namespace
cortex extract meeting-notes.txt --namespace projects/myapp
# Save to general (default)
cortex extract conversation.mdcortex extract reads a conversation transcript (plain text or markdown) and automatically saves key facts, decisions, lessons, and person mentions as separate typed memories. Zero LLM calls β pure regex/heuristic extraction.
Ingest Files & Folders
# Ingest a single markdown file
cortex import MEMORY.md
# Ingest an entire folder of notes
cortex ingest ~/notes
cortex ingest ~/notes --recursive # include subdirectories
cortex ingest ~/notes --smart # extract high-signal lines (Decision:, Lesson:, etc.)
cortex ingest ~/docs --ext .md,.txt,.org # custom file extensions
# Smart mode recognizes prefixed lines:
# Decision: Use PostgreSQL for the main database β type: decision, importance: 0.9
# Lesson: Always test with real data β type: lesson, importance: 0.85
# Bug: Race condition in the queue worker β type: lesson, importance: 0.75Manage & Curate
cortex status # Database overview
cortex curate # Find low-value memories to clean up
cortex curate --auto # Auto-delete low-value entries
cortex export --type semantic # Export as markdown
cortex delete <memory-id> # Delete by IDMCP Server (Claude Desktop / Cursor / OpenClaw)
Cortex ships with a built-in Model Context Protocol server, so AI agents can save and search memories directly.
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"cortex": {
"command": "npx",
"args": ["cortex-memory", "mcp"]
}
}
}Cursor
Add to .cursor/mcp.json:
{
"mcpServers": {
"cortex": {
"command": "npx",
"args": ["cortex-memory", "mcp"]
}
}
}OpenClaw
Add to your OpenClaw MCP config:
{
"cortex": {
"command": "npx",
"args": ["cortex-memory", "mcp"]
}
}MCP Tools Available
Tool | Description |
| Save a new memory with type, importance, and tags |
| Hybrid search across all memories |
| Get memory stats and overview |
| Delete a memory by ID |
| Get AI-powered reflection on stored memories |
Architecture
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β CLI/MCP ββββββΆβ Memory Engine ββββββΆβ LanceDB β
β Client βββββββ (scoring) βββββββ (embedded) β
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β
ββββββββ΄βββββββ
β Embeddings β
β (MiniLM-L6) β
βββββββββββββββStorage: LanceDB embedded vector database at ~/.cortex/lance_db/
Embeddings: Xenova/all-MiniLM-L6-v2 β 384-dimensional vectors, runs locally via ONNX Runtime. No API keys.
Full-text search: Tantivy-powered BM25 scoring, automatically indexed.
Hybrid scoring formula:
score = 0.35Γvector + 0.30Γbm25 + 0.15Γrecency + 0.10Γimportance + 0.05Γaccess_frequency + 0.05Γtype_boostThis means Cortex doesn't just find semantically similar results β it factors in how recently something was accessed, how important it is, and whether it matches exact keywords.
Memory Types
Type | Use Case | Example |
| Facts, preferences, knowledge | "I prefer dark mode" |
| Events, experiences | "Met with client on Tuesday" |
| How-to, processes | "To deploy: run npm build then vercel" |
| Choices made and why | "Chose PostgreSQL over MySQL for JSONB support" |
| Things learned the hard way | "Always test with real data, not mocks" |
| Verified information | "The API rate limit is 100 req/min" |
| Personal preferences | "Prefers tabs over spaces" |
| Current state of a project | "v2 API is in beta, launching next week" |
| Info about people | "Sarah is the frontend lead, prefers React" |
Programmatic Usage
import { MemoryEngine } from 'cortex-memory';
const engine = new MemoryEngine();
// Save
await engine.save({
content: "Always validate user input server-side",
type: "lesson",
importance: 0.9,
tags: ["security", "validation"],
});
// Search
const results = await engine.search({
query: "input validation",
limit: 5,
});
for (const r of results) {
console.log(`[${r.score.toFixed(3)}] ${r.memory.content}`);
}
// Stats
const stats = await engine.stats();
console.log(`Total memories: ${stats.totalMemories}`);Agent Integration
Cortex is designed to be the memory backbone for AI agents. See the docs for full integration guides:
Agent Integration Guide β How any AI agent should use Cortex: search, save, ingest, curate, and best practices
OpenClaw Integration Guide β Specific setup for OpenClaw agents: AGENTS.md config, session ingestion, heartbeat maintenance
Quick Start for Agents
# Search before answering (mandatory dual-search with memory_search)
npx cortex search "deployment steps" --limit 5
# Save lessons immediately when recognized
npx cortex save --type belief --tags "calibration" "Always verify sub-agent output independently"
# Ingest sessions after significant work days
npx cortex ingest-sessions
# Weekly maintenance
npx cortex curate
npx cortex healthDevelopment
git clone https://github.com/ryanfrigo/cortex.git
cd cortex
npm install
npm run build
node bin/cortex.js statusTesting
npm test # Run unit tests (vitest)
npm run bench # Run recall benchmarks against real DB
npm run bench:regression # Compare with previous benchmark runUnit tests (
tests/): engine, scoring, decay, consolidation β uses temp DBBenchmarks (
bench/): 22 ground-truth queries across health, projects, personal, learnings, factual, and semantic categoriesRegression guard: flags if recall drops >5% between runs
Contributing
See CONTRIBUTING.md for guidelines.
License
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Persistent personal memory for AI assistants β save, search, and recall across every MCP client.
- memnodeOAuthdev.memnode
Persistent, inspectable memory for AI agents with lineage, correction, and a hosted MCP endpoint.
shared AI-context layer for teams β persistent memory your agents search and update over MCP
Persistent memory for AI agents across Claude, ChatGPT and any MCP client.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides persistent, local-first AI memory across sessions via MCP tools for storing, searching, and retrieving context from past interactions.1MIT
- AlicenseBqualityBmaintenanceLocal-first persistent memory layer for MCP agents with hybrid search, file ingestion, and GDPR compliance.201,662 PyPI25Apache 2.0
- AlicenseNot gradedqualityCmaintenanceLocal-first memory engine that synthesizes entity profiles at ingestion. Enables persistent, reasoning memory for AI agents via MCP tools like add, search, and profile.MIT
- AlicenseAqualityAmaintenanceEmbedded memory and retrieval engine for AI agents, providing local-first memory with MCP support for multi-agent access control.32MIT