第二大脑
基于Rust构建的个人知识操作系统。它将你的普通markdown笔记索引到一个可搜索的、语义连接的知识库中——由PostgreSQL+pgvector支持,并通过以下方式公开 主控程序 因此,任何人工智能助手都可以阅读、搜索和写你的笔记。
为什么
你已经记笔记了。它们存在于分散的目录中,跨项目,处于不同的完整性阶段。问题不在于写作,而在于 *发现* 你六个月前写的东西,看到了跨领域想法之间的联系,并为你的人工智能工具提供了实际帮助所需的背景。
Second Brain通过将您的markdown文件视为真实来源并构建一个支持全文搜索、语义(向量)搜索、链接图遍历和可组合AI工作流的派生索引来解决这个问题——所有这些都可以从Claude Code、Claude Desktop、Neovim或任何兼容MCP的客户端访问。
您的文件保留在磁盘上,无论您使用何种结构。无需锁定,无需特殊语法,无需迁移。
运作原理
You write markdown --> Watcher detects change --> Parser extracts structure
|
You ask a question //working` (例如。, `alice/2026-03-18/working`)
自定义:通过a `branch` 参数到 `session_init` (例如。, `alice/2026-03-18/notes_on_bees`)
### 运作原理
1. **`session_init`** 在带有日期戳的分支上创建git工作树
1. **`note_create`/`note_update`** 使用AI作者身份写入工作树并自动提交
1. 注释可以在数据库中立即搜索(写入时摄入)
1. 会话结束后,工作台会被清理干净,但 **分支持续存在**
1. 合并到 `main` 是一个深思熟虑的步骤(PR或手动合并)
受保护的分支(`main`, `master`, `staging`, `dev`)从不直接写信给。AI承诺使用 `--author` 所以它们与人类的行为不同 `git log`.
只读工具(搜索、列表、阅读)不需要会话。
## 建筑
second-brain (Cargo workspace) | |-- sb-core Shared foundation: models, DB queries, markdown parser, | ingestion pipeline, file search. Everything depends on this. | |-- sb-embed Embedding pipeline: pluggable providers, markdown chunker, | batch processor. | |-- sb-sync File watcher (notify v7) + sync processor. Detects file | changes, ingests, embeds. Runs as a background tokio task. | |-- sb-skills Skill engine: composable workflows for summarize, reflect, | continue-work, connect-ideas, contextualize. | |-- sb-server MCP server binary. 17 tools via rmcp. Supports stdio | (local) and HTTP (network) transports. | |-- sb-cli CLI for manual ingestion, search, embedding, and skills.
有关更深入的架构细节(数据流、嵌入策略、链接解析、数据库模式),请参阅 [docs/architecture.md](docs/architecture.md).
## 发展
对于没有Docker的本地开发(从源代码构建):
Start just the database
docker compose up -d db
Start Ollama on the host (or use docker compose up -d ollama from the dev compose)
ollama serve & ollama pull nomic-embed-text
Build
cargo build --release
Run the MCP server (stdio mode for Claude Code)
./target/release/second-brain
Or HTTP mode
./target/release/second-brain --transport http --port 8080
通过justfile执行开发命令:
just db-up # start postgres just db-down # stop services just db-reset # wipe and recreate the database just test # run all tests just ci # fmt + clippy + test just server # run MCP server in dev mode
互动 `setup.sh` 脚本也可以遍历本地设置,但Docker部署通过 `deploy.sh` 是主要支持的路径。
## 命令行界面
这 `sb` CLI可通过以下方式在容器内使用 `./deploy.sh cli`,或在当地建造 `cargo build --release -p sb-cli`:
Via deploy.sh (runs inside container)
./deploy.sh cli search "signal processing" ./deploy.sh cli semantic "radio frequency" ./deploy.sh cli skill summarize --period this-week
Or locally
sb search "signal processing" sb semantic "radio frequency interference" sb ingest ~/notes sb embed sb skill summarize --period this-week sb projects sb classify ~/notes/TODO.md volatile
## 测试
cargo test --workspace # 95 unit + integration tests cargo clippy --workspace # lint checks python3 test-mcp-http.py # 51 HTTP integration tests (requires running server)
### 板条箱测试覆盖率
|板条箱|测试|覆盖范围|
|-------|-------|----------|
|sb core | 62 |配置、摄取、生命周期、标记、路径映射、项目检测、项目同步、工作树|
|sb embed|10|分块器,TEI提供商|
|sb技能|16|git_ops(分支验证、提交、快照)、时间周期|
|sb sync|2|监视器(文件更改检测)|
|sb core(集成)|5|DB连接、CRUD、全文搜索、pgvector|
集成测试套件涵盖了依赖数据库的模块(DB/\*)(`test-mcp-http.py`)以及 `tests/db_integration.rs` 测验。
## 延伸阅读
- **[docs/architecture.md](docs/architecture.md)** --数据库模式、数据流、嵌入策略、链接解析
- **[ROADMAP.md](ROADMAP.md)** --未来计划和参考项目
## 许可证
麻省理工学院