Load Arrow and Polars Data

Use columnar ingestion for table-shaped graph input. Use object writes for simple incremental changes (The Property Graph). Choose the backend and serializer independently (Storage Backends); the examples use LMDB/JSON for a portable demonstration, not a claim of native-writer speed.

Choose payload and index policies

Two independent ingestion choices

Policy

Meaning

ColumnarIngestionMode.ENTITY_COLUMNS (high-level default)

Build payloads from IDs, labels, endpoints, types and property columns. JSON-compatible structured input can use eligible optimized conversion.

ColumnarIngestionMode.SERIALIZED_PAYLOADS

Supply node/edge bytes encoded with the graph’s serializer. Column IDs, endpoints and types must agree with the payloads; arbitrary JSON blobs are not necessarily serialized graph entities.

IndexMaintenanceMode.MAINTAIN

Maintain configured secondary indexes during loading; ready for indexed reads.

IndexMaintenanceMode.DEFER

Write canonical records and typed adjacency, mark secondary indexes stale; call rebuild_deferred_indexes() before index-backed reads.

IndexMaintenanceMode.DEFER_REBUILD (high-level default)

Defer during loading, then rebuild before the high-level call returns. This moves work; it does not guarantee lower total time.

Property indexes are explicit. Create them before loading or build them afterward; labels/types are automatic. All examples below choose the policy explicitly so their read-after-load behavior is clear.

Arrow entity columns

Standalone runnable example. Install gestaltdb[lmdb,arrow]. Node columns have two rows and edge columns one row; lengths must agree within each entity family, not across node and edge families.

Standalone example. Choose the capability-qualified installation tab below.

Entity-column loading supports these choices, but optimized JSON conversion and native writer availability differ; do not infer equal performance.

1python -m pip install "gestaltdb[arrow,lmdb]"
 1from tempfile import TemporaryDirectory
 2import pyarrow as pa
 3from gestaltdb.graphdb import GraphDB
 4from gestaltdb.ingestion import ColumnarIngestionMode, IndexMaintenanceMode
 5
 6with TemporaryDirectory() as root:
 7    with GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json') as graph:
 8        graph.create_node_property_index("name")
 9        graph.create_edge_property_index("score")
10        loaded = graph.ingest_arrow(
11            pa.array(["drug-1", "protein-1"]), pa.array(["binding-1"]),
12            pa.array(["drug-1"]), pa.array(["protein-1"]), pa.array(["binds"]),
13            labels=pa.array([["Drug"], ["Protein"]]),
14            node_properties={"name": pa.array(["Aspirin", "PTGS1"])},
15            edge_properties={"score": pa.array([0.9])},
16            ingestion_mode=ColumnarIngestionMode.ENTITY_COLUMNS,
17            index_mode=IndexMaintenanceMode.DEFER_REBUILD,
18        )
19        assert loaded["nodes"] == 2 and loaded["edges"] == 1
20        assert [n.get_id for n in graph.nodes_by_property("name", "Aspirin")] == ["drug-1"]
21        assert [e.get_id for e in graph.edges_by_type_property_range("binds", "score", 0.8, None)] == ["binding-1"]
22        assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]

Polars entity columns with an explicit rebuild

Standalone runnable example. Install gestaltdb[lmdb,polars]. Select property columns explicitly; do not assume every input column becomes a property. This example deliberately defers indexes and rebuilds before indexed lookups.

Standalone example. Choose the capability-qualified installation tab below.

Polars loading keeps the explicit defer/rebuild policy. Backend and codec choice do not imply identical fast paths.

