Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Neuml Txtai RDBMS Graph

From Leeroopedia


Knowledge Sources
Domains Graph Networks, Database Persistence, Relational Databases
Last Updated 2026-02-10 01:00 GMT

Overview

Concrete tool for database-backed graph persistence using the Grand library provided by txtai.

Description

The RDBMS class extends NetworkX to provide graph persistence backed by a relational database. It uses the Grand library's SQLBackend with an InMemoryCachedBackend for performance, combined with SQLAlchemy for database connectivity. The class stores graph nodes and edges in configurable database tables while exposing a NetworkX-compatible interface through Grand's nx property. It supports PostgreSQL schemas, configurable table names for nodes and edges, and connection URL configuration via either the config dictionary or the GRAPH_URL environment variable. On creation, the class clears previous graph data from the target tables. The save method commits the database transaction, and load reconnects to an existing database-backed graph. Subgraph filtering delegates to a plain NetworkX graph to avoid database overhead for temporary results.

Usage

Use RDBMS when graph data needs to persist beyond memory in a relational database such as PostgreSQL or SQLite. This is appropriate for production deployments where graph data must survive process restarts, be shared across multiple services, or be backed by enterprise-grade storage. It provides the same API as the in-memory NetworkX graph, making it a drop-in replacement with added durability.

Code Reference

Source Location

  • Repository: Neuml_Txtai
  • File: src/python/txtai/graph/rdbms.py

Signature

class RDBMS(NetworkX):
    def __init__(self, config)
    def __del__(self)
    def create(self)
    def scan(self, attribute=None, data=False)
    def load(self, path)
    def save(self, path)
    def close(self)
    def filter(self, nodes, graph=None)
    def connect(self)

Import

from txtai.graph.rdbms import RDBMS

I/O Contract

Inputs

Name Type Required Description
config dict Yes Graph configuration dictionary. In addition to base Graph config keys, supports: url (database connection URL, falls back to GRAPH_URL environment variable), schema (PostgreSQL schema name, auto-created if not existing), nodes (node table name, default "nodes"), edges (edge table name, default "edges").
path str Yes (for load/save) Path parameter required by interface but not used for filesystem storage. The save method commits the database transaction; load reconnects to the database.
nodes list Yes (for filter) Node ids or (id, score) tuples for subgraph filtering. Filtering creates a plain NetworkX graph to avoid database overhead.

Outputs

Name Type Description
create() nx.Graph A NetworkX-compatible graph view backed by Grand's SQLBackend with in-memory caching.
connect() tuple A 2-tuple of (Grand Graph instance, SQLAlchemy database connection).
scan() iterator Node iterator; when filtering by attribute, yields nodes (or node-data tuples) by iterating and checking attributes directly rather than using NetworkX subgraph views.
filter() NetworkX Returns a plain in-memory NetworkX subgraph (not database-backed) for filtered results.

Usage Examples

from txtai.graph.rdbms import RDBMS

# Create a database-backed graph with PostgreSQL
config = {
    "url": "postgresql://user:pass@localhost/graphdb",
    "schema": "mygraph",
    "nodes": "graph_nodes",
    "edges": "graph_edges",
    "topics": {
        "algorithm": "louvain"
    }
}

graph = RDBMS(config)
graph.initialize()

# Insert documents - same API as NetworkX
documents = [
    ("doc1", "Machine learning concepts", None),
    ("doc2", "Neural network architectures", None),
]
graph.insert(documents)

# Save commits to database
graph.save("/path/ignored")

# Reload from database
graph2 = RDBMS(config)
graph2.load("/path/ignored")

# Close cleans up database connection
graph.close()

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment