Introducing a new way to review your PRs.

Read the announcement

helixdb / helix-db

HelixDB is an OLTP graph database with native vector and full-text search built in Rust on Object Storage.

View on GitHub

27 documents · Updated Nov 23, 2026

docs / graph-computation-and-value-semantics

Graph computation and value semantics

Graph algorithms and query execution rely on shared contracts for identity, topology, numeric values, ordering, and result shape. These contracts turn database data into a validated immutable graph and let the planner and database make the same decisions about values before and during execution.

Shared computation model

The graph computation model separates data access from local analysis. A graph query response is checked at a boundary, then becomes an immutable graph that algorithms can reuse without another storage read. Query values follow a similar path: request values become typed AST values, the planner uses them to prove access and ordering rules, and the database converts them into runtime values for evaluation.

flowchart LR
    S[Database graph data] --> R[Graph response]
    R --> V[Validated immutable graph]
    V --> A[Graph algorithms]
    Q[Query parameters and literals] --> P[Planner value rules]
    Q --> D[Database runtime values]
    P --> X[Executable plan]
    X --> D
    D --> O[Ordered and shaped results]

This split gives each layer a clear role. Storage and query transport provide data. The graph layer checks graph-wide invariants. The planner checks which values can support an access path. The database evaluates the approved plan while preserving value and result contracts.

References: crates/…/lib.rs• L1-6 crates/…/loader.rs• L1-5 crates/…/lib.rs• L1-5 crates/…/values.rs• L1-16

Immutable graph model

The shared graph model is a validated, immutable view of nodes and edges. It records the declared topology as a directed or undirected simple graph or as a graph that permits parallel edges. It also keeps stable identities, labels, selected attributes, and optional non-negative edge weights for later algorithms.

Graph construction rejects duplicate identities, missing endpoints, invalid weights, and parallel edges that the declared graph kind does not permit. Records and adjacency are placed in deterministic identity order. This means two algorithms that read the same graph see the same node and edge order.

References: crates/…/model.rs• L168-192 crates/…/model.rs• L398-416 crates/…/model.rs• L427-545

Identity model

An external identity is the value used by graph callers to name a node or an edge-related key. The identity model preserves type, so values such as integer 1, string "1", and boolean true remain distinct. It also supports lossless compound identities such as tuples and frozen sets through a canonical tagged form.

Identity selection is explicit. A graph may use its internal node ID, a scalar property, or a tagged property. The loader applies that choice to every node and rejects duplicate external identities before graph construction. This prevents a property conversion from silently merging different graph nodes.

References: crates/…/identity.rs• L13-26 crates/…/identity.rs• L69-91 crates/…/identity.rs• L155-175 crates/…/identity.rs• L322-360 crates/…/loader.rs• L140-170

Topology transformations

Graph transformations create another immutable view without changing the source graph. They support changes needed by algorithms or callers while preserving attributes and stable edge identity where possible.

TransformationContract
Directed viewAdds structural reverse edges for non-loop edges and gives each reverse a collision-free generated identity.
Undirected viewPreserves stored edges and promotes a simple view to a multigraph view when opposite directed edges would become parallel.
Induced subgraphKeeps selected nodes and only edges whose two endpoints are selected.
RelabelReplaces node identities and rewires endpoints. It rejects mappings that merge distinct nodes.
ComposeMerges equal-kind graphs. Right-side attributes take precedence, while conflicting endpoints for one edge identity are rejected.

These transformations matter because an algorithm must not infer topology from a partial or ambiguous view. For example, community algorithms require an explicit undirected graph view, while directed traversal uses stored orientation unless the caller asks for another direction.

References: crates/…/transform.rs• L5-16 crates/…/transform.rs• L66-98 crates/…/transform.rs• L100-165 crates/…/transform.rs• L168-235 crates/…/louvain.rs• L352-359

Graph algorithm behavior

Graph algorithms run against the same immutable graph view and return stable records instead of exposing storage internals. Their shared behavior includes deterministic traversal order, explicit direction, bounded work where needed, and result states that distinguish missing data from a valid empty result.

The algorithm family includes traversal and neighborhood queries, shortest paths, degree and centrality scores, cycle enumeration, layouts, and community detection. The child page Graph algorithms describes these APIs and their individual contracts.

