Skip to content

feature(graph-db): add openGauss backend and memory integration - #2618

Open
SleepySuke wants to merge 28 commits into
MemTensor:dev-v2.0.37from
SleepySuke:feat/opengauss-backend-v2.0.37
Open

SleepySuke wants to merge 28 commits into
MemTensor:dev-v2.0.37from
SleepySuke:feat/opengauss-backend-v2.0.37

Conversation

@SleepySuke

@SleepySuke SleepySuke commented Nov 13, 2026 •

Copy link
Copy Markdown

Description

This PR adds openGauss backend support to MemOS as part of internal feature development, targeting dev-v2.0.37.

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

  • Add openGauss configuration validation, factory registration, environment settings, and connection pooling.
  • Implement scoped node and relationship operations, graph traversal, metadata filtering, vector search, BM25 search, and SQL LIKE lookup.
  • Support memory counts, capacity management, snapshot export, atomic import, and scoped clearing.
  • Add optional Dashboard range selection through all_cubes and exclude_cube_id, with documentation and OpenAPI schema updates.
  • Improve resource ownership and shutdown ordering across API, Cube, Tree memory, and Scheduler components.
  • Preserve Cube identity during search and distinct identities for working and long-term memory pairs.
  • Propagate required storage failures through search and Feedback instead of treating failures as successful empty results.

DependenciesFixes #2616

  • openGauss Enterprise with AGE and native DataVec/BM25 capabilities.
  • psycopg2-binary >=2.9.13,<3.0.0, included in the optional tree-mem and all extras.

Enable the backend with GRAPH_DB_BACKEND=opengauss and configure the corresponding OPENGAUSS_* connection settings. The database and required extensions must be provisioned before use.

Behavior changes and limitations

  • Empty Dashboard categories return empty lists instead of synthetic empty Cube buckets.
  • Non-openGauss backends reject explicit non-null values for the new Dashboard range fields.
  • Required storage errors propagate to callers. Multi-step Feedback updates are not a single transaction.
  • Database-level semantic deduplication, conflict detection, and node merging remain unsupported.
  • Full service E2E, Java client integration, real-model validation, and production-scale performance testing remain follow-up work.

Type of change

  • New feature
  • Bug fix
  • Refactor
  • Documentation update

How Has This Been Tested?

Latest recorded local validation:

  • Full repository suite with real openGauss integration enabled: 2771 passed, 9 skipped, 45 warnings.
  • Unit and integration tests cover scoped storage, retrieval, rollback, backup/restore, Dashboard responses, memory identities, Feedback failures, and concurrent shutdown.
  • A separate local HTTP smoke test passed with real openGauss and controlled model assembly, covering Dashboard results, graceful shutdown, and database session cleanup.
  • Ruff checks and formatting passed.

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_CONFIG with a JSON OpenGaussGraphDBConfig for a test administrator, then run:

poetry install --extras all --with dev --with test
make format
make test

OpenAPI was exported using the repository's component fixtures. Standard make openapi remains 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.

  • Unit Test
  • Test Script Or Test Steps
  • Pipeline Automated API Test

Checklist

  • I have performed a self-review of the final PR diff
  • I have commented code in hard-to-understand areas
  • I have added tests covering the new functionality and fixes
  • I have included backend setup and behavior documentation in this PR
  • I have assigned or mentioned the reviewer

Issue/task linkage: N/A — no associated issue or internal task number.

Reviewer Checklist

  • Confirmed the implementation scope and behavior changes
  • Made sure required checks passed
  • Reviewed the provided tests and validation results

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.
Preserve committed feedback records when optional answer generation fails and
expose answer_status. Propagate required processing and queue failures without
falling back to ordinary add; preserve complete multi-Cube result objects.

Build missing Feedback from the borrowed Cube dependencies, retain explicit
injections, and reject late initialization after close. Reject the unsafe
internal process startup path and inherited Scheduler use; provide an
independent worker entry point that constructs resources in the child.

Validate keep_latest strings against an explicit 64-character bound before
conversion or connection acquisition, preserving zero and arbitrary int values.

Validation: make format; real openGauss make test (2950 passed, 9 skipped);
100% statements/branches for changed functions and all opengauss.py;
real Redis/spawn worker, socket HTTP and resource-release smoke checks.
Standard make openapi remains blocked by existing reader model config; the
fixture-exported application schema matches docs/openapi.json.
@Memtensor-AI Memtensor-AI added area:api 云服务 / FastAPI / OpenAPI / MCP area:core MOS 编排层 / 框架底座 / 跨模块问题 labels Nov 13, 2026
@Memtensor-AI Memtensor-AI added area:database graph_db + vector_db | 图数据库与向量数据库 area:docs 文档、示例 area:memcube GeneralMemCube / cube 生命周期 / cube 配置 area:memory 记忆存储、检索、更新、召回逻辑 area:scheduler 调度模块 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Nov 13, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2618
Task: e442af37d2b2097e
Base: dev-v2.0.37
Head: feat/opengauss-backend-v2.0.37
Head SHA: 97c8431d0bec190cf220d296728ed52ef7fbadef

🔍 OpenCodeReview found 22 issue(s) in this PR.

⚠️ Review warnings (1)

  • bounded analysis finalized with explicit task_done after reviewing all group files

1. docs/openapi.json (L1821-L1825)

APIFeedbackRequest publishes history as required, while its own schema types it as anyOf: [array, null] with no default. The same field is optional (default null, absent from required) in ChatRequest, ChatPlaygroundRequest and APIChatCompleteRequest. As written, POST /product/feedback tells generators that history is mandatory, so SDK clients will require a value callers normally omit (or pass null). Root cause is history: MessageList | None = Field(...) in APIFeedbackRequest — make it optional there and regenerate this spec rather than hand-editing the snapshot.


2. docs/openapi.json (L438)

This operation (the primary non-streaming chat endpoint) documents its 200 response as an empty schema {}; the same applies to /product/scheduler/wait and /health, and MemoryResponse.data is an untyped {"items": {}, "type": "array"}. The cause is that the handlers return plain dict/list without a response_model or return annotation (chat_handler.handle_chat_complete, handle_scheduler_wait, health_check, BaseResponse[list]). Consumers therefore cannot generate typed clients for chat, the most important use case. Add concrete response models in the router/models and regenerate.


3. docs/openapi.json (L4425-L4429)

Same concept, two key names: the request uses mem_cube_name_or_path while this response uses cube_name_or_path. This matches the two source models (RegisterCubeRequest vs RegisterCubeResponseData), so it is a model-level divergence, not a generation bug — but the published contract forces clients to map between them. Align the response field to mem_cube_name_or_path (or the request to cube_name_or_path) so request/response keys match.


4. docs/openapi.json (L2048)

Fields documented as deprecated in prose (moscube, mem_cube_id, memory_content, doc_path, source, and the (Internal) ones such as operation / auto_cleanup_working) carry no "deprecated": true. Tooling and generated SDKs only surface deprecation from that OpenAPI flag, so as published they look fully supported. Declare these via Field(..., deprecated=True) in the Pydantic models and regenerate so the flag is emitted.


5. src/memos/api/handlers/component_init.py (L362-L365)

The intent (see test_cleanup_error_does_not_replace_construction_error) is that a cleanup failure must not replace the construction error, but this guard only catches Exception while the outer handler catches BaseException. A BaseException raised during cleanup (e.g. a second KeyboardInterrupt while joining scheduler threads, MemoryError) escapes and supersedes the original initialization error. Catch BaseException in the guard to preserve the original exception in all cases.

💡 Suggested Change

Before:

        try:
            shutdown_components(components)
        except Exception:
            logger.exception("Failed to release components after initialization failure")

After:

        try:
            shutdown_components(components)
        except BaseException:
            logger.exception("Failed to release components after initialization failure")

6. src/memos/api/handlers/config_builders.py (L29)

Widening the parameter to str | None advertises that None is a valid argument, but the delegated getters are not all None-safe: APIConfig.get_neo4j_community_config (the default backend) and get_noshared_neo4j_config do user_id.replace('-', '') without a guard, so build_graph_db_config(None) raises AttributeError: 'NoneType' object has no attribute 'replace' on the default neo4j-community backend (the new tests already call build_graph_db_config(None)). Either keep the annotation as str = "default", or make the neo4j getters tolerate None like get_polardb_config/get_postgres_config do.

