Skip to content

feat: PolarDB graph backend with decomposed mixin architecture#1054

Open
anatolykoptev wants to merge 1 commit intoMemTensor:mainfrom
anatolykoptev:refactor/polardb-decomposition
Open

feat: PolarDB graph backend with decomposed mixin architecture#1054
anatolykoptev wants to merge 1 commit intoMemTensor:mainfrom
anatolykoptev:refactor/polardb-decomposition

Conversation

@anatolykoptev
Copy link

@anatolykoptev anatolykoptev commented Feb 7, 2026

Summary

Overhaul of the graph_dbs/ module:

  • PolarDB backend: decomposed from a 4200-line monolith into a mixin-based polardb/ package (11 files, ~4300 lines). Each mixin handles a logical concern (connection, nodes, edges, search, filters, etc.)
  • Shared utilities (utils.py): extracted common helpers used across backends
  • BaseGraphDB extended with 8 new abstract methods for full-text search, tag-based neighbors, edge queries, and user management
  • Neo4j/Nebula backends updated to implement new abstract methods
  • Bug fix: self.execute_query() in count_nodes() didn't exist — replaced with standard cursor pattern

PolarDB package structure

File Lines Responsibility
__init__.py 30 Composes all mixins into PolarDBGraphDB
connection.py 334 Pool management, health checks, retries
schema.py 172 AGE extensions, tables, indexes
nodes.py 715 Node CRUD + agtype parsing
edges.py 267 Edge CRUD
filters.py 582 Dual SQL/Cypher WHERE clause builders
search.py 361 Keyword, fulltext, embedding search
traversal.py 432 Neighbors, subgraph, paths
queries.py 658 Metadata queries, counts
maintenance.py 769 Import/export, clear, cleanup
helpers.py 14 Standalone utility functions

Import path unchanged

from memos.graph_dbs.polardb import PolarDBGraphDB  # works as before

Test plan

  • All 31 BaseGraphDB abstract methods implemented in PolarDB (verified via AST)
  • No cross-mixin import violations (mixins use self. for cross-calls)
  • Existing test suite passes across all backends
  • PolarDB search operations work end-to-end

🤖 Generated with Claude Code

@anatolykoptev anatolykoptev force-pushed the refactor/polardb-decomposition branch 2 times, most recently from 26216e3 to 3c85b6a Compare February 7, 2026 06:57
@anatolykoptev anatolykoptev changed the title feat: PolarDB + PostgreSQL graph backends with decomposed architecture feat: PolarDB graph backend with decomposed mixin architecture Feb 7, 2026
@anatolykoptev anatolykoptev force-pushed the refactor/polardb-decomposition branch from 3c85b6a to 6d418fa Compare February 7, 2026 07:02
Major graph_dbs module overhaul:

1. PolarDB backend (polardb/) — decomposed into mixin-based package:
   - connection.py: pool management with health checks and retries
   - schema.py: AGE extensions, tables, indexes
   - nodes.py: node CRUD + agtype parsing
   - edges.py: edge CRUD
   - filters.py: dual SQL/Cypher WHERE clause builders
   - search.py: keyword, fulltext, embedding search
   - traversal.py: neighbors, subgraph, paths
   - queries.py: metadata queries, counts
   - maintenance.py: import/export, clear, cleanup

2. Shared utilities (utils.py) — compose_node, prepare_node_metadata,
   convert_to_vector, detect_embedding_field, clean_properties

3. BaseGraphDB extended with additional abstract methods:
   get_edges, search_by_fulltext, get_neighbors_by_tag,
   delete_node_by_prams, get_user_names_by_memory_ids,
   exist_user_name, search_by_keywords_like, search_by_keywords_tfidf

4. Neo4j/Neo4j Community/Nebula backends updated to implement
   new abstract methods

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@anatolykoptev anatolykoptev force-pushed the refactor/polardb-decomposition branch from 6d418fa to 451fa74 Compare February 7, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant