"Your memory belongs to you, not the cloud."
I built this project with a simple yet powerful goal: Total Data Sovereignty. In an era of subscription-based AI services and cloud dependencies, I wanted a solution that is:
- 100% Local & Private: No data ever leaves your machine. No API fees, no privacy risks.
- Permanent: As long as your hard drive exists, your AI's memory exists. No fear of service shutdowns.
- Infinite Capacity: The only limit is your local disk space.
- High Performance: Utilizing local GPU acceleration (TensorRT/CUDA) for lightning-fast embedding and retrieval.
This is a Memory Context Protocol (MCP) server that gives your AI (like Gemini CLI, Claude Desktop) a persistent, searchable, and evolving long-term memory.
- Hybrid Search Architecture: Combines LanceDB (Vector Search for semantic understanding) and SQLite FTS5 (Full-Text Search for exact keyword matching) for high-precision recall.
- Hardware Acceleration: Powered by ONNX Runtime with TensorRT/CUDA execution providers for millisecond-level embedding generation.
- Standard MCP Tools:
save_memory: Store snippets, code, docs, or personal facts (with automatic duplicate detection).search_memory: Semantic & keyword retrieval.list_memories: View recent entries.delete_memory: Manage and clean up data.update_memory: Update existing memory by ID.
- Lazy Loading: Optimized startup time with on-demand resource initialization.
- Zero Cost: Runs entirely on your existing hardware.
- OS: Windows (tested)
- Python: 3.10 or higher.
- Hardware: NVIDIA GPU recommended (for TensorRT/CUDA acceleration), but works on CPU.
- MCP Client: Gemini CLI or Claude Desktop.Or any IDE that can be configured with MCP.
git clone https://github.com/YanZiBin/Local-memory-mcp.git
cd Local-memory-mcpTo ensure GPU libraries work correctly, Conda is highly recommended.
conda create -n Local-memory-mcp python=3.10
conda activate Local-memory-mcppip install fastmcp lancedb onnxruntime-gpu transformers numpy uvicorn(Note: If you don't have a GPU, install onnxruntime instead of onnxruntime-gpu)
This project uses BAAI/bge-m3 converted to ONNXhere. You need to download the model files into the bge-m3-onnx directory.
You can use huggingface-cli or manually download these files:
config.jsonmodel.onnxmodel.onnx_datavocab.txtsentence_transformers.onnxsentence_transformers.onnx_datatokenizer_config.jsontokenizer.json
Place them inside a folder named bge-m3-onnx in the project root.
Since this server uses heavy local models, we recommend the Manual Start (SSE Mode) for stability.
-
Start the Server: Open a terminal and run:
python server.py
Wait until you see:
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) -
Connect your Client (e.g., Gemini CLI):
Edit your Gemini CLI configuration file (usually at
~/.gemini/settings.jsonor%USERPROFILE%\.gemini\settings.jsonon Windows):{ "mcpServers": { "local-memory": { "url": "http://localhost:8000/sse", "type": "sse" } } } -
Start using it! Open Gemini CLI and try:
"Save this memory: My project uses Python 3.10." "Search my memories for 'project'."
We are currently transitioning to Phase 4 (Memory Management).
-
Phase 1: Prototype
- Initialize MCP server with
fastmcp. - Basic in-memory storage (dict).
- Implement basic
save_memory&search_memory(keyword matching). - Manual connection testing with Gemini CLI.
- Initialize MCP server with
-
Phase 2: Persistence
- Integrate SQLite FTS5 and LanceDB.
- Integrate local ONNX embedding model.
- Dual-storage architecture (Full-text + Vector).
list_memoriesanddelete_memorytools.
-
Phase 3: Intelligent Retrieval (Completed)
- Implement RRF (Reciprocal Rank Fusion) algorithm for high-quality hybrid search.
- Add similarity thresholds & Top-K limits to reduce noise.
- Implement Contextual Retrieval (Enhanced context storage).
- (Optional) Add Reranker for higher precision.
-
Phase 4: Memory Management
- Duplicate detection on save (similarity-based).
- Lifecycle management (Time decay, Conflict tagging).
-
Phase 5: Advanced Optimization
- Expose Resources: Project summaries, ADR (Architecture Decision Records) guardrails.
- Architectural guardrails (Recall ADRs on violation) & Task chain tracking.
“你的记忆属于你,而不是云端。”
开发这个项目的初衷非常纯粹:实现完全的数据主权。 在这个万物订阅制、隐私担忧日益严重的时代,我希望构建一个这样的解决方案:
- 完全本地化 & 隐私安全: 没有任何数据会上传云端。没有 API 调用费,没有隐私泄露风险。
- 永久存储: 只要你的硬盘还在,你的 AI 记忆就在。不必担心服务商倒闭或“跑路”。
- 无限容量: 唯一的限制是你本地硬盘的大小(相当于无限)。
- 极致性能: 利用本地 GPU 加速(TensorRT/CUDA),实现毫秒级的记忆存取。
这是一个 MCP (Model Context Protocol) 服务器,它为你的 AI 工具(如 Gemini CLI, Claude Desktop)提供了一个持久化、可搜索、不断进化的“外脑”。
- 混合搜索架构: 结合了 LanceDB(向量搜索,理解语义)和 SQLite FTS5(全文搜索,精准匹配关键词),并通过 RRF (倒数排名融合) 算法进行智能排序,确保召回率和准确率。
- 硬件加速: 基于 ONNX Runtime 和 TensorRT/CUDA,充分释放本地显卡性能。
- 标准 MCP 工具集:
save_memory: 保存代码片段、文档总结或个人事实(自动检测重复内容)。search_memory: 语义或关键词检索(支持相似度阈值过滤)。list_memories: 查看最近的记忆。delete_memory: 删除过时信息。update_memory: 按 ID 更新现有记忆。
- 懒加载设计 (Lazy Loading): 优化启动流程,按需加载重型模型,拒绝卡顿。
- 零成本: 以前需要付费购买的向量存储服务,现在免费运行在你自己的电脑上。
- 操作系统: Windows (已充分测试)
- Python: 3.10 或更高版本。
- 硬件: 推荐使用 NVIDIA 显卡(以获得 TensorRT/CUDA 加速),但也支持 CPU 运行。
- MCP 客户端: Gemini CLI 或 Claude Desktop。或者任何可以配置mcp的IDE。
git clone https://github.com/YanZiBin/Local-memory-mcp.git
cd Local-memory-mcp为了避免 CUDA 依赖冲突,建议使用 Conda。
conda create -n Local-memory-mcp python=3.10
conda activate Local-memory-mcppip install fastmcp lancedb onnxruntime-gpu transformers numpy uvicorn(注:如果你没有 NVIDIA 显卡,请将 onnxruntime-gpu 替换为 onnxruntime)
本项目使用 BAAI/bge-m3 的 ONNX 量化版本here。你需要将模型文件下载到项目根目录下的 bge-m3-onnx 文件夹中。
你可以使用 huggingface-cli 或手动下载以下文件:
config.jsonmodel.onnxmodel.onnx_datavocab.txtsentence_transformers.onnxsentence_transformers.onnx_datatokenizer_config.jsontokenizer.json
确保它们都在 bge-m3-onnx 文件夹内。
由于本项目加载了本地大模型,为了稳定性,我们推荐使用 手动启动 (SSE 模式)。
-
启动服务器: 打开终端(CMD/PowerShell),运行:
python server.py
等待直到看到提示:
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) -
连接客户端 (以 Gemini CLI 为例):
编辑你的 Gemini CLI 配置文件(通常位于
~/.gemini/settings.json或 Windows 的%USERPROFILE%\.gemini\settings.json):{ "mcpServers": { "local-memory": { "url": "http://localhost:8000/sse", "type": "sse" } } } -
开始体验! 打开 Gemini CLI,直接对话:
“帮我记住:我的项目运行在 Python 3.10 环境下。” “搜索记忆:关于项目环境的信息。”
目前项目正过渡到 第四阶段:记忆管理。
-
第一阶段:原型验证
- 使用
fastmcp初始化 MCP 服务器。 - 使用内存字典进行临时存储。
- 实现基础的
save_memory和search_memory(关键词匹配)。 - 配置 stdio 并在 Gemini CLI 中测试手动连接。
- 使用
-
第二阶段:持久化存储
- 引入 SQLite FTS5 和 LanceDB。
- 集成本地 ONNX 嵌入模型 生成向量。
- 实现双库存储(全文 + 向量)。
- 新增
list_memories(列出记忆)和delete_memory(删除记忆)工具。
-
第三阶段:智能筛选 (已完成)
- 实现 RRF (倒数排名融合) 算法,实现高质量混合检索。
- 增加相似度阈值和 Top-K 限制,减少噪声。
- 实现 Contextual Retrieval(增强文本存储)。
- (可选)加入 Reranker 重排序模型以提升精度。
-
第四阶段:记忆管理
- 保存时自动检测重复内容(基于相似度)
- 实现生命周期管理(时间衰减、冲突标记)。
-
第五阶段:高级优化
- 暴露 Resources(资源):项目摘要、ADR 架构决策记录守栏等。
- 实现架构守栏(违规时自动召回 ADR)和任务链跟踪。
License: MIT Author: [YanZiBin]