Knotrel Docs

Choosing an engine

Knotrel answers the same exact connectivity questions with four engines. They differ only in speed, memory and the operations they make cheap. This page is the canonical guide for choosing one. Keep the default, compact-bfs, unless measurements on your own workload show a reason to change.

Which version you need. All four engines are in the latest release, v1.2.0 (see Getting the latest release). cluster-forest is new in 1.1.0. The v1.0.0 server refuses KNOTREL_ENGINE=cluster-forest at startup (“must be compact-bfs, ett or hdt”), and knotrel-core 1.0 has no EngineConfig::ClusterForest.

At a glance

Engine Status In v1.0.0 Lifecycle Consider it for
compact-bfs Default, stable Yes Yes General and update-heavy workloads; lowest memory
ett Experimental engine Yes No Query-heavy work on tree-like graphs
hdt Experimental engine Yes No Dense graphs with frequent bridge cuts
cluster-forest Experimental engine No: new in 1.1.0 Yes Query-heavy work where compact-bfs searches; dense bridge churn; see when to try it

How to select each engine:

Engine Library (knotrel-core) Server (knotrel-server)
compact-bfs EngineConfig::CompactBfs (the default) KNOTREL_ENGINE unset or compact-bfs
ett EngineConfig::EulerTour KNOTREL_ENGINE=ett
hdt EngineConfig::Hdt KNOTREL_ENGINE=hdt
cluster-forest EngineConfig::ClusterForest; with lifecycle, LifecycleGraph::new(EngineConfig::ClusterForest) KNOTREL_ENGINE=cluster-forest; with lifecycle, also KNOTREL_TOPOLOGY_LIFECYCLE=true

“Experimental engine” means a stable interface with an experimental engine: the selector, the enum variant and the API stay compatible across 1.x, while performance, maturity and the usage recommendation carry no promise (compatibility policy). The asymptotic costs of every engine are in the “Choosing a Backend Engine” section of the knotrel-core crate documentation, on docs.rs.

How cluster-forest works

cluster-forest is a sequential cluster forest after Wulff-Nilsen (SODA 2013, §3) with the path compression of De Man et al. (PVLDB 2025, §4) (ADR 0014):

When to try cluster-forest

The advice below comes from the v1.1.0 CF5 qualification: cluster-forest compared with compact-bfs, ETT and HDT on candidate 02cba68, on one host (Apple M3, 16 GB, macOS), with the classes computed by the campaign analyzer. Every statement holds only for the workloads, sizes, host and build measured. v1.2.0 made compact-bfs connected queries much faster on most graphs (v1.2.0 release notes); the engine comparison was not repeated on 1.2.0, so it understates compact-bfs on query-heavy workloads. Measure on your own workload before switching. Results and limitations: engine comparison page · full report.

Try it when:

Keep compact-bfs, ETT or HDT when:

Measure first on staged random insert and delete workloads (K2, mixed results against every engine), and against ETT and HDT on the server, where results were equivalent except one configuration (mixed50-b64-c16, about 30 % slower).

Known limitations from CF5:

Library and server: what each offers

Capability Library (knotrel-core) Server (knotrel-server)
Select the engine ConnectivityGraph::new(EngineConfig::ClusterForest), with_limits, try_from_edges KNOTREL_ENGINE=cluster-forest at startup; reported by GET /v1/info ("engine": "cluster-forest", "experimental": true)
Add nodes, link, cut, query Yes Yes: /v1/operations, /v1/batch, feeder events and imports
Node and edge lifecycle (activate, enable, remove) Yes: LifecycleGraph::new(EngineConfig::ClusterForest) Yes: KNOTREL_TOPOLOGY_LIFECYCLE=true
Neighbor listing Only through LifecycleGraph::incident_after; ConnectivityGraph::enable_neighbor_listing returns false and as_compact returns None Node listing and detail always; incident and edge listing (KNOTREL_INSPECTION=true) only with lifecycle support, otherwise 409 inspection_unsupported
Bulk listing of every node and edge Yes, on every engine (Experimental, new in 1.3): ConnectivityGraph::for_each_node / for_each_edge, and LifecycleGraph::for_each_node / for_each_edge with flags Used by snapshots (ADR 0016)
Engine statistics None: the backend type is internal None beyond the common stats
Switch engine at runtime Build a new graph No: restart with another KNOTREL_ENGINE; the in-memory graph is lost and must be rebuilt or re-imported

The engine never changes answers: every engine returns the same exact results for the same operations.

Examples

Library

Plain connectivity:

use knotrel_core::{ConnectivityGraph, EngineConfig, GraphError};

fn main() -> Result<(), GraphError> {
    let mut graph = ConnectivityGraph::new(EngineConfig::ClusterForest);
    graph.link(1, 2)?;
    graph.link(2, 3)?;
    assert!(graph.connected(1, 3)?);
    graph.cut(2, 3)?;
    assert!(!graph.connected(1, 3)?);
    assert!(graph.engine().is_experimental());
    Ok(())
}

Node and edge lifecycle: take a node offline and restore it without recreating its edges.

use knotrel_core::{EngineConfig, LifecycleGraph};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut graph = LifecycleGraph::new(EngineConfig::ClusterForest)?;
    for (u, v) in [(1, 2), (2, 4), (1, 3), (3, 4)] {
        graph.link(u, v)?;
    }
    graph.set_node_active(2, false)?;
    assert!(graph.connected(1, 4)?); // through 3
    graph.set_node_active(3, false)?;
    assert!(!graph.connected(1, 4)?);
    graph.set_node_active(2, true)?;
    assert!(graph.connected(1, 4)?); // the edges of 2 are back
    Ok(())
}

The same two examples are doctests of the knotrel-core crate documentation (section “Choosing a Backend Engine”), run by cargo test --doc -p knotrel-core.

Server

Plain mode:

KNOTREL_ENGINE=cluster-forest ./target/release/knotrel-server
curl -s http://127.0.0.1:8080/v1/info
# {"engine":"cluster-forest","experimental":true,...}
curl -s -H 'Content-Type: application/json' -d '{"operations":[
  {"op":"link","source":"1","target":"2"},
  {"op":"link","source":"2","target":"3"},
  {"op":"connected","source":"1","target":"3"}]}' http://127.0.0.1:8080/v1/batch
# {"results":[{"result":"changed","changed":true},{"result":"changed","changed":true},{"result":"connected","connected":true}]}

With node and edge lifecycle:

KNOTREL_ENGINE=cluster-forest KNOTREL_TOPOLOGY_LIFECYCLE=true ./target/release/knotrel-server
curl -s -H 'Content-Type: application/json' -d '{"operations":[
  {"op":"link","source":"1","target":"2"},{"op":"link","source":"2","target":"4"},
  {"op":"link","source":"1","target":"3"},{"op":"link","source":"3","target":"4"},
  {"op":"set_node_active","node":"2","active":false},
  {"op":"connected","source":"1","target":"4"}]}' http://127.0.0.1:8080/v1/batch
# the last result is {"result":"connected","connected":true}: node 3 still connects 1 and 4

Without KNOTREL_TOPOLOGY_LIFECYCLE=true, lifecycle operations answer 409 topology_lifecycle_disabled. With ett or hdt, lifecycle support makes startup fail: KNOTREL_TOPOLOGY_LIFECYCLE requires KNOTREL_ENGINE=compact-bfs or cluster-forest.

Going back to compact-bfs

Getting the latest release

cluster-forest needs 1.1.0 or later. With v1.0.0 (server or knotrel-core 1.0), use the selectors in the first three rows of the table only.

See also