Repository navigation
feat(graph-db): add openGauss backend and memory integration - #2564
SleepySuke wants to merge 23 commits into
Conversation
Add a strict OpenGaussGraphDBConfig for connection settings, logical tenant scopes, and bounded connection-pool configuration. Validate required credentials, port and timeout boundaries, positive embedding dimensions, and ordered pool limits. Require a tenant scope for shared databases and preserve explicitly supplied scope values. Add 105 parameter cases covering valid and invalid configuration, JSON/YAML round trips, hidden password repr, driver-independent imports, and existing backend configuration selection. Validation: - make format - poetry run pytest tests/configs tests/graph_dbs -q (237 passed; 3 existing opt-in Neo4j integration cases not enabled) - New configuration class: 26 statements and 6 branch exits covered, with zero missing statements or branch exits - pre-commit checks for both changed files passed
Add an internal node store with scoped business identities, stable native graphids, atomic batch upserts, ordered reads and row-locked partial updates. Reject incompatible layouts without deleting data. Prepare ordinary-role AGE sessions through a bounded psycopg2 pool. Preserve driver causes, roll back failures and close owned connections deterministically. Check server session cleanup within a fixed deadline after client close. Add GraphDBError and declare psycopg2-binary in tree-mem/all extras. Keep the incomplete backend out of the public factories. Validate 107 unit cases and 29 live openGauss integration cases. Config/graph regression: 373 passed, 3 existing skips. Full suite: 1207 passed, 9 existing skips, with live openGauss enabled and Hugging Face restricted to the local cache. Pool/store statement and branch coverage: 100%, with no new exclusions.
Add native directed typed relationships, scoped edge/neighbor queries, and atomic deletion of a node and all its incident edges. Serialize graph mutations to preserve edge uniqueness and prevent deletion races. Delete incident edges with AGE and node label rows with SQL in one transaction, preserving trigger and permission failure rollback behavior. Bind business values and validate relationship identifiers before borrowing a connection. Add 73 unit cases and 17 live integration cases for directions, scope, self/parallel edges, concurrency, special values and rollback. Cumulative config/graph regression: 463 passed, 3 existing skips. Full suite: 1297 passed, 9 existing skips, with live openGauss enabled and Hugging Face restricted to the local cache. Pool/store statement and branch coverage: 100%, with no new exclusions.
Add directed shortest paths with deterministic tie breaking and a strict five-hop bound. Return complete two-way neighborhood nodes and induced edges, preserving native direction, parallel edge types and self-loops. Rank active non-reasoning/non-working memories by unique tag overlap, with scoped exclusions, deterministic ties and optional vector projection. Reject malformed tag data and invalid inputs instead of returning false success. Add 86 unit cases and 21 live integration cases for traversal, projections, scope, special strings, tag filtering and permission failure recovery. Cumulative config/graph regression: 570 passed, 3 existing skips. Full suite: 1404 passed, 9 existing skips, with live openGauss enabled and Hugging Face restricted to the local cache. Pool/store statement and branch coverage: 100%, with no new exclusions.
Consolidate the connection pool, AGE node/graph operations and filters in OpenGaussGraphDB, following the existing PostgreSQL and PolarDB layout. Create the pool in __init__ and keep filter parameters local to each call. Include scoped metadata/type queries, atomic conditional deletion and soft-delete/restore visibility tests. Preserve AGE fractional-number round trips and the existing transaction, isolation and error contracts. Keep unfinished BaseGraphDB methods abstract and factory registration pending. Replace the private connection and storage modules with opengauss.py; test-only concrete support raises for every unfinished capability. Validation: 398 storage/graph unit tests and 125 real openGauss integration tests; configs/graph_dbs 760 passed, 3 existing skips; full suite 1594 passed, 9 existing skips. opengauss.py has 100% statement and branch coverage. Formatting, applicable hooks and lock checks passed; temporary resources 0.
Add DataVec cosine retrieval with normalized scores, scoped filters, thresholds, projection and compatible Cube completion. Validate HNSW indexes through 2000 dimensions and use exact search up to 16000 dimensions. Replace underfilled vector candidates with one identically filtered query. Add native BM25 OR retrieval with raw scores and TAAT candidate scoring, including requests above 200 results. Validate the owned text index and recover its verified failed-write state with one REINDEX and one read retry. Keep unrelated errors explicit and never replay writes. Validate real GraphMemoryRetriever completion, filtering, rollback, concurrent recovery, index permissions, cancellation and timeouts. Keep factory registration pending the remaining maintenance and consumer APIs. Validation: make format; applicable hooks; poetry check --lock; configs/graph_dbs/retriever: 966 passed, 3 existing skips; make test: 1794 passed, 9 existing skips, including all 170 openGauss IT; backend statement and branch coverage: 100% (869 statements, 358 branch exits). This message describes the complete current workspace delta from 86ef67b.
Add scoped grouping, memory counts, existence checks, and oldest-memory eviction to OpenGaussGraphDB. Count all statuses and keep numeric AGE groups consistent with transaction-local sort aggregation. Lock a fixed candidate set, validate every timestamp, then remove incident edges and nodes in batches of at most 500 within one transaction. Preserve concurrent inserts for a later cleanup and propagate transaction failures without retrying writes. Cover ordinary-role database behavior, public vector/BM25 visibility, multibatch rollback, concurrent writers, cancellation, connection replacement, commit/return failures, and real MemoryManager/Reorganizer boundaries. Centralize transactional cursors and optional UTC/advisory setup. Compose named SQL fragments with collision checks and reusable bindings, and separate grouping validation, query construction, and result decoding. Validate with 741 backend unit tests and 226 real openGauss integration tests. The full suite passes 2040 tests with 9 existing skips; the complete openGauss module has 100% statement and branch coverage. Factory registration and the eight remaining abstract methods stay pending.
Select strictly activated memories of the requested type and Cube without same-Cube PARENT adjacency in one SQL snapshot. Preserve deterministic order, optional embeddings, scoped graph identities and existing transaction errors. Request embeddings from Reorganizer and verify real partitioning, summaries and PARENT writes with controlled model services. Keep the remaining seven abstract methods pending and factory wiring unchanged. Validation: make format; enabled openGauss make test: 2115 passed, 9 existing skips. Full opengauss.py statements/branches and modified optimize_structure function reach 100%. Temporary databases, roles and test/application sessions are zero after the run.
Add explicit cross-Cube reads with preserved node and edge ownership, global pagination, filtering and stable ordering. Keep ordinary exports scoped to the configured Cube. Counts, nodes and induced edges share one read-only REPEATABLE READ transaction; later borrowers return to read-write defaults. Validation: 40 Red to Green tests; 1407 passed / 3 existing skips in affected configuration, graph and textual-memory regression with real openGauss. Full opengauss.py: 1060 statements and 446 branch exits covered, no omissions. make format and git diff --check pass.
Validate graph input before borrowing, preserve existing node identities and merge edges in one transaction. Reject missing endpoints without partial imports. Clear a fixed locked Cube set in 500-node blocks and retain shared schema and other Cubes; drop_database clears only its configured scope. Validation: 43 Red to Green tests plus commit uncertainty, cancellation, physical scope and concurrency cases. Related real-database regression: 1456 passed, 3 existing skips. Full opengauss.py: 1123 statements and 482 branch exits covered. make format and git diff --check pass.
Resolve unique Cube ownership and reject ambiguous IDs. Add atomic scoped soft deletion, recovery and batch hard deletion while preserving other node properties, vectors and relations. Validation: 38 initial Red/Green cases, 3 concurrent transaction cases; 1497 passed and 3 existing skips in affected regression. The full backend has 1172/1172 statements and 496/496 branches covered; make format passes.
Implement scoped one-hop outgoing context queries. Explicitly reject semantic deduplication, conflict detection and merging with named capability errors; keep application MMR independent. All tests now use the production class. Validation: 6 initial Red cases; 8 targeted Green cases including structure. Full make test with real openGauss: 2246 passed, 9 unchanged existing skips. Backend coverage: 1183/1183 statements and 496/496 branches; changed Reorganizer function: 48/48 statements and 24/24 branches. make format and git diff --check pass. Temporary databases, roles and sessions: zero.
Exercise batch hard deletion under permission denial, last-block timeout and actual driver cancellation. Verify full rollback, preserved deletion records, replacement connections and search visibility after recovery. Validation: 30 targeted real-database tests pass; final make test reports 2249 passed with the same 9 existing skips. Full backend statement and branch coverage remains 100%; make format and git diff --check pass.
Restore read-only component mappings and leave close state with resource owners. Quiesce recovery before draining current and retired executors; reject self-close before entering terminal state. Preserve concurrent close results, retryable cleanup, explicit Cube initialization, and diagnostic logs.
Preserve primary IDs and derive stable Working IDs with working_binding. Submit each pair in one batch transaction on openGauss, propagate write failures, and preserve input result order across both add paths. Reuse binding cleanup rules and protect historical self-bindings. Cover rollback, retries, concurrent writes, capacity cleanup, and default Feedback with real database tests.
🤖 Open Code ReviewTarget: PR #2564 🔍 OpenCodeReview found 15 issue(s) in this PR.
1.
|
|
|
Description
This PR adds openGauss backend support to MemOS as part of internal feature development, targeting
dev-v2.0.36.It integrates AGE graph storage, native vector retrieval, and BM25 full-text search with the existing memory components, API, and Scheduler.
Related Issue / Task: N/A — internally planned feature development with no associated issue or task number.
Main changes
all_cubesandexclude_cube_id, with documentation and OpenAPI schema updates.Dependencies
psycopg2-binary >=2.9.13,<3.0.0, included in the optionaltree-memandallextras.Enable the backend with
GRAPH_DB_BACKEND=opengaussand configure the correspondingOPENGAUSS_*connection settings. The database and required extensions must be provisioned before use.Behavior changes and limitations
Type of change
How Has This Been Tested?
Latest recorded local validation:
Integration tests use openGauss 7.0.0 with AGE 1.0.0. Test fixtures provision disposable databases and roles; application operations run with an ordinary database role.
To reproduce, configure
MEMOS_OPENGAUSS_TEST_CONFIGwith a JSONOpenGaussGraphDBConfigfor a test administrator, then run:OpenAPI was exported using the repository's component fixtures. Standard
make openapiremains blocked in the local environment by missing InternetRetriever model configuration.These results describe local validation. Hosted CI and full service E2E are not claimed as complete.
Checklist
Issue/task linkage: N/A — no associated issue or internal task number.
Reviewer Checklist