CORTEX Memory MCP
Persistent semantic memory MCP server for AI agents with hybrid search, LLM scoring, and decay engine, fully local.
README
π§ CORTEX Memory MCP
Persistent semantic memory for AI agents. TypeScript Β· LangGraph.js Β· Qdrant Β· fastembed ONNX Β· Ollama β 100% local, zero mandatory cloud.
What is CORTEX?
CORTEX is a Model Context Protocol (MCP) server that gives AI agents a persistent, semantically searchable long-term memory. Unlike simple key-value stores, CORTEX understands what information is important, how memories relate to each other, and which memories are becoming stale over time.
Built for agents running in CPU-only environments β no GPU required, no cloud dependencies.
Architecture β 3 Memory Layers
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CORTEX v3.2 β
β β
β β WORKING MEMORY temp_memories (Qdrant) β
β ββ quick_observe β instant write, no LLM β
β β
β β‘ SEMANTIC MEMORY cortex_<project> (Qdrant) β
β ββ dense (all-MiniLM-L6-v2) + sparse (SPLADE) β
β ββ scored by qwen3 Β· linked Β· decay-weighted β
β β
β β’ EPISODIC MEMORY cortex_episodes_<project> (Qdrant) β
β ββ sessions with timestamped events, no LLM β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Key Features
| Feature | Details |
|---|---|
| LLM scoring on ingest | qwen3 assigns importance (1-10), type, and tags to every memory |
| Hybrid search | Dense (all-MiniLM-L6-v2) + Sparse (SPLADE_PP_en_v1) via Qdrant RRF fusion |
| Cross-encoder reranking | Single qwen3 call evaluates all (query, candidate) pairs in batch |
| Dual decay engine | Bayesian (DECISION/FACT/ERROR) + FSRS-inspired (PREFERENCE/CONTEXT) |
| Contradiction detection | Auto-marks superseded memories on ingest |
| Episodic sessions | Zero-LLM session tracking with typed events |
| Operator Profile | Persistent coding preferences and work patterns |
| 20 MCP tools | Complete CRUD + search + analytics surface |
| 100% local | fastembed ONNX for embeddings, Ollama for LLM β no API keys needed |
Competitive Landscape (June 2026)
| CORTEX | mem0 | Graphiti | Basic Memory | MCP Official | |
|---|---|---|---|---|---|
| LLM scoring on ingest | β | β | β | β | β |
| Hybrid search (dense+sparse) | β | β οΈ cloud | β | β | β |
| Cross-encoder reranking | β | β οΈ cloud | β | β | β |
| Episodic layer (no LLM) | β | β | β | β | β |
| Dual decay engine | β | β | β bi-temporal | β | β |
| Contradiction detection | β | β | β | β | β |
| TypeScript + LangGraph.js | β | β Python | β Python | β Python | β |
| 100% local | β | β οΈ MCP=cloud | β | β | β |
Prerequisites
# 1. Qdrant (Docker)
docker run -d -p 6333:6333 --name qdrant qdrant/qdrant
# 2. Ollama + models
ollama pull qwen3:8b # scoring, tagging, reranking, consolidation
# optional faster alternative:
# ollama pull qwen3:1.7b # 3-5Γ faster on CPU, slightly lower accuracy
fastembed (embeddings) is bundled as an npm dependency β no separate installation needed. Models download automatically to
.fastembed_cache/on first use (~22 MB dense, ~110 MB sparse).
Installation
git clone git@github.com:alainrc2005/cortex_memory_mcp.git
cd cortex_memory_mcp
npm install
npm run build
Environment Configuration
Create a .env file in the project root:
QDRANT_URL=http://localhost:6333
FASTEMBED_CACHE_DIR=/absolute/path/to/cortex_memory_mcp/.fastembed_cache
# Optional β only needed if Qdrant has auth enabled
# QDRANT_API_KEY=your_key
# Optional β defaults to http://localhost:11434
# OLLAMA_URL=http://localhost:11434
MCP Configuration
Add to your MCP client config (e.g. ~/.gemini/config/mcp_config.json):
{
"mcpServers": {
"langgraph-memory-mcp": {
"command": "/absolute/path/to/cortex_memory_mcp/cortex-mcp.sh"
}
}
}
Tool Reference β 20 Tools
Semantic Memory (17 tools)
| Tool | Description | Trigger |
|---|---|---|
observe |
Store a memory through the full pipeline: score β embed β link β persist | Manual / session close |
recall |
Hybrid BM25+dense search with LLM cross-encoder reranking | On demand |
get_context_for |
RAG-style context injection for a project + message | Auto (cold start) |
consolidate |
Merge duplicate/similar memories using LLM | End of long session |
detect_patterns |
Extract operator behavior patterns, update Operator Profile | Periodic |
get_operator_profile |
Read coding preferences and detected patterns | Auto (cold start) |
cortex_status |
System health: collections, engram counts, pending buffer | Diagnostic |
delete_memory |
Delete a single engram by ID | On demand |
update_memory |
Update engram content, recalculate embedding + score | On demand |
get_all_memories |
List all engrams for a project sorted by decay score | Audit |
delete_all_memories |
β οΈ Irreversible reset of a project (requires confirm: true) |
Explicit only |
batch_observe |
Store up to 20 memories in one call | Bulk import |
export_memories |
Export project as JSON (backup/migration) | On demand |
quick_observe |
Write to working buffer instantly β no LLM, no embedding | Auto (post-turn hook) |
list_pending |
View working buffer contents by project | Diagnostic |
index_temp |
Promote buffer β semantic memory with ONNX embedding + LLM scoring | Auto (next cold start) |
recall_hybrid |
Search both buffer (keyword) and indexed memories (semantic) simultaneously | On demand |
Episodic Memory (3 tools)
| Tool | Description |
|---|---|
start_session |
Open an episodic session for a project. Auto-closes any previous open session. Returns sessionId. |
log_event |
Record a typed event in the active session. Types: DECISION ERROR SOLUTION INSIGHT CONTEXT_CHANGE |
recall_sessions |
Semantic search over past session summaries using fastembed ONNX |
Indexing Pipeline
quick_observe(content)
β
βΌ (instant, no LLM, no embedding)
temp_memories βββββ working buffer (Qdrant, dummy vectors)
β
β index_temp() β called at next session cold start
βΌ
fastembed ONNX
ββ AllMiniLML6V2 β dense vector 384d
ββ SpladePPEnV1 β sparse BM25 vector
β
qwen3 (Ollama)
ββ importance: 1-10
ββ type: DECISION | FACT | ERROR | PATTERN | PREFERENCE | CONTEXT
ββ tags: [keyword, ...]
β
Contradiction detection (qwen3)
ββ marks superseded memories if similarity > 0.88
β
βΌ
Qdrant upsert (dense + sparse vectors)
ββ bidirectional links to related engrams
Decay Engine
CORTEX uses a dual decay model tuned per memory type:
Bayesian (DECISION Β· FACT Β· ERROR Β· PATTERN)
utility = alpha / (alpha + beta)
alpha += importance on access
beta += 1 per day without access
FSRS-inspired (PREFERENCE Β· CONTEXT)
stability = log1p(accessCount) Γ (importance / 5)
retrievability = exp(-daysSinceAccess / stability)
Memories accessed frequently become more stable. Stale, unaccessed memories decay toward zero and eventually become candidates for consolidation.
Project Structure
src/
βββ server.ts # MCP server β 20 tools, ~1500 LOC
βββ bootstrap.ts # Qdrant collection init on startup
βββ graph/
β βββ observe/
β β βββ workflow.ts # LangGraph pipeline: scoreβembedβlinkβpersist
β β βββ state.ts # Graph state types
β β βββ nodes/
β β βββ score.ts # qwen3: importance + type + tags
β β βββ embed.ts # fastembed ONNX: dense + sparse vectors
β β βββ link.ts # Bidirectional links in Qdrant
β β βββ persist.ts # Final upsert
β βββ consolidate/
β βββ nodes.ts # LLM merge of duplicate engrams
βββ services/
β βββ qdrant.ts # Qdrant client, collections, hybrid search
β βββ fastembed.ts # ONNX embeddings: dense (AllMiniLM) + sparse (SPLADE)
β βββ ollama.ts # qwen3: scoring, reranking, contradiction detection
β βββ decay.ts # Dual decay engine: Bayesian + FSRS-inspired
β βββ episode.ts # Episodic session management
βββ types/
βββ engrama.ts # Engram TypeScript types
βββ episode.ts # Episode/event types
Running Tests
npm test
# Covers all 20 tools with valid, invalid, and connectivity test cases
Memory Lifecycle
Session N (active)
Agent detects storable fact
β
quick_observe() β instant, no CPU cost
β
Written to temp_memories
Session N+1 cold start
get_context_for() + get_operator_profile() β parallel
β
Pending in temp_memories? β index_temp()
β
fastembed ONNX + qwen3 scoring applied
β
Promoted to cortex_<project> with full embeddings
β
Available for recall() and get_context_for()
License
MIT Β© 2026 β Built by Zeus with Antigravity
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.