Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/memos/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,8 @@ def get_polardb_config(user_id: str | None = None) -> dict[str, Any]:
def get_postgres_config(user_id: str | None = None) -> dict[str, Any]:
"""Get PostgreSQL + pgvector configuration for MemOS graph storage.
Uses standard PostgreSQL with pgvector extension.
Schema: memos.memories, memos.edges
Uses standard PostgreSQL with pgvector. Shard count, index, and
full-text configuration keep the backend defaults unless overridden.
"""
user_name = os.getenv("MEMOS_USER_NAME", "default")
if user_id:
Expand All @@ -922,7 +922,7 @@ def get_postgres_config(user_id: str | None = None) -> dict[str, Any]:
"schema_name": os.getenv("MEMOS_SCHEMA", "memos"),
"user_name": user_name,
"use_multi_db": False,
"embedding_dimension": int(os.getenv("EMBEDDING_DIMENSION", "384")),
"embedding_dimension": int(os.getenv("EMBEDDING_DIMENSION", "1024")),
"maxconn": int(os.getenv("POSTGRES_MAX_CONN", "20")),
}

Expand Down
33 changes: 28 additions & 5 deletions src/memos/configs/graph_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, ClassVar
from typing import Any, ClassVar, Literal

from pydantic import BaseModel, Field, field_validator, model_validator

Expand Down Expand Up @@ -195,8 +195,7 @@ class PostgresGraphDBConfig(BaseConfig):
Does NOT require Apache AGE or other graph extensions.
Schema:
- memos_memories: Main table for memory nodes (id, memory, properties JSONB, embedding vector)
- memos_edges: Edge table for relationships (source_id, target_id, type)
- {schema}_graph_{n}."Memory" and "Edges", one physical shard per tenant
Example:
---
Expand All @@ -223,13 +222,33 @@ class PostgresGraphDBConfig(BaseConfig):
default=False,
description="If False: use single database with logical isolation by user_name",
)
embedding_dimension: int = Field(
default=768, description="Dimension of vector embedding (768 for all-mpnet-base-v2)"
embedding_dimension: int = Field(default=1024, description="Dimension of vector embedding")
shard_count: int = Field(
default=400,
ge=1,
le=4096,
description="Number of MD5 tenant shards",
)
maxconn: int = Field(
default=20,
description="Maximum number of connections in the connection pool",
)
minconn: int = Field(
default=8,
ge=1,
description="Warm connections kept in the pool",
)
vector_index_type: Literal["hnsw", "ivfflat"] = Field(
default="hnsw",
description="pgvector approximate index type",
)
hnsw_m: int = Field(default=16, ge=2, le=100)
hnsw_ef_construction: int = Field(default=64, ge=4, le=1000)
ivfflat_lists: int = Field(default=100, ge=1)
fulltext_config: str = Field(
default="jiebacfg",
description="PostgreSQL text search configuration used to build search_vector",
)

@model_validator(mode="after")
def validate_config(self):
Expand All @@ -238,6 +257,10 @@ def validate_config(self):
raise ValueError("`db_name` must be provided")
if not self.use_multi_db and not self.user_name:
raise ValueError("In single-database mode, `user_name` must be provided")
if self.minconn > self.maxconn:
raise ValueError(f"`minconn` ({self.minconn}) must be <= `maxconn` ({self.maxconn})")
if not self.fulltext_config.replace(".", "_").isidentifier():
raise ValueError("`fulltext_config` must be a valid PostgreSQL configuration name")
return self


Expand Down
Loading
Loading