💡 Suggested Change

Before:

def build_graph_db_config(user_id: str | None = "default") -> GraphDBConfigFactory:

After:

def build_graph_db_config(user_id: str = "default") -> GraphDBConfigFactory:

7. src/memos/api/handlers/memory_handler.py (L557-L558)

Dashboard input validation signals client errors with bare ValueError, but nothing in the request path translates it: server_router.get_memories_dashboard calls this handler directly (no try/except), and there is no app-level ValueError exception handler. Malformed dashboard requests (all_cubes=True with a cube, conflicting scope controls, bad and/or nodes, unsupported-range requests on non-openGauss backends) will therefore surface as HTTP 500 instead of 400 — the same PR already standardises the add/feedback handlers on HTTPException. Consider raising HTTPException(status_code=400, ...) for these user-input cases (or wrap the scope resolution in a try/except that converts ValueError to a 400).


8. src/memos/api/lifecycle.py (L38-L39)

This helper is now a raising teardown, but the two shipped callers do not handle it: server_api.py:36 and server_api_ext.py:68 both call shutdown_components(...) directly after yield in the FastAPI lifespan. Any component close failure (e.g. rabbitmq_close timing out) will now propagate out of the ASGI lifespan shutdown and be reported as "Application shutdown failed", instead of the previous log-and-continue behavior.

It interacts badly with the if drained: guard above: when the scheduler close fails, drained is False, so the graph connection is never released either — yet at process shutdown there is no retry, so both the non-zero-exit/noisy failure and the leaked graph handle land on the normal shutdown path. Consider keeping best-effort logging here (or returning the failures) and letting callers decide, or wrapping the lifespan call sites in try/except.


9. src/memos/configs/mem_scheduler.py (L34)

The description contradicts the field itself: the only accepted value is "thread", but the text describes process-mode workers ("Create independent process workers inside the child..."). Since start_consumer() now raises ConfigurationError for process startup, this doc string is misleading for anyone configuring the scheduler. Suggest describing thread startup instead.

💡 Suggested Change

Before:

        description="Create independent process workers inside the child; runtime resources cannot be inherited.",

After:

        description="Run the message consumer in a thread inside the owning process (process startup is unsupported).",

10. src/memos/mem_feedback/feedback.py (L1269-L1272)

The previous 30s bounded wait plus cancellation was removed, so answer_future.result() (and core_future.result()) now block without any timeout, and the executor's __exit__ waits for both tasks. A hung LLM call in _generate_answer therefore blocks the synchronous feedback API indefinitely, even though the answer is optional and its failure is already handled. Consider a bounded wait for the optional answer task.

💡 Suggested Change

Before:

            if answer_future is not None:
                answer_status = "unavailable"
                try:
                    candidate = answer_future.result()

After:

            if answer_future is not None:
                answer_status = "unavailable"
                try:
                    candidate = answer_future.result(timeout=30)

11. src/memos/mem_scheduler/base_mixins/queue_ops.py (L330)

self._consumer_process can no longer be non-None here: start_consumer() raises ConfigurationError whenever scheduler_startup_mode == STARTUP_BY_PROCESS, and BaseSchedulerConfig.scheduler_startup_mode is now Literal["thread"], so the if self.scheduler_startup_mode == STARTUP_BY_PROCESS and self._consumer_process: branch above (and this new nested check) is unreachable dead code. The same unreachable process handling exists in BaseScheduler._join_consumers. Consider deleting the process branch and the _consumer_process field/STARTUP_BY_PROCESS import to avoid maintaining two shutdown paths that cannot both run.


12. src/memos/mem_scheduler/base_scheduler.py (L396)

Unbounded join() here (and in SchedulerDispatcherMonitor._quiesce) can make close() hang forever. The consumer loop wakes immediately on _stop_event, but a thread already inside self.memos_message_queue.get_messages(...) sits in a blocking Redis xreadgroup (SchedulerRedisQueue.task_broker), and the previous stop_consumer() path used join(timeout=5.0) precisely because that read can take a long time. Prefer a bounded join per thread and raise MemOSError (so _close_resources reports the unreleased part) when a thread is still alive, instead of blocking the caller indefinitely.

💡 Suggested Change

Before:

                thread.join()

