Bear Notes MCP Server with RAG

by ruanodendaal
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Integrates with Bear Notes on macOS, providing semantic search and RAG capabilities for accessing personal notes.

  • Uses Node.js as the runtime environment for the MCP server, required for version 16 or higher.

  • Connects to Bear Notes' SQLite database to access and search notes content for retrieval and context enhancement.

Bear Notes MCP 服务器与 RAG

想要通过 AI 助手提升你的 Bear Notes 体验吗?这款小工具使用语义搜索和 RAG(检索增强生成)技术,将你的个人知识库与 AI 系统连接起来。

我开发这个应用是因为我希望我的AI助手能够真正理解我的笔记内容,而不仅仅是进行简单的文本匹配。我自己都觉得,结果相当不错。

入门

设置很简单:

git clone [your-repo-url] cd bear-mcp-server npm install

使脚本可执行(因为权限很重要):

chmod +x src/bear-mcp-server.js chmod +x src/create-index.js

首先要做的事情:索引你的笔记

在深入研究之前,您需要创建笔记的矢量嵌入:

npm run index

温馨提示:如果你像我一样是个笔记高手,这可能需要几分钟。它会把你所有的笔记转换成数学向量,从而捕捉它们的含义——真是个聪明的主意😉。

配置

更新您的 MCP 配置文件:

{ "mcpServers": { "bear-notes": { "command": "node", "args": [ "/absolute/path/to/bear-mcp-server/src/bear-mcp-server.js" ], "env": { "BEAR_DATABASE_PATH": "/Users/yourusername/Library/Group Containers/9K33E3U3T4.net.shinyfrog.net.bear/Application Data/database.sqlite" } } } }

🚨记得将路径替换为你的实际安装位置。直接使用示例路径恐怕没什么好处。

有何特别之处?

  • 语义搜索:基于语义而非关键词查找笔记。例如,如果您搜索“生产力系统”,即使笔记中不包含这些关键词,它也能找到您关于 GTD 和番茄工作法的笔记。
  • RAG 支持:您的 AI 助手现在可以从您的笔记中提取相关内容,即使您没有明确提及它们。
  • 全部本地处理:一切都在您的计算机上运行。无需任何数据离开您的计算机,无需 API 密钥,无需互联网依赖(初始设置后)。
  • 优雅的回退:如果语义搜索因任何原因不可用,它将悄悄地回退到传统搜索。安全第一。

工作原理

巧妙之处

该服务器使用 Xenova 实现的 transforms.js 和 all-MiniLM-L6-v2 模型:

  • 它创建 384 维向量来捕捉笔记的语义本质
  • 所有处理均在您的机器本地进行
  • 第一次启动时模型加载可能会有点慢,但之后就很快了

流程

  1. 使用转换器模型,您的查询将被转换为向量
  2. 该向量与笔记的预索引向量进行比较
  3. 无论关键字是否完全匹配,都会返回具有相似含义的注释
  4. 人工智能助手使用这些相关注释作为其回复的背景

项目结构

这里没有什么太复杂的:

bear-mcp-server/ ├── package.json ├── readme.md └── src/ ├── bear-mcp-server.js # Main MCP server ├── create-index.js # Script to index notes ├── utils.js # Utility functions ├── lib/ # Additional utilities and diagnostic scripts │ └── explore-database.js # Database exploration and diagnostic tool ├── note_vectors.index # Generated vector index (after indexing) └── note_vectors.json # Note ID mapping (after indexing)

人工智能助手可用的工具

连接到该服务器的AI助手可以使用以下工具:

  1. search_notes :查找符合查询的笔记
    • 参数: query (必需)、 limit (可选,默认值:10)、 semantic (可选,默认值:true)
  2. get_note :通过 ID 获取特定笔记
    • 参数: id (必填)
  3. get_tags :列出 Bear Notes 中使用的所有标签
  4. 检索_for_rag :获取语义上类似于查询的注释,专门为 RAG 格式化
    • 参数: query (必需)、 limit (可选,默认值:5)

要求

  • Node.js 版本 16 或更高版本
  • 熊掌记 macOS 版
  • 兼容MCP的AI助手客户端

限制和注意事项

  • 对 Bear Notes 的只读访问权限(我们不会修改您宝贵的笔记)
  • 仅限 macOS(抱歉,Windows 和 Linux 用户)
  • 如果你添加了大量新笔记,你需要使用npm run index重建索引
  • 首次启动有点像等待水壶烧开,同时嵌入模型加载

故障排除

如果事情变得不对劲:

  1. 仔细检查你的 Bear 数据库路径
  2. 确保已使用npm run index运行索引过程
  3. 检查 Bear Notes 数据库的权限
  4. 验证服务器脚本是否可执行
  5. 在日志中查找错误消息

如有疑问,请尝试将其关闭并重新打开。它的效果比我们愿意承认的要好得多。

执照

MIT(欢迎随意修改、分享和改进)

-
security - not tested
F
license - not found
-
quality - not tested

使用语义搜索和 RAG(检索增强生成)将 Bear Notes 连接到 AI 助手,让 AI 系统通过有意义的搜索而不是仅仅通过关键字匹配来访问和理解您的个人知识库。

  1. Getting Started
    1. First Things First: Index Your Notes
      1. Configuration
        1. What Makes This Special?
          1. How It Works
            1. The Clever Bits
            2. The Flow
          2. Project Structure
            1. Available Tools for AI Assistants
              1. Requirements
                1. Limitations & Caveats
                  1. Troubleshooting
                    1. License
                      ID: 4ok9u922cb