PostgreSQL + pgvector graph store backend for Mem0 — powered by dbay.cloud
Project description
mem0-dbay
干掉 Neo4j,一个数据库搞定一切。
mem0-dbay 是 Mem0 的图存储插件,用 dbay.cloud 的 Serverless PostgreSQL + pgvector 替代 Neo4j。向量存储和图存储跑在同一个数据库里,零基础设施运维。
为什么需要这个?
自托管 Mem0 需要 3 个独立的数据库:
Mem0 → PostgreSQL + pgvector (向量存储)
→ Neo4j (图存储) ← 额外基础设施
→ SQLite (历史记录)
Neo4j 带来的痛苦:
- 多一个数据库要部署、监控、备份、付费
- Docker 冷启动 90 秒(
start_period: 90s) - 完全不同的查询语言(Cypher)
- 依赖 APOC 插件
用 mem0-dbay,一切跑在一个 dbay.cloud 数据库上:
Mem0 → dbay.cloud PostgreSQL (向量 + 图谱 + 历史,全部搞定)
一个连接串。一个数据库。不用 Cypher。不用运维。
快速开始
1. 在 dbay.cloud 创建免费数据库
注册 dbay.cloud,创建一个数据库,拿到连接串:
postgres://user_xxx:password@pg.dbay.cloud:4432/my-mem0-db?sslmode=require&options=endpoint%3Dmy-mem0-db
pgvector 已预装。不需要手动启用扩展,不需要手动建表 —— mem0-dbay 全自动处理。
2. 安装
pip install mem0-dbay
3. 使用
import mem0_dbay
DBAY_URL = "postgres://user_xxx:password@pg.dbay.cloud:4432/my-mem0-db?sslmode=require&options=endpoint%3Dmy-mem0-db"
m = mem0_dbay.create_memory({
"graph_store": {
"provider": "dbay",
"config": {"connection_string": DBAY_URL, "embedding_dimension": 1536}
},
"vector_store": {
"provider": "pgvector",
"config": {"connection_string": DBAY_URL, "embedding_model_dims": 1536}
},
"llm": {
"provider": "openai",
"config": {"api_key": "sk-..."}
},
"embedder": {
"provider": "openai",
"config": {"api_key": "sk-..."}
},
})
# 添加记忆 —— 自动提取实体和关系
m.add("Alice 在 Google 当工程师", user_id="alice")
m.add("Bob 是 Alice 在 Google 的上司", user_id="alice")
# 搜索 —— 向量相似度 + 图谱关系扩展 + BM25 重排序
results = m.search("Alice 在哪里工作?", user_id="alice")
就这么简单。不需要装 Neo4j,不需要 Docker Compose 起 3 个容器。pip install + 一个连接串就行。
支持任何 OpenAI 兼容的 LLM
不只是 OpenAI —— 可以用 DeepSeek、硅基流动 SiliconFlow 或任何 OpenAI 兼容的服务:
m = mem0_dbay.create_memory({
"graph_store": {
"provider": "dbay",
"config": {"connection_string": DBAY_URL, "embedding_dimension": 1024}
},
"vector_store": {
"provider": "pgvector",
"config": {"connection_string": DBAY_URL, "embedding_model_dims": 1024}
},
"llm": {
"provider": "openai",
"config": {
"api_key": "sk-...",
"openai_base_url": "https://api.siliconflow.cn/v1",
"model": "deepseek-ai/DeepSeek-V3",
}
},
"embedder": {
"provider": "openai",
"config": {
"api_key": "sk-...",
"openai_base_url": "https://api.siliconflow.cn/v1",
"model": "BAAI/bge-m3",
}
},
})
为什么选 dbay.cloud?
dbay.cloud 是专为 AI 场景打造的 Serverless PostgreSQL 平台。
| 自建 PG + Neo4j | dbay.cloud | |
|---|---|---|
| 要管几个数据库 | 2 个(PG + Neo4j) | 0 个 —— 全托管 |
| 空闲成本 | 24/7 运行(~$50+/月) | Scale-to-zero —— 空闲零成本 |
| 冷启动 | Neo4j: 90秒 | ~500ms 热启动 / ~8s 冷启动 |
| 算力弹性 | 固定规格 | 1cu–8cu 按需弹性 —— 跟着负载走 |
| pgvector | 自己装 | 预装,HNSW 索引开箱即用 |
| BM25 全文检索 | 没有 | pg_search (ParadeDB) 预装 |
| 数据库分支 | 不可能 | Git 风格 copy-on-write 分支 |
| 搭建时间 | 几小时(Docker、配置、健康检查) | 30 秒 |
Scale-to-zero:空闲不花钱
大多数 AI 记忆数据库 90% 的时间都是空闲的。在 dbay.cloud 上,空闲数据库自动休眠,零成本。Agent 查询时,数据库 ~500ms 自动唤醒。每个用户一个独立记忆数据库也不是问题 —— 不活跃的不花钱。
Git 风格分支:A/B 测试记忆策略
想测试新的记忆反思策略,又不想影响生产数据?
main(生产记忆)
├── branch: experiment-a ← 测试新的实体提取 prompt
└── branch: experiment-b ← 测试不同的相似度阈值
分支是瞬间 copy-on-write —— 零存储开销。对比结果,留下赢家,删掉其余。其他记忆基础设施做不到这一点。
弹性算力:批处理轻松扩容
跑批量记忆反思任务?临时扩到 8cu(8 vCPU / 16 GB),跑完缩回 1cu。不用改配置、不用重启、不用停机。
它是怎么工作的?
Mem0 的图谱记忆其实只做很简单的操作 —— 不用 PageRank,不用最短路径,不用图算法:
| Mem0 做的事 | Neo4j (Cypher) | mem0-dbay (SQL) |
|---|---|---|
| 存实体 | :__Entity__ 节点 |
graph_nodes 表 |
| 向量相似搜索 | vector.similarity.cosine() |
pgvector <=> 算子 |
| 存关系 | MERGE (a)-[r:TYPE]->(b) |
INSERT INTO graph_edges |
| 查邻居 | MATCH (n)-[r]->(m) |
JOIN graph_edges ON ... |
两张 PostgreSQL 表替代一整个 Neo4j 实例。
Mem0 已经支持 pgvector 了,这个有什么不同?
Mem0 本身已经支持 pgvector 做向量存储。但图存储仍然需要 Neo4j(或 Memgraph / Neptune / Kuzu)。
mem0-dbay 把图存储也换成了 PostgreSQL,两个存储共用一个数据库:
向量存储 图存储
──────── ──────
Mem0 默认: pgvector ✅ Neo4j ❌(另一个数据库)
Mem0 + mem0-dbay: pgvector ✅ pgvector ✅(同一个数据库!)
也支持本地 PostgreSQL
如果你更喜欢自托管,mem0-dbay 也支持任何装了 pgvector 的 PostgreSQL:
"connection_string": "postgresql://user:pass@localhost:5432/mydb"
许可
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mem0_dbay-0.1.1.tar.gz.
File metadata
- Download URL: mem0_dbay-0.1.1.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd03d2c57e60d741697772621c44a9817648b3edf48cae340fa9497c134ea925
|
|
| MD5 |
4c6deeb773379f3e6a5026b3d54da1e5
|
|
| BLAKE2b-256 |
e5c2ddcfb3e457c4b0f26523fb9054145840cae565abe5e93b0d2fecad9eacf8
|
File details
Details for the file mem0_dbay-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mem0_dbay-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b401cc3c11cd0caf4205ea81bdf930da47bd00703429db83389f25ae9a55d9da
|
|
| MD5 |
d01e391a2d8e6f4026979164c08a6374
|
|
| BLAKE2b-256 |
99c12a84b2549faaaf4ef0743630851a4930dfc7b5a16cef85914dac1cc2f4ec
|