References: crates/…/mod.rs• L1-16 crates/…/traversal.rs• L7-16 crates/…/traversal.rs• L125-143 crates/…/cycles.rs• L9-34

Deterministic graph results

Determinism is a shared output contract. The graph model sorts records and adjacency by external node identity and then by edge key and stable edge identity. Algorithms use that order for discovery, neighbor lists, path edges, cycles, communities, and score records. Seeded modes use an explicit seed so repeated runs with the same graph and options return the same result.

Determinism does not mean every algorithm returns the same kind of result. A traversal reports discovery order and depth. A shortest path reports MissingSource, MissingTarget, NoPath, or a found node and edge sequence. A cycle result reports whether an output cap truncated enumeration. These states keep “no result” separate from “the input was not present” and from “the result is incomplete.”

References: crates/…/model.rs• L515-531 crates/…/traversal.rs• L195-214 crates/…/traversal.rs• L374-419 crates/…/cycles.rs• L28-40 crates/…/centrality.rs• L333-352

Algorithm input contracts

Algorithm options state the limits and assumptions that affect meaning. Traversals select seeds, depth, direction, labels, and optional hub expansion. Weighted algorithms use selected edge weights and treat an absent weight as one. Community algorithms require undirected topology and use bounded levels or trials. Layouts use finite settings and a deterministic seed.

The contracts fail early when an option cannot produce a valid result. Examples include an empty traversal seed set, an unknown node, a non-finite layout position, or a zero edge weight in weighted betweenness. This makes a rejected computation different from a valid computation over an empty or disconnected graph.

References: crates/…/traversal.rs• L42-84 crates/…/centrality.rs• L34-79 crates/…/centrality.rs• L237-249 crates/…/layout.rs• L8-22 crates/…/louvain.rs• L8-29

Query value model

PropertyValue is the common value vocabulary for stored properties, literals, and parameters. It represents null, booleans, signed integers, datetimes, two float widths, strings, bytes, typed arrays, nested arrays, and objects. QueryValue is the JSON-compatible vocabulary used for query parameters, and the database converts both query values and AST property values into its runtime value form without changing their nested shape.

The conversion boundary is structural rather than textual. A nested array remains an array and an object remains an object. A datetime remains a datetime in property values, while query parameter rules accept a valid RFC3339 string for a declared datetime parameter. Bytes are valid property data but are rejected when the query JSON route cannot represent them safely.

References: crates/…/value.rs• L7-44 crates/…/query.rs• L44-84 crates/…/conversion.rs• L8-53

Numeric semantics

Numeric comparison is shared through CanonicalNumber, which represents integers and floats without first rounding an integer through a float. It treats signed zero as one numeric zero and rejects NaN as an orderable number. Infinities have an explicit place in the numeric order when the source value permits them, while query input validation rejects non-finite JSON float parameters.

This rule protects planner proofs and runtime access decisions at large integer boundaries. Range index literals accept integers, datetimes, non-NaN floats, and strings. Numeric integer and float literals can compare across numeric widths, but datetimes remain a separate ordered type and do not compare as numbers.

References: crates/…/lib.rs• L49-76 crates/…/lib.rs• L78-109 crates/…/lib.rs• L155-176 crates/…/value.rs• L47-61 crates/…/value.rs• L183-200 crates/…/value.rs• L203-241

Planner value rules

The planner uses value semantics to decide whether a literal or parameter can support an index access. Equality access can use values allowed by secondary index storage. Range access needs an ordered scalar literal or a runtime parameter whose value will be checked later. Literal collections are used for finite membership reasoning only when their values have reflexive equality, which excludes NaN and nested non-reflexive values.

These rules keep an optimization equivalent to execution. The planner does not treat every property value as orderable or as a safe set member. It also removes duplicate members from eligible literal collections so a finite lookup represents membership rather than repeated input entries.

References: crates/…/values.rs• L7-24 crates/…/values.rs• L26-67 crates/…/values.rs• L69-109 crates/…/value.rs• L10-15

Runtime ordering

Database ordering applies the same value comparison to explicit sort keys and then uses row order as a stable tie break. A missing sort value is lower than a present value for ascending order. Descending order reverses the value comparison, while equal keys still use the row comparison so the result order remains stable.

When a range index already provides the requested order, execution keeps the access order rather than sorting the rows again. This is safe only because the planner and the index contract agree that the range key is orderable under the same value rules.

References: crates/…/order.rs• L7-31 crates/…/order.rs• L35-55

Query result shape

Query execution carries both data and shape. A stream, folded stream, count, boolean, scalar list, and operation receipt have different meanings even when they contain the same number of items. Returned values preserve that distinction so an empty collection is serialized as [] while an absent at-most-one object is serialized as null.

Rows also carry traversal path, bindings, runtime-only properties, and optional sack state. These values belong to execution state until a projection makes them visible. This lets operators pass row context through a plan without confusing internal state with stored graph properties.

References: crates/…/types.rs• L63-80 crates/…/types.rs• L324-355 crates/…/types.rs• L548-557

Parameter contracts

Query parameters may be untyped JSON-compatible values or values checked against a declared type. A request must use one mode, parameter names must be unique and non-empty, and typed names must match value names. Typed numeric parameters may use the documented widening or narrowing conversions when the result stays valid; arrays apply the same rule to each member.

The request boundary rejects non-finite floats, unsupported bytes, invalid datetime strings, wrong object or array shapes, and schema/value name mismatches. This gives the planner and database a closed set of parameter values instead of making each execution operator repeat wire validation.

References: crates/…/query.rs• L8-32 crates/…/query.rs• L88-126 crates/…/query.rs• L486-526 crates/…/query.rs• L546-627

Change checklist

When these files or sections are changed, remember to consider these:

  • If an identity representation changes, review graph loader decoding, binding serialization, node lookup, and all SDK-facing graph result records together.
  • If graph topology or edge identity rules change, review directed and undirected transformations, multigraph validation, traversal direction, cycle canonicalization, and edge score mapping.
  • If numeric comparison changes, review CanonicalNumber, range index literals, planner literal collection checks, runtime sort comparison, and index-provided ordering as one contract.
  • If a query value variant or conversion rule changes, review AST serialization, typed parameter normalization, database conversion, expression evaluation, and response serialization.
  • If result shape changes, review planner return inference and the distinction between empty lists and absent at-most-one values.

Important failure modes

TriggerConsequenceGuard
A graph response contains duplicate external node identitiesDistinct stored nodes can collapse into one algorithm nodeLoader rejects the response before graph construction.
An edge points to a node outside the selected node setAn algorithm could read incomplete topologyLoader rejects the edge row as invalid.
A simple graph receives parallel endpoint pairsAlgorithms could apply the wrong topology contractGraph construction rejects the graph kind mismatch.
An identity uses a non-canonical compound encodingLookups or serialized results can disagree about identityTagged identity decoding validates the envelope, order, uniqueness, depth, and size.
A range bound is a boolean, collection, object, or NaN floatThe planner cannot prove an ordered index accessRange literal construction accepts only ordered scalar types.
A query contains a non-finite float or unsupported bytes parameterThe JSON request cannot carry a safe valueQuery validation rejects the parameter at the request boundary.
Explicit sort keys compare equalResult order could vary between runsRuntime ordering uses the row as a final stable tie break.
Weighted betweenness sees a zero-weight edgeShortest-path centrality assumptions do not holdCentrality validation rejects weighted mode for zero weights.

Key files

FileWhy to read it
crates/…/model.rsDefines the validated immutable graph and topology contract used by every native algorithm.
crates/…/loader.rsShows the boundary that turns query response rows into a complete graph.
crates/…/identity.rsDefines lossless external identity and identity selection rules.
crates/…/transform.rsExplains how graph views change without mutating source data.
crates/…/traversal.rsShows direction, deterministic discovery, shortest-path states, and neighborhood behavior.
crates/…/centrality.rsShows weighted versus unweighted path assumptions and seeded sampling.
crates/…/lib.rsDefines exact cross-type numeric equality and ordering shared by planner logic.
crates/…/value.rsDefines the property value vocabulary used by queries and stored data.
crates/…/query.rsDefines query parameter shapes, validation, normalization, and wire contracts.
crates/…/values.rsShows which values are safe for planner equality and finite-collection reasoning.
crates/…/value.rsDefines orderable range index literals and their numeric comparison.
crates/…/conversion.rsShows conversion from AST and query values into runtime values.
crates/…/order.rsShows runtime sort behavior and use of index-provided order.
crates/…/types.rsDefines execution row context, value shapes, and return normalization.