1python -m pip install "gestaltdb[lmdb,polars]"
 1from tempfile import TemporaryDirectory
 2import polars as pl
 3from gestaltdb.graphdb import GraphDB
 4from gestaltdb.ingestion import ColumnarIngestionMode, IndexMaintenanceMode
 5
 6nodes = pl.DataFrame({
 7    "node_id": ["drug-1", "protein-1"],
 8    "labels": [["Drug"], ["Protein"]],
 9    "name": ["Aspirin", "PTGS1"],
10})
11edges = pl.DataFrame({
12    "edge_id": ["binding-1"], "source": ["drug-1"], "target": ["protein-1"],
13    "edge_type": ["binds"], "score": [0.9],
14})
15with TemporaryDirectory() as root:
16    with GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json') as graph:
17        graph.create_node_property_index("name")
18        graph.ingest_polars(
19            nodes, edges, node_property_columns=["name"], edge_property_columns=["score"],
20            ingestion_mode=ColumnarIngestionMode.ENTITY_COLUMNS,
21            index_mode=IndexMaintenanceMode.DEFER,
22        )
23        # Known-ID reads use canonical records; secondary indexes are still stale.
24        assert graph.get_node("drug-1").properties["name"] == "Aspirin"
25        graph.rebuild_deferred_indexes()
26        assert [n.get_id for n in graph.nodes_by_property("name", "PTGS1")] == ["protein-1"]

Pre-serialized payloads

Standalone runnable example. Install gestaltdb[lmdb,arrow]. Build bytes with the graph’s own entity serializers so IDs, labels and relationship types are represented correctly. Pre-serialization is useful when an upstream producer already owns compatible payload construction, not as a reason to double-encode it.

Standalone example. Choose the capability-qualified installation tab below.

Payloads are encoded by the chosen graph serializer; changing the tab rebuilds compatible bytes rather than reusing bytes from another codec.

1python -m pip install "gestaltdb[arrow,lmdb]"
 1from tempfile import TemporaryDirectory
 2import pyarrow as pa
 3from gestaltdb.graphdb import Edge, GraphDB, Node
 4from gestaltdb.ingestion import ColumnarIngestionMode, IndexMaintenanceMode
 5
 6with TemporaryDirectory() as root:
 7    with GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json') as graph:
 8        nodes = [Node("drug-1", labels=["Drug"]), Node("protein-1", labels=["Protein"])]
 9        edge = Edge("binding-1", "drug-1", "protein-1", properties={"type": "binds"})
10        graph.ingest_arrow(
11            pa.array([n.get_id for n in nodes]), pa.array([edge.get_id]),
12            pa.array([edge.source]), pa.array([edge.target]), pa.array(["binds"]),
13            node_values=pa.array([graph.serialize_node_value(n) for n in nodes]),
14            edge_values=pa.array([graph.serialize_edge_value(edge)]),
15            ingestion_mode=ColumnarIngestionMode.SERIALIZED_PAYLOADS,
16            index_mode=IndexMaintenanceMode.MAINTAIN,
17        )
18        assert [n.get_id for n in graph.nodes_by_label("Drug")] == ["drug-1"]
19        assert graph.get_edge("binding-1").properties["type"] == "binds"

Boundaries and lower-level interfaces

  • Columnar edge ingestion is append-only. Use object/Cypher writes for relationship replacement. Typed adjacency is maintained, while the legacy adjacency blobs are intentionally not populated by this ingestion path.

  • chunk_size controls write chunks, not an end-to-end process-memory cap. Conversion, index rebuilding and backend buffers have separate costs.

  • native=True requests available fast paths; it does not guarantee every backend/codec/input uses a native writer. Plain PyRex can use native columnar writes; transactional PyRex currently has a different write path.

  • Do not infer portable cross-call or cross-family atomicity from the word “bulk”. Graph-level wrappers use available transactions; use an explicit supported transaction for a larger application scope (Storage Backends).

  • Format services are available as graph.ingest.arrow / graph.ingest.polars. Their nodes/edges methods consume payloads; node_entities/ edge_entities consume structured columns. Low-level maintain/defer policy is distinct from the high-level graph-wide defer/rebuild coordinator.

  • This loads current records, not temporal versions or epistemic claims. See Temporal history and service reference for immutable history writes.

Continue with Choose How to Load and Query Data for indexed lookup choices, Query and Mutate with Cypher for result composition, or Property-Graph Filtering and Indexes for a filtered sampler build.