Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
9c43395
add polardb.py
wustzdy Oct 18, 2025
188d4a2
add polardb.py
caocuilong Oct 18, 2025
b8b22b4
add polar factory
wustzdy Oct 18, 2025
a95f323
delete
caocuilong Oct 18, 2025
64e842d
update get_memory_count
wustzdy Oct 18, 2025
5b3fd09
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 18, 2025
ac3da33
update get_memory_count
wustzdy Oct 18, 2025
1d5581a
update node_not_exist
wustzdy Oct 18, 2025
57e5b4b
update remove_oldest_memory
wustzdy Oct 18, 2025
6e6febc
fix
caocuilong Oct 18, 2025
9aa5f67
update get_node
wustzdy Oct 18, 2025
5146de8
update get_node
wustzdy Oct 18, 2025
47862b4
update update_node
wustzdy Oct 18, 2025
2ce2c06
update delete_node
wustzdy Oct 18, 2025
5e48c54
add edge
caocuilong Oct 18, 2025
c050d8f
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 18, 2025
bc826a1
add create_extension,create_graph,create_edge
wustzdy Oct 18, 2025
31c5d70
add add_edge
wustzdy Oct 18, 2025
4e830fd
edge_exist
caocuilong Oct 19, 2025
7f95ec4
edge_exist
caocuilong Oct 19, 2025
63437c9
edge_exist
caocuilong Oct 19, 2025
580fb31
update edge_exists
wustzdy Oct 19, 2025
2746be1
update polardb.py
wustzdy Oct 19, 2025
f6e3187
update get_children_with_embeddings
wustzdy Oct 19, 2025
382dc18
update get_children_with_embeddings
wustzdy Oct 19, 2025
13c43a5
update get_subgraph
wustzdy Oct 19, 2025
5cf7772
update get_grouped_counts
wustzdy Oct 19, 2025
7f53eaf
update get_all_memory_items
wustzdy Oct 19, 2025
aed76a7
update export_graph
wustzdy Oct 19, 2025
58600a2
remove
wustzdy Oct 19, 2025
8579961
insert Memory
caocuilong Oct 19, 2025
b84577a
fix add_node
wustzdy Oct 19, 2025
59d5502
fix polardb.py
wustzdy Oct 19, 2025
6bfbe72
fix
caocuilong Oct 19, 2025
c152304
fix get_subgraph
wustzdy Oct 19, 2025
2149233
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 19, 2025
5a6b29d
fix
caocuilong Oct 19, 2025
7a8e0cb
get_grouped_counts
caocuilong Oct 19, 2025
771e771
update get_by_metadata
wustzdy Oct 19, 2025
0d3f3b9
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 19, 2025
9cc3d27
get_grouped_counts
caocuilong Oct 19, 2025
18a0c4d
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 19, 2025
ad2b542
update get_grouped_counts
wustzdy Oct 19, 2025
1275d79
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 19, 2025
825ba5b
update get_grouped_counts
wustzdy Oct 19, 2025
06f9bfc
get_grouped_counts
caocuilong Oct 19, 2025
57dbca9
update get_nodes
wustzdy Oct 19, 2025
d7cccd0
update search_by_embedding filter user_name
wustzdy Oct 20, 2025
25ad681
update search_by_embedding filter user_name
wustzdy Oct 20, 2025
16537a7
add filter user_name for update_node
wustzdy Oct 20, 2025
33bd15c
get_structure_optimization_candidates
caocuilong Oct 20, 2025
691c676
add filter user_name for update_node
wustzdy Oct 20, 2025
6e0dc79
fix
wustzdy Oct 20, 2025
332bf8d
fix
caocuilong Oct 20, 2025
77d6bc6
fix
caocuilong Oct 20, 2025
0104b6d
feat: 增加polardb的启动配置
lijicode Oct 20, 2025
503ec3c
fix
caocuilong Oct 20, 2025
e0bf484
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 20, 2025
4245ee0
fix
caocuilong Oct 20, 2025
9651240
fix get_structure_optimization_candidates
wustzdy Oct 20, 2025
260f2d0
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 20, 2025
fed35de
fix get_all_memory_items
wustzdy Oct 20, 2025
d7a7ada
fix get_all_memory_items
wustzdy Oct 20, 2025
ec43e3c
remove embedding for get_nodes
wustzdy Oct 20, 2025
b2a893f
fix get_structure_optimization_candidates
wustzdy Oct 20, 2025
4b849f3
add _parse_node_new
wustzdy Oct 20, 2025
7c79df6
update get_all_memory_items
wustzdy Oct 20, 2025
834b0ec
update get_all_memory_items
wustzdy Oct 20, 2025
ee365ad
Merge remote-tracking branch 'origin/test' into test_zdy_1001
caocuilong Oct 20, 2025
ee9fb71
update get_all_memory_items for include_embedding
wustzdy Oct 20, 2025
862aa8d
feat: server router add polardb config
lijicode Oct 20, 2025
dced597
feat: server router add polardb config
lijicode Oct 20, 2025
c2f7ff3
update get_all_memory_items for include_embedding False
wustzdy Oct 20, 2025
6d3d446
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 20, 2025
563a8a1
update get_all_memory_items for include_embedding False
wustzdy Oct 20, 2025
2d62433
fix
caocuilong Oct 20, 2025
7f9b4ab
fix get_all_memory_items
caocuilong Oct 20, 2025
3a8c98c
update get_all_memory_items for include_embedding False
wustzdy Oct 20, 2025
5fe53f1
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 20, 2025
26590a9
fix get_all_memory_items
caocuilong Oct 20, 2025
fd4df0e
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 20, 2025
9ecc94b
update get_all_memory_items for include_embedding False
wustzdy Oct 20, 2025
932e410
update get_grouped_counts
wustzdy Oct 21, 2025
6222430
update get_grouped_counts
wustzdy Oct 21, 2025
94a557a
add_node and graph_id
wustzdy Oct 21, 2025
e3e97d2
fix
caocuilong Oct 21, 2025
1cc11d9
fix get_all_memory_items false
wustzdy Oct 21, 2025
3525481
fix
caocuilong Oct 21, 2025
50a75bb
fix get_all_memory_items true
wustzdy Oct 21, 2025
e76b8cd
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 21, 2025
d949f9d
fix
caocuilong Oct 21, 2025
9849b94
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 21, 2025
0bd074a
fix
caocuilong Oct 21, 2025
e1087c1
fix
caocuilong Oct 21, 2025
c2eb13b
fix export_graph
caocuilong Oct 21, 2025
fee4a73
fix export_graph
caocuilong Oct 21, 2025
7c59fbc
fix get_by_metadata
caocuilong Oct 21, 2025
7957db4
update get_neighbors_by_tag
wustzdy Oct 21, 2025
d3cf342
update get_neighbors_by_tag
wustzdy Oct 21, 2025
73c7f0d
update get_neighbors_by_tag
wustzdy Oct 21, 2025
56351e5
fix
caocuilong Oct 21, 2025
b363c47
fix
caocuilong Oct 21, 2025
5a448d8
add import_graph
wustzdy Oct 21, 2025
0e05327
fix
caocuilong Oct 21, 2025
88a2718
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 21, 2025
b96874f
add get_edges
wustzdy Oct 21, 2025
03af765
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 21, 2025
1f8154a
add clear
wustzdy Oct 21, 2025
5436b59
get_neighbors_by_tag
wustzdy Oct 22, 2025
c7b5f7c
get_neighbors_by_tag
wustzdy Oct 22, 2025
32a6298
update get_by_metadata
wustzdy Oct 22, 2025
f7ab323
search_by_emdedding remove embedding
caocuilong Oct 22, 2025
ab50c35
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 22, 2025
fe1a9fd
fix:parseJson.py
caocuilong Oct 22, 2025
69cbcb0
fix:get_my_metadata
caocuilong Oct 22, 2025
e91d190
fix
wustzdy Oct 22, 2025
bd190c6
fix get_by_metadata result
wustzdy Oct 22, 2025
779db23
update polardb.py
wustzdy Oct 23, 2025
3159dc2
fix _coerce_metadata
wustzdy Oct 23, 2025
c668123
feat: add rerank time
lijicode Oct 24, 2025
69745ab
feat: add rerank time
lijicode Oct 24, 2025
9c15f5b
fix:node_not_exist
caocuilong Oct 24, 2025
45533c4
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 24, 2025
157deff
import node
caocuilong Oct 24, 2025
c8e1cea
import node
caocuilong Oct 24, 2025
c3a2367
feat: fix merge_config_with_default
lijicode Oct 24, 2025
00c9b4a
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
lijicode Oct 24, 2025
8f10b2d
import node
caocuilong Oct 24, 2025
46dabd2
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 24, 2025
b8f29c1
fix
caocuilong Oct 24, 2025
0b58d47
fix
caocuilong Oct 24, 2025
bfeb4dc
feat: fix polardb
lijicode Oct 26, 2025
ed20e79
feat: fix scheduler method name
lijicode Oct 26, 2025
b91c203
fix get_by_metadata for "query": "How long ago was Caroline's 18th bi…
wustzdy Oct 26, 2025
794c9fd
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
wustzdy Oct 26, 2025
c1f2c83
fix get_by_metadata for "query": "How long ago was Caroline's 18th bi…
wustzdy Oct 26, 2025
365c480
fix get_node format_param_value
wustzdy Oct 27, 2025
3165a8d
Merge remote-tracking branch 'refs/remotes/origin/dev' into test_zdy_…
wustzdy Oct 27, 2025
5cfd425
Merge remote-tracking branch 'refs/remotes/origin/dev' into test_zdy_…
wustzdy Oct 27, 2025
1ebc660
feat: fix CONFIG
lijicode Oct 27, 2025
8c6f7f4
fix
caocuilong Oct 27, 2025
6dd35b7
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 27, 2025
67bd2c8
feat: fix import
lijicode Oct 27, 2025
20c63da
feat: delete test file
lijicode Oct 27, 2025
41040e2
feat: fix polardb
lijicode Oct 27, 2025
4d15cd9
feat: fix recall
lijicode Oct 27, 2025
f005939
Comment out unused configuration handling code
wustzdy Oct 27, 2025
5cf3fa6
fix
caocuilong Oct 27, 2025
2bec50c
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 27, 2025
1e09846
feat: fix polardb
lijicode Oct 27, 2025
9c8cc61
import polardb
caocuilong Oct 27, 2025
7f69ab6
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 27, 2025
58b4e1d
feat: fix polardb
lijicode Oct 27, 2025
e0c77ac
fix
caocuilong Oct 27, 2025
3a9d542
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 27, 2025
7ab927f
feat: fix polardb
lijicode Oct 27, 2025
8608c07
fix
caocuilong Oct 27, 2025
86560d2
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
caocuilong Oct 27, 2025
26f2b5d
fix
caocuilong Oct 27, 2025
d566590
feat: fix polardb
lijicode Oct 27, 2025
50b0f85
Merge branch 'dev' into test_zdy_1001
CaralHsi Oct 27, 2025
af929c9
feat: delete polardb
lijicode Oct 27, 2025
5fef6aa
feat: fix utils
lijicode Oct 27, 2025
5a70742
feat: fix polardb
lijicode Oct 27, 2025
83cc7a3
feat: format polardb
lijicode Oct 27, 2025
4c7f680
feat: format utils
lijicode Oct 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ volcengine-python-sdk==4.0.6
watchfiles==1.1.0
websockets==15.0.1
xlrd==2.0.2
xlsxwriter==3.2.5
xlsxwriter==3.2.5
30 changes: 30 additions & 0 deletions src/memos/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,32 @@ def get_milvus_config():
"password": os.getenv("MILVUS_PASSWORD", "12345678"),
}

@staticmethod
def get_polardb_config(user_id: str | None = None) -> dict[str, Any]:
"""Get PolarDB configuration."""
use_multi_db = os.getenv("POLAR_DB_USE_MULTI_DB", "false").lower() == "true"

if use_multi_db:
# Multi-DB mode: each user gets their own database (physical isolation)
db_name = f"memos{user_id.replace('-', '')}" if user_id else "memos_default"
user_name = None
else:
# Shared-DB mode: all users share one database with user_name tag (logical isolation)
db_name = os.getenv("POLAR_DB_DB_NAME", "shared_memos_db")
user_name = f"memos{user_id.replace('-', '')}" if user_id else "memos_default"

return {
"host": os.getenv("POLAR_DB_HOST", "localhost"),
"port": int(os.getenv("POLAR_DB_PORT", "5432")),
"user": os.getenv("POLAR_DB_USER", "root"),
"password": os.getenv("POLAR_DB_PASSWORD", "123456"),
"db_name": db_name,
"user_name": user_name,
"use_multi_db": use_multi_db,
"auto_create": True,
"embedding_dimension": int(os.getenv("EMBEDDING_DIMENSION", 1024)),
}

@staticmethod
def get_mysql_config() -> dict[str, Any]:
"""Get MySQL configuration."""
Expand Down Expand Up @@ -540,6 +566,7 @@ def create_user_config(user_name: str, user_id: str) -> tuple[MOSConfig, General
neo4j_community_config = APIConfig.get_neo4j_community_config(user_id)
neo4j_config = APIConfig.get_neo4j_config(user_id)
nebular_config = APIConfig.get_nebular_config(user_id)
polardb_config = APIConfig.get_polardb_config(user_id)
internet_config = (
APIConfig.get_internet_config()
if os.getenv("ENABLE_INTERNET", "false").lower() == "true"
Expand All @@ -549,6 +576,7 @@ def create_user_config(user_name: str, user_id: str) -> tuple[MOSConfig, General
"neo4j-community": neo4j_community_config,
"neo4j": neo4j_config,
"nebular": nebular_config,
"polardb": polardb_config,
}
graph_db_backend = os.getenv("NEO4J_BACKEND", "neo4j-community").lower()
if graph_db_backend in graph_db_backend_map:
Expand Down Expand Up @@ -607,10 +635,12 @@ def get_default_cube_config() -> GeneralMemCubeConfig | None:
neo4j_community_config = APIConfig.get_neo4j_community_config(user_id="default")
neo4j_config = APIConfig.get_neo4j_config(user_id="default")
nebular_config = APIConfig.get_nebular_config(user_id="default")
polardb_config = APIConfig.get_polardb_config(user_id="default")
graph_db_backend_map = {
"neo4j-community": neo4j_community_config,
"neo4j": neo4j_config,
"nebular": nebular_config,
"polardb": polardb_config,
}
internet_config = (
APIConfig.get_internet_config()
Expand Down
1 change: 1 addition & 0 deletions src/memos/api/routers/server_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def _build_graph_db_config(user_id: str = "default") -> dict[str, Any]:
"neo4j-community": APIConfig.get_neo4j_community_config(user_id=user_id),
"neo4j": APIConfig.get_neo4j_config(user_id=user_id),
"nebular": APIConfig.get_nebular_config(user_id=user_id),
"polardb": APIConfig.get_polardb_config(user_id=user_id),
}

graph_db_backend = os.getenv("NEO4J_BACKEND", "nebular").lower()
Expand Down
54 changes: 54 additions & 0 deletions src/memos/configs/graph_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,59 @@ def validate_config(self):
return self


class PolarDBGraphDBConfig(BaseConfig):
"""
PolarDB-specific configuration.

Key concepts:
- `db_name`: The name of the target PolarDB database
- `user_name`: Used for logical tenant isolation if needed
- `auto_create`: Whether to automatically create the target database if it does not exist
- `use_multi_db`: Whether to use multi-database mode for physical isolation

Example:
---
host = "localhost"
port = 5432
user = "postgres"
password = "password"
db_name = "memos_db"
user_name = "alice"
use_multi_db = True
auto_create = True
"""

host: str = Field(..., description="Database host")
port: int = Field(default=5432, description="Database port")
user: str = Field(..., description="Database user")
password: str = Field(..., description="Database password")
db_name: str = Field(..., description="The name of the target PolarDB database")
user_name: str | None = Field(
default=None,
description="Logical user or tenant ID for data isolation (optional, used in metadata tagging)",
)
auto_create: bool = Field(
default=False,
description="Whether to auto-create the database if it does not exist",
)
use_multi_db: bool = Field(
default=True,
description=(
"If True: use multi-database mode for physical isolation; "
"each tenant typically gets a separate database. "
"If False: use a single shared database with logical isolation by user_name."
),
)
embedding_dimension: int = Field(default=1024, description="Dimension of vector embedding")

@model_validator(mode="after")
def validate_config(self):
"""Validate config."""
if not self.db_name:
raise ValueError("`db_name` must be provided")
return self


class GraphDBConfigFactory(BaseModel):
backend: str = Field(..., description="Backend for graph database")
config: dict[str, Any] = Field(..., description="Configuration for the graph database backend")
Expand All @@ -162,6 +215,7 @@ class GraphDBConfigFactory(BaseModel):
"neo4j": Neo4jGraphDBConfig,
"neo4j-community": Neo4jCommunityGraphDBConfig,
"nebular": NebulaGraphDBConfig,
"polardb": PolarDBGraphDBConfig,
}

@field_validator("backend")
Expand Down
2 changes: 2 additions & 0 deletions src/memos/graph_dbs/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from memos.graph_dbs.nebular import NebulaGraphDB
from memos.graph_dbs.neo4j import Neo4jGraphDB
from memos.graph_dbs.neo4j_community import Neo4jCommunityGraphDB
from memos.graph_dbs.polardb import PolarDBGraphDB


class GraphStoreFactory(BaseGraphDB):
Expand All @@ -14,6 +15,7 @@ class GraphStoreFactory(BaseGraphDB):
"neo4j": Neo4jGraphDB,
"neo4j-community": Neo4jCommunityGraphDB,
"nebular": NebulaGraphDB,
"polardb": PolarDBGraphDB,
}

@classmethod
Expand Down
Loading