llama-memory
llama-memory
用于 llama-server 的 MCP 记忆服务,通过 Postgres + PGVector 提供持久化历史和语义记忆。
注意:本项目仅用于本地/演示用途。未经额外加固(HTTPS、适当认证、备份),请勿直接暴露到互联网。
功能
语义记忆:按含义而非仅关键词保存和检索记忆。
对话桥接:LLM 自动创建对话,记忆相互关联。
跨会话回忆:询问“我们之前聊过什么?”即可获得准确答案。
MCP 协议:直接与 llama-server 内置的 MCP 支持配合使用。
Related MCP server: engram
要求
Python 3.11(推荐使用 Miniconda)
PostgreSQL 16+ 并带有 PGVector 扩展
带 --jinja 标志的 llama-server(工具调用必需)
在 llama-server 上运行 nomic-embed-text(默认端口 8081)
安装
# Clone the repo
git clone https://github.com/noualit/llama-memory-local.git
cd llama-memory-local
# Create environment
conda create -n llama-memory python=3.11
conda activate llama-memory
# Install dependencies
pip install -e .配置
将 .env.example 复制为 .env 并进行编辑:
cp .env.example .env示例:
# Database
DATABASE_URL="postgresql://postgres:yourpassword@localhost:5432/llamamem"
# Llama-server (LLM)
LLAMA_SERVER_BASE_URL="http://localhost:8080"
# Embedding model (nomic-embed-text via llama-server)
EMBEDDING_MODEL_URL="http://localhost:8081"
# Embedding model name (default: nomic-embed-text)
EMBEDDING_MODEL_NAME="nomic-embed-text"
# Service port
SERVICE_PORT=9001设置数据库
创建数据库并运行迁移:
psql -U postgres -c "CREATE DATABASE llamamem;"
alembic upgrade head应用还会在启动时自动确保基本模式,以方便使用。
运行服务
# Using the script
.\scripts\run_server.ps1
# Or directly
python -m uvicorn app.main:app --host 0.0.0.0 --port 9001连接到 llama-server
添加到您的 llama-server MCP 配置中:
{
"mcpServers": {
"llama-memory": {
"url": "http://YOUR_SERVER_IP:9001/mcp"
}
}
}服务必须可从 llama-server 访问。如果它们运行在不同的机器上,请使用实际 IP,而不是 localhost。
MCP 工具
工具 | 描述 |
create_conversation | 创建新的对话会话 |
list_conversations | 列出对话及其记忆数量 |
get_conversation_history | 获取对话中的所有记忆 |
search_memories | 跨所有记忆进行语义搜索 |
save_memory | 存储重要事实或决策 |
系统提示
您可以:
从服务获取推荐的系统提示:
GET /system-prompt → 返回纯文本。
或者将以下最小版本粘贴到 llama-server 中:
MEMORY WORKFLOW:
- At the start of each new conversation, call create_conversation with a short title.
- Use the conversation_id from create_conversation when calling save_memory.
- Before answering questions about past topics, call search_memories FIRST.
- When the user shares important information, save it with save_memory.
- If list_conversations has previous chats, check get_conversation_history for context.健康检查
curl http://localhost:9001/health返回数据库状态、嵌入服务状态和工具数量。
架构
高层结构:
app/main.py — FastAPI 应用、生命周期、/system-prompt
app/settings.py — 从 .env 读取的 Pydantic 设置
app/clients/embeddings.py — 调用 nomic-embed-text 生成向量
app/db/engine.py — asyncpg 连接池(单例)
app/db/schema.py — 启动时自动创建表
app/mcp/endpoint.py — MCP 协议处理器、速率限制器
app/mcp/tools/ — 各个工具的实现
migrations/ — Alembic 数据库迁移
开发
# Run tests
pytest tests/ -v
# Run with auto-reload
python -m uvicorn app.main:app --host 0.0.0.0 --port 9001 --reload有关贡献指南,请参阅 CONTRIBUTING.md。
许可证
MIT(参见 LICENSE 文件)。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenancePersistent semantic memory server for AI assistants via MCP, enabling long-term context retention and semantic search across conversations.11MIT
- AlicenseNot gradedqualityCmaintenanceProvides persistent, local-first AI memory across sessions via MCP tools for storing, searching, and retrieving context from past interactions.1MIT
- AlicenseAqualityDmaintenanceProvides persistent memory for AI assistants via MCP, enabling them to store and recall facts, preferences, and tasks across conversations using either local file storage or a cloud backend with semantic search.514MIT
- AlicenseAqualityDmaintenanceProvides persistent memory with semantic search for MCP-based AI agents, enabling them to store and recall information across sessions using vector embeddings.41MIT
Related MCP Connectors
Shared, governed long-term memory for AI agents across tools and sessions via MCP and REST.
Persistent memory for AI agents. Search, store, and recall across sessions.
Cross-AI personal memory. Save once in ChatGPT, recall in Claude, Mistral, Grok, or any MCP client.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/noualit/llama-memory-local'
If you have feedback or need assistance with the MCP directory API, please join our Discord server