After:

                if thread is threading.current_thread():
                    raise MemOSError("Scheduler cannot close from its consumer thread")
                thread.join(timeout=5.0)
                if thread.is_alive():
                    raise MemOSError(f"Scheduler worker thread {thread.name} did not exit")

13. src/memos/memories/textual/tree.py (L544-L545)

load() now raises MemoryError for a missing memory file, whereas it previously logged a warning and returned. GeneralMemCube.load() calls self.text_mem.load(dir) without handling this, so restoring a directory that has a valid config but no memory file (e.g. a cube whose text memory was never dumped, or a legacy dump with a different filename) now fails hard where it used to be a benign no-op. If the strict behavior is intended, consider explicitly documenting/validating it at the GeneralMemCube.load boundary so callers know a missing file is an error rather than a best-effort restore.


14. src/memos/memories/textual/tree.py (L115-L121)

close() only releases graph_store, but this object also owns self.memory_manager, whose GraphStructureReorganizer starts background threads (_run_message_consumer_loop, _run_structure_organizer_loop) when is_reorganize=True; those threads keep issuing graph queries after the store is closed (and the structure optimizer polls every 30s). MemoryManager.close() already exists to drain/stop them, so they should be stopped before releasing the graph (and before the close() call in the __init__ failure path).

💡 Suggested Change

Before:

    def close(self) -> None:
        """Release the graph created by this memory; injected graphs are borrowed."""

        def release() -> None:
            close = getattr(self.graph_store, "close", None)
            if self._owns_graph_store and callable(close):
                close()

After:

    def close(self) -> None:
        """Release the graph created by this memory; injected graphs are borrowed."""

        def release() -> None:
            memory_manager = getattr(self, "memory_manager", None)
            if memory_manager is not None:
                memory_manager.close()
            close = getattr(self.graph_store, "close", None)
            if self._owns_graph_store and callable(close):
                close()

15. src/memos/memories/textual/tree_text_memory/organize/manager.py (L133)

This drops the previous per-memory error isolation and the as_completed(..., timeout=500) guard. future.result() is now called eagerly in submission order, so the first failing memory aborts the loop: nodes already written by earlier futures stay committed (partial state), and exceptions from the remaining futures are never retrieved (silently dropped when the executor is torn down). If fail-fast is intended, it would be clearer to collect results with error aggregation and at least log failed futures; if not, restore the per-future try/except so one bad memory does not fail the whole add() batch.

💡 Suggested Change

Before:

            added_ids = [node_id for future in futures for node_id in future.result()]

After:

            added_ids: list[str] = []
            for future in futures:
                try:
                    added_ids.extend(future.result())
                except Exception:
                    logger.exception("Memory processing error:\n%s", traceback.format_exc())
                    raise

16. src/memos/multi_mem_cube/composite_cube.py (L62-L64)

ordered_views.setdefault(view.cube_id, view) silently drops any view whose cube_id was already seen. Stable merge order is already achieved by iterating the submitted futures list (instead of as_completed), so this dedupe is not needed for the stated goal and only changes fan-out coverage: two views targeting the same cube_id (or both having cube_id is None) now search only the first one. Iterate self.cube_views directly and keep the ordering fix.

💡 Suggested Change

Before:

        ordered_views = {}
        for view in self.cube_views:
            ordered_views.setdefault(view.cube_id, view)

After:

        with ContextThreadPoolExecutor(max_workers=2) as executor:
            futures = [executor.submit(_search_single_cube, view) for view in self.cube_views]

17. src/memos/multi_mem_cube/composite_cube.py (L70-L71)

