feat: add PostgreSQL + pgvector graph database backend#966
Merged
CaralHsi merged 10 commits intoMemTensor:dev-20260202-v2.0.5from Feb 3, 2026
Merged
feat: add PostgreSQL + pgvector graph database backend#966CaralHsi merged 10 commits intoMemTensor:dev-20260202-v2.0.5from
CaralHsi merged 10 commits intoMemTensor:dev-20260202-v2.0.5from
Conversation
added 5 commits
January 24, 2026 06:11
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
Contributor
|
Dear open-source author, |
CaralHsi
approved these changes
Feb 3, 2026
Collaborator
CaralHsi
left a comment
There was a problem hiding this comment.
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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