OpenClaw应该内置的记忆层。
Cortex 是一个面向AI智能体的开源、导入优先记忆系统。单Go二进制文件,SQLite存储,零云依赖。它解决了OpenClaw的头号抱怨:智能体在压缩后忘记一切。
GitHub: https://github.com/hurttlocker/cortex
安装: brew install hurttlocker/cortex/cortex 或从 Releases 下载
为什么选择 Cortex?
OpenClaw的默认记忆是Markdown文件。当上下文填满时,压缩会总结并销毁细节。Cortex 解决了这个问题:
| 问题 | Cortex 解决方案 |
|---|
| 压缩丢失细节 | 持久化SQLite DB在任何会话中存活 |
| 无搜索 — 只是把文件倒入上下文 | 混合BM25 + 语义搜索(~16ms关键词,~52ms语义) |
| 一切权重相等 | 艾宾浩斯遗忘曲线 — 重要事实保留,噪音自然消退 |
| 无法导入现有文件 | 导入优先:Markdown、文本、任何文件。8个连接器(GitHub、Gmail、日历、Drive、Slack、Notion、Discord、Telegram) |
| 多智能体记忆泄漏 | 内置按智能体作用域隔离 |
| 昂贵的云记忆服务 | $0/月。永久。本地SQLite。 |
快速开始
1. 安装 Cortex
# macOS/Linux (Homebrew)
brew install hurttlocker/cortex/cortex# 或直接下载二进制文件
# https://github.com/hurttlocker/cortex/releases/latest
2. 导入您的记忆
# 导入OpenClaw的记忆文件
cortex import ~/clawd/memory/ --extract# 导入特定文件
cortex import ~/clawd/MEMORY.md --extract
cortex import ~/clawd/USER.md --extract
3. 搜索
# 快速关键词搜索
cortex search "wedding venue" --limit 5# 语义搜索(需要ollama和nomic-embed-text)
cortex search "what decisions did I make about the project" --mode semantic
# 混合搜索(推荐)
cortex search "trading strategy" --mode hybrid
4. 作为MCP服务器使用(推荐用于OpenClaw)
# 添加到您的MCP配置 — Cortex暴露17个工具 + 4个资源
cortex mcp # stdio模式
cortex mcp --port 8080 # HTTP+SSE模式
关键特性
艾宾浩斯遗忘曲线
事实根据类型以不同速率消退。身份事实(名字、角色)持续约2年。时间事实(事件、日期)在约1周内消退。状态事实(状态、心情)在约2周内消退。这意味着搜索结果自然地优先显示重要的内容——无需手动整理。
混合搜索
- BM25 — 通过SQLite FTS5进行即时关键词匹配(~16ms)
- 语义 — 通过本地嵌入进行基于含义的搜索(~52ms)
- 混合 — 结合两者使用倒数排名融合
事实提取
每个导入的文件都会自动提取事实:
- 基于规则的提取(零成本,即时)
- 可选的LLM增强(Grok、Gemini或任何提供商 — 找出规则遗漏的事实)
- 自动分类为9种类型:身份、关系、偏好、决策、时间、地点、状态、配置、kv
连接器(Beta)
从外部来源拉取记忆:
cortex connect sync --provider github --extract
cortex connect sync --provider gmail --extract
cortex connect sync --all --extract
知识图谱
可视化探索您的记忆:
cortex graph --serve --port 8090
# 在浏览器中打开交互式2D图谱浏览器
自我清理
cortex cleanup --purge-noise # 移除垃圾和重复
cortex stale 30 # 找出30天未访问的事实
cortex conflicts # 检测矛盾
cortex conflicts --resolve llm # 使用LLM自动解决
与 OpenClaw 集成
推荐的搜索链
memory_search → Cortex → QMD → ripgrep → web搜索
使用OpenClaw内置的memory_search处理对话历史,然后使用Cortex进行深度知识检索。
包装器脚本
包含的scripts/cortex.sh提供快捷方式:
scripts/cortex.sh search "query" 5 # 混合搜索
scripts/cortex.sh stats # 记忆健康状况
scripts/cortex.sh stale 30 # 陈旧事实检测
scripts/cortex.sh conflicts # 矛盾检测
scripts/cortex.sh sync # 增量导入
scripts/cortex.sh reimport # 完全擦除+重新导入
scripts/cortex.sh compaction # 压缩前状态简报
自动同步(launchd/systemd)
# 每30分钟自动导入会话 + 同步连接器
cortex connect schedule --every 30m --install
架构
- 语言: Go(62,300+行,1,081个测试)
- 存储: SQLite + FTS5 + WAL模式
- 二进制文件: 19MB,纯Go,零CGO,零运行时依赖
- 平台: macOS(arm64/amd64)、Linux(arm64/amd64)、Windows(amd64)
- MCP: 17个工具 + 4个资源(stdio或HTTP+SSE)
- 嵌入: 本地通过Ollama(nomic-embed-text),或OpenAI/DeepSeek/自定义
- LLM: 通过任何提供商进行可选增强(Grok、Gemini、DeepSeek、OpenRouter)
- 规模: 测试至100K+记忆。按~20-50/天,5+年不会达到上限。
- 许可证: MIT
vs 其他记忆工具
| Cortex | Mem0 | Zep | LangMem |
|---|
| 部署 | 单二进制 | 云或K8s | 云 | Python库 |
| 成本 | $0 | $19-249/月 | $25/月+ | 基础设施成本 |
| 隐私 | 100%本地 | 默认云 | 云 | 取决于 |
| 消退 | 艾宾浩斯(7种速率) | 仅TTL | 时间性 | 无 |
| 导入 | 文件+8连接器 | 聊天提取 | 聊天/文档 | 聊天提取 |
| 搜索 | BM25+语义 | 向量+图 | 时间性KG | JSON文档 |
| MCP | 17个工具原生 | 无 | 无 | 无 |
| 依赖 | 零 | Python+云 | 云+积分 | Python+LangGraph |
需求
- Cortex二进制文件 — 通过Homebrew安装或从GitHub Releases下载
- 可选: 带
nomic-embed-text的Ollama用于语义搜索
- 可选: 用于增强的LLM API密钥(Grok、Gemina等)
- 无Python。无Node。无Docker。无云账户。只有二进制文件。
v1.1/v1.2 集成指南(为OpenClaw智能体接线)
何时使用cortex answer vs cortex search
- answer — "我对X了解多少?" / "Y是谁?" / 综合问题 → 带引用的单一连贯响应
- search — "找到提到X的文件" / 调试 / 探索存在什么 → 排名结果列表
源提升(config.yaml)
添加到~/.cortex/config.yaml:
search:
source_boost:
- prefix: "memory/"
weight: 1.5
- prefix: "file:MEMORY"
weight: 1.6
- prefix: "github"
weight: 1.3
- prefix: "session:"
weight: 0.9
权重越高 = 越可信。每日笔记和核心文件排名高于自动导入的会话。
搜索意图
当您知道答案在哪里时使用--intent:
--intent memory — 个人决策、偏好、人
--intent connector — 代码、PRs、邮件、外部数据
--intent import — 导入的文件和文档
- 无标志 = 搜索一切(默认,适合发现)
生命周期运行器计划
# 夜间试运行 + 应用(launchd或cron)
cortex lifecycle run --dry-run > /tmp/lifecycle-plan.log 2>&1# 如果发现任何内容,应用:
cortex lifecycle run
推荐:每天凌晨3:30。第一周:仅试运行,查看日志。
策略预设
新智能体(< 500个事实):
policies:
reinforce_promote:
min_reinforcements: 3
min_sources: 2
decay_retire:
inactive_days: 90
confidence_below: 0.25
conflict_supersede:
min_confidence_delta: 0.20
成熟智能体(2000+事实):
policies:
reinforce_promote:
min_reinforcements: 5
min_sources: 3
decay_retire:
inactive_days: 45
confidence_below: 0.35
conflict_supersede:
min_confidence_delta: 0.10
导入后清理
任何批量导入后,运行:
cortex cleanup --dedup-facts # 移除近似重复
cortex conflicts --auto-resolve # 解决矛盾
推荐的OpenClaw搜索链(更新版)
memory_search → cortex answer(综合)→ cortex search(指针)→ QMD → ripgrep → web
The memory layer OpenClaw should have built in.
Cortex is an open-source, import-first memory system for AI agents. Single Go binary, SQLite storage, zero cloud dependencies. It solves the #1 complaint about OpenClaw: agents forget everything after compaction.
GitHub: https://github.com/hurttlocker/cortex
Install: brew install hurttlocker/cortex/cortex or download from Releases
Why Cortex?
OpenClaw's default memory is Markdown files. When context fills up, compaction summarizes and destroys specifics. Cortex fixes this:
| Problem | Cortex Solution |
|---|
| Compaction loses details | Persistent SQLite DB survives any session |
| No search — just dump files into context | Hybrid BM25 + semantic search (~16ms keyword, ~52ms semantic) |
| Everything has equal weight | Ebbinghaus decay — important facts stay, noise fades naturally |
| Can't import existing files | Import-first: Markdown, text, any file. 8 connectors (GitHub, Gmail, Calendar, Drive, Slack, Notion, Discord, Telegram) |
| Multi-agent memory leaks | Per-agent scoping built in |
| Expensive cloud memory services | $0/month. Forever. Local SQLite. |
Quick Start
1. Install Cortex
# macOS/Linux (Homebrew)
brew install hurttlocker/cortex/cortex# Or download binary directly
# https://github.com/hurttlocker/cortex/releases/latest
2. Import Your Memory
# Import OpenClaw's memory files
cortex import ~/clawd/memory/ --extract# Import specific files
cortex import ~/clawd/MEMORY.md --extract
cortex import ~/clawd/USER.md --extract
3. Search
# Fast keyword search
cortex search "wedding venue" --limit 5# Semantic search (requires ollama with nomic-embed-text)
cortex search "what decisions did I make about the project" --mode semantic
# Hybrid (recommended)
cortex search "trading strategy" --mode hybrid
4. Use as MCP Server (recommended for OpenClaw)
# Add to your MCP config — Cortex exposes 17 tools + 4 resources
cortex mcp # stdio mode
cortex mcp --port 8080 # HTTP+SSE mode
Key Features
Ebbinghaus Forgetting Curve
Facts decay at different rates based on type. Identity facts (names, roles) last ~2 years. Temporal facts (events, dates) fade in ~1 week. State facts (status, mood) fade in ~2 weeks. This means search results naturally prioritize what matters — without manual curation.
Hybrid Search
- BM25 — instant keyword matching via SQLite FTS5 (~16ms)
- Semantic — meaning-based via local embeddings (~52ms)
- Hybrid — combines both with reciprocal rank fusion
Fact Extraction
Every imported file gets facts extracted automatically:
- Rule-based extraction (zero cost, instant)
- Optional LLM enrichment (Grok, Gemini, or any provider — finds facts rules miss)
- Auto-classification into 9 types: identity, relationship, preference, decision, temporal, location, state, config, kv
Connectors (Beta)
Pull memory from external sources:
cortex connect sync --provider github --extract
cortex connect sync --provider gmail --extract
cortex connect sync --all --extract
Knowledge Graph
Explore your memory visually:
cortex graph --serve --port 8090
# Opens interactive 2D graph explorer in browser
Self-Cleaning
cortex cleanup --purge-noise # Remove garbage + duplicates
cortex stale 30 # Find facts not accessed in 30 days
cortex conflicts # Detect contradictions
cortex conflicts --resolve llm # Auto-resolve with LLM
Integration with OpenClaw
Recommended Search Chain
memory_search → Cortex → QMD → ripgrep → web search
Use OpenClaw's built-in memory_search for conversation history, then Cortex for deep knowledge retrieval.
Wrapper Script
The included
scripts/cortex.sh provides shortcuts:
scripts/cortex.sh search "query" 5 # Hybrid search
scripts/cortex.sh stats # Memory health
scripts/cortex.sh stale 30 # Stale fact detection
scripts/cortex.sh conflicts # Contradiction detection
scripts/cortex.sh sync # Incremental import
scripts/cortex.sh reimport # Full wipe + re-import
scripts/cortex.sh compaction # Pre-compaction state brief
Automated Sync (launchd/systemd)
# Auto-import sessions + sync connectors every 30 min
cortex connect schedule --every 30m --install
Architecture
- Language: Go (62,300+ lines, 1,081 tests)
- Storage: SQLite + FTS5 + WAL mode
- Binary: 19MB, pure Go, zero CGO, zero runtime dependencies
- Platforms: macOS (arm64/amd64), Linux (arm64/amd64), Windows (amd64)
- MCP: 17 tools + 4 resources (stdio or HTTP+SSE)
- Embeddings: Local via Ollama (nomic-embed-text), or OpenAI/DeepSeek/custom
- LLM: Optional enrichment via any provider (Grok, Gemini, DeepSeek, OpenRouter)
- Scale: Tested to 100K+ memories. At ~20-50/day, won't hit ceiling for 5+ years.
- License: MIT
vs Other Memory Tools
| Cortex | Mem0 | Zep | LangMem |
|---|
| Deploy | Single binary | Cloud or K8s | Cloud | Python lib |
| Cost | $0 | $19-249/mo | $25/mo+ | Infra costs |
| Privacy | 100% local | Cloud by default | Cloud | Depends |
| Decay | Ebbinghaus (7 rates) | TTL only | Temporal | None |
| Import | Files + 8 connectors | Chat extraction | Chat/docs | Chat extraction |
| Search | BM25 + semantic | Vector + graph | Temporal KG | JSON docs |
| MCP | 17 tools native | No | No | No |
| Dependencies | Zero | Python + cloud | Cloud + credits | Python + LangGraph |
Requirements
- Cortex binary — install via Homebrew or download from GitHub Releases
- Optional: Ollama with
nomic-embed-text for semantic search
- Optional: LLM API key for enrichment (Grok, Gemini, etc.)
- No Python. No Node. No Docker. No cloud account. Just the binary.
v1.1/v1.2 Integration Guide (Wiring for OpenClaw Agents)
When to use cortex answer vs cortex search
- answer — "What do I know about X?" / "Who is Y?" / synthesis questions → single coherent response with citations
- search — "Find the file where X is mentioned" / debugging / exploring what exists → ranked result list
Source Boost (config.yaml)
Add to
~/.cortex/config.yaml:
search:
source_boost:
- prefix: "memory/"
weight: 1.5
- prefix: "file:MEMORY"
weight: 1.6
- prefix: "github"
weight: 1.3
- prefix: "session:"
weight: 0.9
Higher weight = more trusted. Daily notes and core files rank above auto-imported sessions.
Search Intent
Use
--intent when you know where the answer lives:
--intent memory — personal decisions, preferences, people
--intent connector — code, PRs, emails, external data
--intent import — imported files and documents
- No flag = search everything (default, good for discovery)
Lifecycle Runner Schedule
# Nightly dry-run + apply (launchd or cron)
cortex lifecycle run --dry-run > /tmp/lifecycle-plan.log 2>&1
# If anything found, apply:
cortex lifecycle run
Recommended: 3:30 AM daily. First week: dry-run only, review logs.
Policy Presets
Fresh agent (< 500 facts):
policies:
reinforce_promote:
min_reinforcements: 3
min_sources: 2
decay_retire:
inactive_days: 90
confidence_below: 0.25
conflict_supersede:
min_confidence_delta: 0.20
Mature agent (2000+ facts):
policies:
reinforce_promote:
min_reinforcements: 5
min_sources: 3
decay_retire:
inactive_days: 45
confidence_below: 0.35
conflict_supersede:
min_confidence_delta: 0.10
Post-Import Hygiene
After any bulk import, run:
cortex cleanup --dedup-facts # Remove near-duplicates
cortex conflicts --auto-resolve # Resolve contradictions
Recommended OpenClaw Search Chain (Updated)
memory_search → cortex answer (synthesis) → cortex search (pointers) → QMD → ripgrep → web