-
Notifications
You must be signed in to change notification settings - Fork 444
feat: add PostgreSQL + pgvector graph database backend #966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The MOSMCPStdioServer class was calling _setup_tools() which was not defined. Consolidated into MOSMCPServer which has the proper implementation.
- Create PostgresGraphDB class with full BaseGraphDB implementation - Add PostgresGraphDBConfig with connection pooling support - Register postgres backend in GraphStoreFactory - Update APIConfig with get_postgres_config method - Support GRAPH_DB_BACKEND env var with neo4j fallback Replaces Neo4j dependency with native PostgreSQL using: - JSONB for flexible node properties - pgvector for embedding similarity search - Standard SQL for graph traversal
Match krolik schema embedding dimension for compatibility
Add remove_oldest_memory and get_grouped_counts methods required by MemOS memory management functionality.
The merge/deduplicate logic was converting hit IDs to a set, losing the score-based ordering from vector search. Now keeps highest score per ID and returns results sorted by similarity score (descending). Fixes both _vector_recall and _fulltext_recall methods.
When embeddings aren't available, the reranker was defaulting to 0.5 scores, ignoring the relativity scores set during the recall phase. Now uses item.metadata.relativity from the recall stage when available. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add overlays/krolik/ with auth, rate-limit, admin API - Add Dockerfile.krolik for production builds - Add SYNC_UPSTREAM.md documentation - Keeps customizations separate from base MemOS for easy upstream sync
|
Dear open-source author, |
CaralHsi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Anatolykoptev,
Thanks for the contribution! We’ve verified everything locally/in our test environment and are ready to merge.
To keep things moving quickly, I’ll exclude SYNC_UPSTREAM.md from this merge (we’ll incorporate/adapt the guidance in our documentation going forward).
Summary
Add a new PostgreSQL + pgvector backend for the graph database layer. This provides a lightweight alternative to Neo4j that uses standard PostgreSQL with the pgvector extension for vector similarity search.
Key Features
remove_oldest_memory,get_grouped_counts)Files Changed
src/memos/graph_dbs/postgres.py- New PostgresGraphDB implementation (~885 lines)src/memos/configs/graph_db.py- Added PostgresGraphDBConfigsrc/memos/graph_dbs/factory.py- Registered postgres backendConfiguration Example
```yaml
graph_db:
backend: postgres
config:
host: postgres
port: 5432
user: memos
password: secret
db_name: memos
schema_name: memos
user_name: default
embedding_dimension: 768
```
Why PostgreSQL?
Test Plan