future.result() is unguarded here. Since SingleCubeView._search_text now re-raises GraphDBError/ValueError, a failure in one cube aborts the whole multi-cube search (the remaining cubes' results are discarded and the request returns an error), whereas previously one bad cube only degraded to empty results. If keeping the loud-failure policy for a single cube is intended, the fan-out should still isolate per-cube failures (log + continue, or collect and re-raise after merging).

💡 Suggested Change

Before:

            for future in futures:
                cube_result = future.result()

After:

            for future in futures:
                try:
                    cube_result = future.result()
                except Exception:
                    self.logger.exception("[CompositeCubeView] cube search failed; skipping")
                    continue

18. src/memos/multi_mem_cube/single_cube.py (L221-L222)

Re-raising ValueError is broader than the DB failure this is meant to surface: pydantic.ValidationError is a ValueError subclass and many unrelated code paths in the search pipeline raise ValueError for data/shape issues. Such errors now fail the whole search request instead of returning an empty result set. Consider narrowing to the explicit failure type (e.g. GraphDBError) or to a dedicated validation exception.

💡 Suggested Change

Before:

        except (GraphDBError, ValueError):
            raise

After:

        except GraphDBError:
            raise

19. src/memos/graph_dbs/opengauss.py (L1521)

ORDER BY here references the output alias r{i} inside an expression (r0 COLLATE "C" ASC NULLS LAST). PostgreSQL (and openGauss) only resolves an output-column name in ORDER BY when it stands alone as a bare name; once it is part of a larger expression it is resolved against the FROM namespace, so r0 is unknown and the statement fails with column "r0" does not exist. The full query is SELECT MIN(agtype_out(g0)::text COLLATE "C") AS r0, COUNT(*) FROM (...) AS grouped GROUP BY g0 ORDER BY r0 COLLATE "C" ..., and the outer FROM exposes only g0..gN. This makes get_grouped_counts() raise for every call (it is used by MemoryManager._refresh_memory_size on the memory-add path). Repeat the aggregate expression (or order by the group key) rather than the alias, e.g. keep a list of MIN(ag_catalog.agtype_out(g{i})::text) expressions and reuse them in both the select list and the ORDER BY.

💡 Suggested Change

Before:

        order = ", ".join(f'r{i} COLLATE "C" ASC NULLS LAST' for i in range(len(group_fields)))

After:

        order = ", ".join(
            f'MIN(ag_catalog.agtype_out(g{i})::text) COLLATE "C" ASC NULLS LAST'
            for i in range(len(group_fields))
        )

20. src/memos/graph_dbs/opengauss.py (L2082)

Temporal filter parsing rejects the widely used Z zone designator on Python 3.10, which this package supports (requires-python = ">=3.10"): datetime.fromisoformat("2026-01-01T00:00:00Z") only works from Python 3.11, so on 3.10 a filter value with Z (the format used by this backend's own fixtures, e.g. test_opengauss_integration.py) raises ValueError("Invalid ISO date/time filter") while it succeeds on 3.11+. Normalize the designator before parsing.

💡 Suggested Change

Before:

                    instant = datetime.fromisoformat(value)

After:

                    normalized = value[:-1] + "+00:00" if value[-1:] in ("Z", "z") else value
                    instant = datetime.fromisoformat(normalized)

21. src/memos/graph_dbs/opengauss.py (L1272-L1274)

get_neighbors_by_tag reads every row of the Cube (all properties, plus embedding::text when include_embedding=True) and then filters/ranks in Python. The only predicate pushed to SQL is the scope and the exclusion list, so the work grows linearly with the Cube size and it is invoked per memory during organization (relation_reason_detector.py), making it effectively quadratic for large Cubes. Consider pushing the tag overlap to SQL (properties @> %(tags)s::ag_catalog.agtype for the overlap filter, and properties @> '{"tags": ...}' / ORDER BY on an overlap count) so only the matching candidates are materialized, keeping the Python ranking only as a fallback.


22. src/memos/graph_dbs/opengauss.py (L738)

tsvector_field and tsquery_config are validated here but never used afterwards: the generated query always ranks on the memory column with the native BM25 operator (ORDER BY memory <&> %(query)s). This silently diverges from the PostgreSQL/PolarDB backends, where tsvector_field selects the column being searched, so a caller that requests properties_tsvector_zh gets results from a different field with no error or warning. Either honour the requested field in the SQL or reject anything other than "memory" so the mismatch cannot go unnoticed.

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI Memtensor-AI added status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 and removed status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:api 云服务 / FastAPI / OpenAPI / MCP area:core MOS 编排层 / 框架底座 / 跨模块问题 area:database graph_db + vector_db | 图数据库与向量数据库 area:docs 文档、示例 area:memcube GeneralMemCube / cube 生命周期 / cube 配置 area:memory 记忆存储、检索、更新、召回逻辑 area:scheduler 调度模块 status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants