Skip to main content
This page describes how to integrate FalkorDB with PyTorch Geometric (PyG) using the falkordb-pyg package.

Overview

falkordb-pyg implements PyG’s Remote Backend interface (FeatureStore + GraphStore) for FalkorDB. Once connected, you can plug the backend directly into NeighborLoader, LinkNeighborLoader, and other standard PyG data loaders — no changes to your model or training code required. Key features:
  • Zero-copy lazy loading — features and topology are fetched on demand and cached locally
  • Heterogeneous graph support — multiple node and edge types
  • Automatic ID remapping — non-contiguous FalkorDB node IDs are mapped to contiguous PyG indices transparently
  • Drop-in replacement — works with any PyG workflow that accepts a remote backend

Installation

Prerequisite: PyTorch and PyTorch Geometric must be installed first. Follow the PyTorch and PyG installation guides for your platform and CUDA version.
Or install with PyTorch and PyG included (CPU-only defaults):
Requires: Python ≥ 3.10, PyTorch ≥ 2.0, PyTorch Geometric ≥ 2.4, FalkorDB Python client ≥ 1.0.

Quick Start

1. Start FalkorDB

2. Load data into FalkorDB

3. Create the remote backend

4. Use with NeighborLoader

API Reference

get_remote_backend

Returns a (FalkorDBFeatureStore, FalkorDBGraphStore) tuple.

FalkorDBFeatureStore

Implements torch_geometric.data.FeatureStore. Constructor:

FalkorDBGraphStore

Implements torch_geometric.data.GraphStore. Constructor:

NodeIDMapper

Bidirectional mapping between FalkorDB internal node IDs and contiguous 0-based PyG indices.

Node ID Remapping

FalkorDB assigns internal integer IDs to nodes that may not be contiguous or start at zero. falkordb-pyg transparently builds a NodeIDMapper for each node type on first access, converting FalkorDB IDs to contiguous PyG indices. Edges referencing IDs not present in the mapper are silently dropped.

Example: Training GraphSAGE

See examples/train_example.py for a complete GraphSAGE training script that:
  1. Populates FalkorDB with a synthetic paper-citation graph
  2. Creates a remote backend with get_remote_backend
  3. Fetches features and edge indices lazily
  4. Trains a two-layer GraphSAGE classifier

Reference

Frequently Asked Questions

It enables you to train Graph Neural Networks (GNNs) directly on graphs stored in FalkorDB using PyTorch Geometric’s remote backend interface, without exporting data to files first.
You need Python >= 3.10, PyTorch >= 2.0, PyTorch Geometric >= 2.4, and FalkorDB Python client >= 1.0. Install with pip install falkordb-pyg or pip install 'falkordb-pyg[torch]' for bundled PyTorch.
Yes, it fully supports heterogeneous graphs with multiple node and edge types. Use the node_type_to_label and edge_type_to_rel parameters in get_remote_backend to map PyG types to FalkorDB labels.
FalkorDB assigns internal integer IDs that may not be contiguous. The NodeIDMapper automatically builds a bidirectional mapping between FalkorDB IDs and contiguous 0-based PyG indices on first access.
Yes, the remote backend works as a drop-in replacement with NeighborLoader, LinkNeighborLoader, and any other PyG data loader that accepts a (FeatureStore, GraphStore) tuple.