🧠 开放大脑
具有MCP接口的个人语义记忆系统。存储、搜索和分析对你来说重要的一切。
](https://github.com/benclawbot/open-brain/stargazers) ](https://hub.docker.com/r/benclawbot/open-brain) 
什么是开放大脑?
开放的大脑是 个人知识管理系统 它就像你的第二个大脑。它
- 📥 摄入 来自任何地方的数据(电报、WhatsApp、克劳德代码、Gmail、文件)
- 🧠 嵌入 语义上的一切(OpenRouter、OpenAI、Ollama或任何自定义API)
- 🔍 搜索 立即使用向量相似度
- 📊 分析 趋势、集群和联系
- 🔔 通报 你的重要变化
- 🌐 供应 通过MCP、REST API、CLI或仪表板
把它想象成 黑曜石与ChatGPT内存相遇 --但可以从任何工具访问。
______________________________________________________________________
✨ 特性
核心
- 语义搜索 --通过意义而不仅仅是关键字来寻找记忆
- 自动标记 --自动主题和实体提取
- 实体识别 --提取人物、地点、组织、日期
- 趋势分析 --查看哪些主题正在出现或正在减少
集成
- MCP服务器 --从Claude、Codex或任何MCP客户处使用
- REST API --任何应用程序的HTTP访问
- 命令行界面 --用于快速操作的命令行界面
- 源连接器 --从Telegram、WhatsApp、Gmail、Claude Code导入
用户界面
- 流线型仪表板 --可视化记忆、统计数据和趋势
- 周报 --自动降价报告
______________________________________________________________________
🚀 快速开始
先决条件
- 码头工人 +Docker编写
- 至少2GB RAM
- (可选)用于嵌入的OpenRouter API密钥
1.克隆和配置
git clone https://github.com/benclawbot/open-brain.git
cd open-brain
# Copy environment file
cp .env.example .env2.设置环境变量
编辑 .env:
# Database
DB_PASSWORD=your_secure_password
# Embeddings (OpenRouter = FREE)
OPENROUTER_API_KEY=your_openrouter_key
# Optional: Telegram notifications
TELEGRAM_BOT_TOKEN=
TELEGRAM_CHAT_ID=没有API密钥? OpenRouter有一个免费层。只需在以下网址注册 openrouter.ai.
3.开始一切
docker compose up -d4.访问服务
| 服务 | URL | 描述 |
|---|---|---|
| 仪表盘 | http://localhost:8501 | 流线型UI |
| MCP服务器 | http://localhost:8080 | MCP协议 |
| REST API | http://localhost:8000 | HTTP API |
| API文件 | http://localhost:8000/docs | Swagger文档 |
______________________________________________________________________
🔧 配置
中的所有设置 config/settings.yaml:
database:
host: postgres
port: 5432
name: openbrain
user: postgres
password: ${DB_PASSWORD}
embedder:
# Providers: openrouter, openai, ollama, custom
provider: openrouter
model: text-embedding-3-small
dimensions: 768
mcp:
host: 0.0.0.0
port: 8080
api:
host: 0.0.0.0
port: 8000
dashboard:
port: 8501嵌入器提供商
| 提供者 | 环境变量 | 注释 |
|---|---|---|
| 开放路由 (默认) | OPENROUTER_API_KEY | 免费套餐可用 |
| OpenAI | OPENAI_API_KEY | 已付 |
| 奥拉马 | OLLAMA_BASE_URL | 本地,免费 |
| 自定义 | CUSTOM_API_URL + CUSTOM_API_KEY | 任何兼容OpenAI的 |
______________________________________________________________________
📡 用法
命令行界面
# Install
pip install -e .
# Search memories
openbrain search "what did I learn about AI"
# Store a memory
openbrain store "Meeting with Oliver about trading bot" --source telegram --tags ai,trading
# Show stats
openbrain stats
# Generate weekly report
openbrain report
# Start API server
openbrain serveMCP工具
将任何MCP客户端连接到 http://localhost:8080:
# Example: Using memory_search
{
"name": "memory_search",
"arguments": {
"query": "trading strategies",
"limit": 5,
"sources": ["telegram", "claude"]
}
}REST API
# Search
curl -X POST http://localhost:8000/memories/search \
-H "Content-Type: application/json" \
-d '{"query": "AI agents", "limit": 5}'
# Store
curl -X POST http://localhost:8000/memories \
-H "Content-Type: application/json" \
-d '{"content": "New idea", "source": "manual"}'
# Stats
curl http://localhost:8000/stats______________________________________________________________________
🏗 建筑
┌─────────────────────────────────────────────────────────────┐
│ Clients │
│ Claude Code | Codex | OpenClaw | Custom Apps | CLI │
└─────────────────────────┬───────────────────────────────────┘
│ MCP / HTTP / CLI
▼
┌─────────────────────────────────────────────────────────────┐
│ Open Brain │
│ ┌─────────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ MCP API │ │ REST API │ │ CLI Tools │ │
│ └─────────────┘ └──────────────┘ └──────────────────┘ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Application Layer │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │Extractors│ │ Tagger │ │Analytics │ │ Notifier │ │ │
│ │ │ (Entities│ │ (Auto-tag│ │ (Trends) │ │(Telegram)│ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Embedder (Multi-Provider) │ │
│ │ OpenRouter | OpenAI | Ollama | Custom │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────┐
│ PostgreSQL + pgvector │
│ memory table with vector embeddings, GIN indexes │
│ for tags/entities, IVFFlat for similarity search │
└─────────────────────────────────────────────────────────────┘组件
| 组件 | 技术 | 目的 |
|---|---|---|
| 数据库 | PostgreSQL+pgvector | 存储+向量搜索 |
| MCP服务器 | FastMCP | AI代理工具界面 |
| REST API | FastAPI | HTTP访问 |
| CLI | 单击 | 终端命令 |
| 仪表板 | 流媒体 | 可视化用户界面 |
| 嵌入器 | 请求 | 多提供者嵌入 |
| 提取器 | NLTK/spaCy | 实体提取 |
______________________________________________________________________
📁 项目结构
open-brain/
├── config/
│ └── settings.yaml # Configuration
├── src/
│ ├── main.py # MCP server entry
│ ├── db/ # Database layer
│ │ ├── schema.sql
│ │ ├── connection.py
│ │ └── queries.py
│ ├── embedder/ # Multi-provider embeddings
│ ├── extractors/ # NER + tagging
│ ├── analytics/ # Trends + reports
│ ├── connectors/ # Source importers
│ ├── cli/ # CLI commands
│ ├── api/ # REST API
│ ├── notifications/ # Telegram + email
│ └── ingestion/ # Bulk import
├── ui/
│ └── dashboard.py # Streamlit dashboard
├── scripts/
│ ├── setup_db.py # Database setup
│ ├── backup.sh # Automated backups
│ └── healthcheck.sh # Health monitoring
├── tests/
│ └── test_core.py
├── docker-compose.yml # Full stack
├── Dockerfile # App container
├── pyproject.toml # CLI package
├── requirements.txt # Python deps
└── README.md______________________________________________________________________
🔌 源连接器
电报
from src.connectors.telegram import TelegramImporter
importer = TelegramImporter(
export_file="telegram_export.json"
)
importer.import_all(db_conn)from src.connectors.whatsapp import WhatsAppImporter
importer = WhatsAppImporter(
export_file="whatsapp_chat.txt"
)
importer.import_all(db_conn)克劳德代码
from src.connectors.claude_code import ClaudeCodeImporter
importer = ClaudeCodeImporter(
sessions_path="~/.claude/sessions"
)
importer.import_all(db_conn)Gmail
from src.connectors.gmail import GmailImporter
importer = GmailImporter(
takeout_path="./mail"
)
importer.import_all(db_conn)______________________________________________________________________
📊 分析
趋势检测
自动检测:
- 新兴话题 --标签比基线增加>50%
- 拒绝话题 --标签下降>30%
- 新实体 --首次出现的人/地点
- 共现 --一起出现的主题
周报
每周日通过cron生成:
# Weekly Memory Report
### Activity
- New memories: 47
- By source: telegram: 23, claude: 15, manual: 9
### What's Hot
- ai: +200% (15 mentions)
- trading: +50% (8 mentions)
### Insights
- You're researching AI agents heavily this week
- Oliver appeared 5 times — significant collaboration______________________________________________________________________
🔔 通知
电报警报
- 新兴趋势
- 周报
- 内存统计摘要
电子邮件
- 每日摘要
- 周报
- 异常警报
______________________________________________________________________
🐳 Docker服务
| 服务 | 映像 | 端口 |
|---|---|---|
| postgres | pgvector/pgvector:0.5.1 | 5432 |
| api | benclawbot/开放式大脑 | 8000 |
| 仪表板 | benclawbot/开放式大脑 | 8501 |
| mcp | benclawbot/开放大脑 | 8080 |
______________________________________________________________________
🤖 手机安装(ARM)
在转换为Linux的旧Android手机上运行:
# Use ARM-compatible images
docker-compose -f docker-compose.arm.yml up -d
# Or build locally on phone
docker build --platform=linux/arm64 .资源:约500MB RAM,约1GB存储空间
______________________________________________________________________
🧪 测试
# Run tests
pytest tests/
# Test MCP connection
python -c "from src.main import mcp; print(mcp)"______________________________________________________________________
📝 许可证
麻省理工学院许可证——随心所欲。
______________________________________________________________________
🙏 致谢
______________________________________________________________________
