Skip to content

Library

Top level Functions

SDK

Model

Builders

Performance Optimization

NetworkX Backends (GraphQL & Analysis)

Graphinate leverages NetworkX for graph data structures and algorithms. For large graphs, standard Python execution of graph algorithms (like centrality, diameter, etc.) can be slow.

The GraphQLBuilder exposes many of these algorithms as fields (e.g., measure(measure: radius)). To significantly speed up these calculations, you can install a high-performance NetworkX backend.

For more details, see the official NetworkX Backends documentation.

Recommended Backend: graphblas-algorithms

  1. Install:

    pip install graphblas-algorithms
    

  2. Enable: Set the environment variable before running your application:

    export NETWORKX_BACKEND_PRIORITY=graphblas
    
    Or configure it programmatically:
    import networkx as nx
    nx.config.backend_priority = ["graphblas"]
    

Pros: * Speed: Orders of magnitude faster for complex algorithms (e.g., PageRank, Betweenness Centrality) on large graphs. * Parallelism: Some backends support multi-threading or GPU acceleration.

Cons/Disclaimers: * Overhead: There is a conversion cost to move data from the standard NetworkX graph to the backend's internal representation. For small graphs or simple queries, this might actually be slower. * Compatibility: Not all NetworkX algorithms are implemented in every backend. NetworkX will seamlessly fall back to the default Python implementation if a backend doesn't support a specific algorithm.

Modeling Concepts

Dependency Injection and Parameter Naming

When defining node generators using @model.node, you can request context from parent nodes by adding arguments to your generator function.

Strict Naming Convention: To receive the ID of a parent node, your argument name must follow this pattern: {node_type}_id.

For example, if you have a node type user, a child node generator can request user_id.

1
2
3
4
@model.node(parent_type='user')
def get_posts(user_id):
    # user_id is automatically injected
    ...

Note: Arbitrary arguments are not currently supported. All arguments must match a registered node type followed by _id.

Examples

See the following examples for practical usage of this pattern: