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 / uniffi-bindings

UniFFI bindings

The UniFFI bindings form the foreign-function interface between the Rust HelixDB core and language SDKs. They expose embedded database access, reusable graph data, graph algorithms, and stable error types so Python, Node.js, and Go callers can use core HelixDB behavior without reimplementing it.

For the wider SDK model, see Client SDKs and bindings. The Rust SDK and DSL page explains the Rust-facing query model, while Language client SDKs explains the language-level clients that consume this boundary.

Binding boundary

Foreign-language interface

The binding crate at bindings/…/lib.rs is the public boundary for foreign code. UniFFI turns its exported objects, records, enums, and errors into language-native APIs while the Rust core remains responsible for database and graph behavior.

The boundary keeps values portable. Database handles and graph handles are shared objects. Request and result data crosses the boundary as byte arrays or simple records. JSON remains the common format for query bodies, query responses, and node or edge attributes.

References: bindings/…/lib.rs• L3-12 bindings/…/Cargo.toml• L6-25

Generated binding artifacts

Binding generation

The compiled UniFFI library is the source for generated language bindings. The standard generator supports Python through the binding crate. Dedicated generator tools produce the Node.js and Go forms used by their embedded SDK adapters.

The generation flow keeps one Rust API contract across languages:

flowchart LR
    RustAPI[Exported Rust API] --> NativeLib[UniFFI native library]
    NativeLib --> Python[Python binding module]
    NativeLib --> Node[Node.js binding module]
    NativeLib --> Go[Go binding package]
    Python --> PythonSDK[Python embedded client]
    Node --> NodeSDK[Node.js embedded client]
    Go --> GoSDK[Go embedded client]

The package names are set in bindings/…/uniffi.toml. The generated modules are runtime inputs for the SDKs, not separate implementations of database behavior. Cross-language parity checks build the native library, generate these artifacts, and compare embedded behavior across Rust, TypeScript, Go, and Python.

References: bindings/…/uniffi.toml• L1-8 bindings/…/uniffi_bindgen.rs• L1-3 bindings/…/Cargo.toml• L7-25 sdks/…/run-embedded-parity.ts• L49-145

Embedded database access

Embedded database handles

The HelixDB binding provides an in-process database handle. Callers choose an in-memory source, a local disk source, or an S3-compatible object source. They can open a read/write handle or a read-only handle, optionally with a portable cache profile.

Once open, the handle accepts SDK-built query bytes and returns query result bytes. It also has a graph path that runs one ordinary read request and turns the response into a reusable native graph. Closing the handle releases the storage resource.

sequenceDiagram
    participant SDK as Language SDK
    participant Binding as UniFFI handle
    participant Core as Rust database core
    participant Store as Storage source

    SDK->>Binding: open source and cache profile
    Binding->>Core: create embedded handle
    Core->>Store: open database
    SDK->>Binding: query JSON or load graph
    Binding->>Core: execute request
    Core-->>Binding: response or graph data
    Binding-->>SDK: result or stable error
    SDK->>Binding: close
    Binding->>Core: close storage handle

Cache profiles provide a small cross-language choice set: vector-memory-only, memory cache, or hybrid memory and disk cache. The binding validates the profile before it reaches the database core, so invalid budgets and paths fail as configuration errors.

References: bindings/…/helix_db.rs• L14-36 bindings/…/helix_db.rs• L106-121 bindings/…/helix_db.rs• L148-232

Dedicated async runtime

The binding owns a multi-thread Tokio runtime for database futures. This keeps long-running database work on owned worker threads instead of making a foreign callback thread poll the full Rust future and its stack.

The runtime is created once for the process. Its worker count uses HELIX_UNIFFI_RUNTIME_THREADS when that value is a positive integer. Otherwise it uses the available CPU count with a fixed fallback when that count cannot be read.

References: bindings/…/runtime.rs• L1-48 bindings/…/helix_db.rs• L162-231

Graph adapter

Graph loading contract

The graph adapter converts one normal HelixDB read response into an immutable graph object. A graph selection defines the node and edge rows, graph kind, identity form, optional edge key and weight, selected attributes, and result limits before the query runs.

The adapter validates the response against that contract. It rejects incomplete selections, duplicate external identities, invalid topology, and non-canonical identifiers. This protects graph algorithms from ambiguous or partial input.

The returned graph keeps topology in the Rust graph core. Node and edge attributes cross the boundary as JSON bytes and become language-native maps in the SDK adapters. External node identities use a canonical tagged JSON form. Structural edge identities preserve both stored edges and generated reverse edges.

References: bindings/…/graph.rs• L100-181 bindings/…/graph.rs• L513-582 sdks/…/graph.ts• L18-105 sdks/…/graph.py• L121-220

Graph operations

The native graph exposes a common set of read and analysis capabilities. Synchronous calls serve direct native clients. Async algorithm calls move blocking work to the binding runtime for event-loop based clients.

CapabilityPurpose
Topology accessRead counts, graph shape, nodes, edges, labels, weights, and attributes.
Neighborhood accessFind neighbors, predecessors, successors, incident edges, and edges between two nodes.
Traversal and pathsRun bounded BFS or DFS, inspect discovery edges, and find a shortest path with direction and label limits.
Graph analysisCompute degree, betweenness, bounded cycles, Louvain communities, Leiden communities, and spring-layout positions.
Graph transformsCreate copies, induced subgraphs, directed or undirected views, composed graphs, and relabeled graphs.

Graph results report meaningful state instead of hiding it. For example, a shortest path can report a missing source, a missing target, no path, or a found path. A cycle result reports when an output cap truncated the result.

References: bindings/…/graph.rs• L398-511 bindings/…/graph.rs• L584-1065 sdks/…/graph.ts• L177-355

Error translation

Stable error vocabulary

The HelixError type reduces detailed Rust database failures to six categories that foreign callers can handle without depending on Rust-only error payloads. Each error keeps a machine-readable code and a diagnostic message.

CategoryCaller meaning
InvalidConfigThe embedded setup or index configuration is not valid.
InvalidRequestThe request or API use is not valid and should be corrected.
PlannerQuery planning failed.
StorageStorage or database state failed.
TransactionA conflict or stale view may require transaction retry logic.
InternalThe failure indicates a core invariant, runtime task, or stored-data problem.

The mapping keeps caller-correctable input errors separate from internal data and lifecycle failures. A failed binding-runtime task becomes an internal error rather than unwinding across the foreign-function boundary.

Graph loading uses its own NativeGraphError vocabulary because graph response validation and graph algorithm options have different caller actions from database request failures. SDK adapters then map generated errors into their language-specific client error types while preserving the code and message.

References: bindings/…/error.rs• L1-40 bindings/…/error.rs• L42-139 bindings/…/graph.rs• L10-37 sdks/…/embedded_uniffi.go.tmpl• L92-121 sdks/…/_client_common.py• L83-119

Change checklist

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

  • Update the UniFFI exports, generated-language support, and SDK adapter calls together when an exported object, record, enum, or error changes.
  • Keep uniffi.toml package names aligned with the module names expected by the Python, Node.js, and Go loaders.
  • Preserve canonical external node and structural edge identity rules across Rust encoding and every language decoder.
  • Keep graph selection fields aligned with the projection sent by each SDK and with the response validation contract in the native loader.
  • Recheck async graph methods when changing runtime ownership or blocking behavior. Event-loop clients depend on work staying off their callback threads.
  • Preserve the six HelixError categories and their retry meaning when new core error variants are added.

Important failure modes

TriggerConsequenceGuard
A generated native module is missing or lacks a required export.Embedded graph or database access cannot start in that language.The SDK loader checks the native module and reports an embedded-bindings-unavailable error.
A graph response exceeds a configured node or edge limit.Graph construction fails instead of returning a partial graph.The loader reports IncompleteSelection; request limits must allow a complete selection.
A response contains duplicate external identities or invalid topology.Graph algorithms cannot use a unique node or edge model.Graph loading rejects the response with a graph validation error.
A caller sends a non-canonical identity or structural edge ID.The lookup or graph transform fails at the binding boundary.Encode IDs with the binding contract and preserve canonical bytes.
A foreign caller runs a blocking graph algorithm on its event loop.The host event loop can stall.Use the async graph methods, which run work on the dedicated binding runtime.
A transaction view becomes stale or a transaction conflicts.The operation fails with a retryable transaction category.Treat Transaction errors as retry signals rather than storage corruption.

Key files

FileWhy to read it
bindings/…/lib.rsShows the public UniFFI export surface.
bindings/…/helix_db.rsDefines embedded sources, cache profiles, database handles, query access, and graph loading.
bindings/…/graph.rsDefines the graph data contract, graph operations, async adapters, and graph errors.
bindings/…/runtime.rsExplains the runtime that owns database futures for foreign callers.
bindings/…/error.rsDefines the stable error categories and their mapping from core failures.
bindings/…/uniffi.tomlDefines generated package names for Go, Node.js, and Python.
bindings/…/go.rsConnects the shared UniFFI API to Go binding generation.
bindings/…/node.rsConnects the shared UniFFI API to Node.js binding generation.
sdks/…/graph.tsShows the Node.js-facing graph loading and native graph adapter contract.
sdks/…/graph.pyShows the Python-facing graph values, identity types, and native graph adapter.
sdks/go/internal/embedded_templates/native_graph_uniffi.go.tmplShows how the Go SDK maps its graph API to generated native methods.