Skip to content

Snapshots from Parquet & CSV (impulse build)

If you use Python, PyTorch, C/C++, Rust, Go, C#, or Node.js—or want to compile .imps snapshots from Apache Parquet, CSV, or TSV files without writing Java code—the standalone impulse CLI (binary: impulse-graph, aliased as impulse) in impulse-graph-core/impulse-cli builds, inspects, validates, and optimizes snapshots directly from declarative manifests.

Related Guides


1. How impulse build Works

Instead of writing imperative ingestion code, you export your node and edge tables from DuckDB, Pandas, Polars, PyArrow, Spark, Snowflake, or PostgreSQL to Apache Parquet (.parquet) or CSV/TSV (.csv, .tsv), describe your domains and relations in a declarative manifest.json, and run:

impulse build --manifest manifest.json -o graph.imps

Under the hood, impulse build automatically:

  1. Assigns Contiguous Dense IDs (\(0 \dots N_d-1\)) per Domain: Scans your node files (or derives unique node keys directly from your edge files) and builds an embedded Minimal Perfect Hash (_domain_index) table for \(O(1)\) key-to-dense-ID resolution at query time.
  2. Sorts Edges into Forward CSR & Reorders Edge Attributes: Sorts edges by (src_dense_id, tgt_dense_id) to build the Compressed Sparse Row (row_offsets[], col_indices[]) arrays and reorders all edge attribute columns in lockstep so edge_attr[k] aligns with col_indices[k].
  3. Optionally Builds Reverse CSC ("include_csc": true): Transposes the CSR matrix into Compressed Sparse Column arrays so reverse traversals (.in(...) and <-[]- in openCypher) run at the exact same speed as forward traversals.
  4. Aligns All Sections to 128 Bytes: Pads every CSR/CSC array, Structure-of-Arrays (SoA) attribute column, and fixed-width vector embedding to 128-byte boundaries (2 CPU cache lines / AVX-512 / GPU cuFile warp alignment) and seals the snapshot with a Page 0 header and SHA-256 footer.

Installing the impulse CLI

# Install from source (Rust 1.80+)
git clone https://github.com/impulse-graph/impulse-graph-core.git
cargo install --path impulse-graph-core/impulse-cli

# Alias for 'impulse':
alias impulse="impulse-graph"

2. Walkthrough 1: From CSV Files to Python Queries

Let's build the exact same banking graph (User -[:OWNS]-> Account -[:TRANSFERRED_TO {amount}]-> Account) from the Java Builder Guide, using CSV files and querying it in Python.

 (User: "usr_101") ──[:OWNS]──> (Account: "acc_5001") ──[:TRANSFERRED_TO {amount: 2500.00}]──> (Account: "acc_7008")

Step 1: Prepare the CSV Files

Create four CSV files in a bank_data/ directory:

user_id,name,age,risk_score
usr_101,Alice,34,0.12
usr_102,Bob,29,0.05
usr_103,Charlie,52,0.88
account_id,balance
acc_5001,14200.50
acc_6004,890.00
acc_7008,53100.00
user_id,account_id
usr_101,acc_5001
usr_102,acc_6004
usr_103,acc_7008
from_account,to_account,amount,timestamp_ms
acc_5001,acc_6004,450.00,1711929600000
acc_5001,acc_7008,2500.00,1711933200000
acc_6004,acc_7008,1200.00,1711936800000

Step 2: Create manifest.json

Create bank_data/manifest.json mapping the two domains (User = 0, Account = 1), their node attributes, and the two directed relations (OWNS and TRANSFERRED_TO). Because impulse build resolves "file" paths relative to the directory containing manifest.json (bank_data/), reference the CSV filenames directly:

{
  "domains": [
    {
      "id": 0,
      "name": "User",
      "key_type": "string",
      "file": "users.csv",
      "id_column": "user_id",
      "attributes": [
        { "name": "name", "column": "name", "type": "string" },
        { "name": "age", "column": "age", "type": "int32" },
        { "name": "risk_score", "column": "risk_score", "type": "float32" }
      ]
    },
    {
      "id": 1,
      "name": "Account",
      "key_type": "string",
      "file": "accounts.csv",
      "id_column": "account_id",
      "attributes": [
        { "name": "balance", "column": "balance", "type": "float64" }
      ]
    }
  ],
  "relations": [
    {
      "name": "OWNS",
      "src_domain": 0,
      "tgt_domain": 1,
      "file": "owns.csv",
      "src_column": "user_id",
      "tgt_column": "account_id",
      "include_csc": true
    },
    {
      "name": "TRANSFERRED_TO",
      "src_domain": 1,
      "tgt_domain": 1,
      "file": "transfers.csv",
      "src_column": "from_account",
      "tgt_column": "to_account",
      "include_csc": true,
      "attributes": [
        { "name": "amount", "column": "amount", "type": "float64" },
        { "name": "timestamp_ms", "column": "timestamp_ms", "type": "int64" }
      ]
    }
  ]
}

Step 3: Build, Inspect & Validate

Run impulse build to compile banking.imps, then inspect and validate it:

# 1. Compile CSVs into an .imps binary snapshot
impulse build --manifest bank_data/manifest.json -o banking.imps

# 2. Inspect domains, relations, attribute columns, and section offsets
impulse snapshot inspect banking.imps --verbose

# 3. Verify alignment, monotonic CSR offsets, and SHA-256 checksum
impulse snapshot validate banking.imps --strict-alignment

Step 4: Mount and Query in Python

Open banking.imps in Python (pip install impulse-graph):

from impulse_graph import Snapshot

with Snapshot("banking.imps") as snap:
    print(f"Domains: {snap.domain_count()}, Relations: {snap.relation_count()}")

    # 1. Domain-bound Fluent Traversal from User "usr_101":
    # Walk OWNS -> walk TRANSFERRED_TO -> return reached Account keys and dense IDs
    users = snap.domain("User")
    reached_account_keys = (
        users.from_key("usr_101")
             .out("OWNS")
             .out("TRANSFERRED_TO")
             .to_key_list()
    )
    print("Accounts reached from usr_101:", reached_account_keys)

    # 2. Parameterized openCypher Query over the same memory-mapped snapshot:
    high_value_recipients = snap.cypher(
        """
        MATCH (u:User)-[:OWNS]->(src:Account)-[:TRANSFERRED_TO]->(dst:Account)
        WHERE u.id = $user_id
        RETURN dst
        """,
        params={"user_id": 0},
        catalog={"OWNS": 0, "TRANSFERRED_TO": 1},
    )
    print("Destination Account dense IDs:", high_value_recipients)

3. Walkthrough 2: From Apache Parquet to PyTorch & GNNs

If your data lives in Apache Parquet (from PyArrow, Pandas, Polars, DuckDB, or Spark) and your destination is PyTorch / PyG, impulse build reads .parquet files natively—including fixed-size vector embeddings (FixedSizeListArray) and nullable Arrow validity bitmaps. Once compiled, PyTorch mounts the .imps file directly via torch.from_numpy() and shares the OS page cache across DataLoader workers (see PyTorch GNN Sampling, Embeddings & Vamana Vector Search and PyTorch & GNN Showcase).

Step 1: Export Node & Edge Tables to Parquet (Python / PyArrow)

Here we generate a synthetic citation graph (papers.parquet with 128-dimensional float32 feature vectors and citations.parquet with edge weights):

import numpy as np
import pyarrow as pa
import pyarrow.parquet as pq

num_papers = 10_000
num_edges = 80_000
feat_dim = 128

# 1. Build papers.parquet with scalar attributes + 128-D float32 embedding column
rng = np.random.default_rng(42)
flat_features = rng.standard_normal(num_papers * feat_dim, dtype=np.float32)
feature_list_array = pa.FixedSizeListArray.from_arrays(pa.array(flat_features), feat_dim)

papers_table = pa.table({
    "paper_id": pa.array([f"paper_{i}" for i in range(num_papers)], type=pa.string()),
    "year": pa.array(rng.integers(2015, 2026, size=num_papers, dtype=np.int32)),
    "label": pa.array(rng.integers(0, 10, size=num_papers, dtype=np.int32)),
    "features": feature_list_array,
})
pq.write_table(papers_table, "papers.parquet")

# 2. Build citations.parquet (directed edges: citing_id -> cited_id)
src_idx = rng.integers(0, num_papers, size=num_edges)
tgt_idx = rng.integers(0, num_papers, size=num_edges)
citations_table = pa.table({
    "citing_id": pa.array([f"paper_{i}" for i in src_idx], type=pa.string()),
    "cited_id": pa.array([f"paper_{i}" for i in tgt_idx], type=pa.string()),
    "weight": pa.array(rng.uniform(0.1, 1.0, size=num_edges).astype(np.float32)),
})
pq.write_table(citations_table, "citations.parquet")

Step 2: Create citation_manifest.json

Point domains and relations directly at the .parquet files. Notice "dimension": 128 on the features attribute—impulse build writes the 128-dimensional float32 vectors as a contiguous [N, 128] tensor block inside the .imps file:

{
  "domains": [
    {
      "id": 0,
      "name": "Paper",
      "key_type": "string",
      "file": "papers.parquet",
      "format": "parquet",
      "id_column": "paper_id",
      "attributes": [
        { "name": "year", "column": "year", "type": "int32" },
        { "name": "label", "column": "label", "type": "int32" },
        { "name": "features", "column": "features", "type": "float32", "dimension": 128 }
      ]
    }
  ],
  "relations": [
    {
      "name": "CITES",
      "src_domain": 0,
      "tgt_domain": 0,
      "file": "citations.parquet",
      "format": "parquet",
      "src_column": "citing_id",
      "tgt_column": "cited_id",
      "include_csc": true,
      "attributes": [
        { "name": "weight", "column": "weight", "type": "float32" }
      ]
    }
  ]
}

Step 3: Compile & Optimize CSR Locality (--rcm)

Compile the Parquet files into an .imps snapshot, and optionally run impulse snapshot optimize --rcm (Reverse Cuthill-McKee bandwidth reduction) so that densely connected nodes are placed adjacent to one another in memory for higher L2/L3 cache hit rates during GNN message passing:

# 1. Compile Parquet files into raw .imps snapshot
impulse build --manifest citation_manifest.json -o citations_raw.imps

# 2. Reorder dense IDs with Reverse Cuthill-McKee (RCM) to minimize CSR cache misses
impulse snapshot optimize -i citations_raw.imps -o citations.imps --rcm --csc

# 3. Inspect degree distribution & supernodes (statistical Z-score threshold, default 3.0)
impulse snapshot stats citations.imps --supernode-threshold 3.0

Step 4: Mount in PyTorch (impulse-gnn)

Showcase Package (impulse-gnn)

impulse_gnn lives in the impulse-gnn showcase repository (not published on PyPI). Install it from a local clone with pip install -e ..

Load citations.imps in PyTorch. CSR arrays (row_offsets, col_indices) and node attributes are exposed as read-only torch.Tensor views:

import torch
from impulse_gnn import ImpulseGnnDataset, ImpulseNeighborSampler

# 1. Open citations.imps directly from disk
dataset = ImpulseGnnDataset("citations.imps")
print(f"Nodes: {dataset.node_count:,}, Edges: {dataset.edge_count:,}")

# 2. Read-only tensor views over the CSR arrays
row_offsets: torch.Tensor = dataset.row_offsets   # torch.uint32 [node_count + 1]
col_indices: torch.Tensor = dataset.col_indices   # torch.uint32 [edge_count]

# 3. Sample 2-hop GraphSAGE mini-batches (25 neighbors at hop 1, 10 at hop 2)
sampler = ImpulseNeighborSampler(dataset, sizes=[25, 10])
seed_nodes = torch.arange(0, 1024, dtype=torch.int32)
subgraphs = sampler.sample(seed_nodes.tolist())

print(f"Sampled {len(subgraphs)} hops; hop-0 edges: {subgraphs[0].shape[1]}")

# 4. Also interoperates with SciPy / NetworkX / GraphBLAS:
csr_mat = dataset.to_scipy_csr()

Tip

Want to learn more about PyTorch GNN training, embedded Vamana ANN (0x08), and graphs larger than RAM? See PyTorch GNN Sampling, Embeddings & Vamana Vector Search and the PyTorch & Graph Neural Networks Showcase.


4. manifest.json Complete Reference

A manifest.json file contains two top-level arrays: "domains" and "relations".

4.1 domains[] Schema

Each object in "domains" defines an independent node domain with its own contiguous dense ID space (\(0 \dots N_d-1\)):

Field Type Required Description
id u16 Yes Unique numeric domain ID (0, 1, 2, ...). Referenced by src_domain and tgt_domain in relations[].
name string Yes Logical domain name used in queries (e.g., "User", "Account", "Paper").
key_type string Yes Data type of the external primary key: "string", "int64", "uint64", "uuid", "int32", or "uint16".
file string No Path to the node table file (.parquet, .pq, .csv, .tsv), resolved relative to the directory containing manifest.json. If omitted, the domain's unique keys and node count are inferred automatically from the edge files that reference this domain.
format string No "parquet", "csv", or "tsv". Auto-detected from the file extension if omitted.
id_column string No Column name containing the primary key in file. Defaults to "id" (or column 0 in headerless CSVs).
attributes AttributeDef[] No List of node attribute columns to extract from file into SoA columns.

4.2 relations[] Schema

Each object in "relations" defines a directed edge relation from src_domain to tgt_domain:

Field Type Required Description
name string No Relation name used in .out("NAME") / .in("NAME") and openCypher [:NAME]. Defaults to "REL_{src}_{tgt}" if omitted.
src_domain u16 Yes Numeric id of the source domain.
tgt_domain u16 Yes Numeric id of the target domain.
file string Yes Path to the edge table file (.parquet, .pq, .csv, .tsv, .txt), resolved relative to the directory containing manifest.json.
format string No "parquet", "csv", or "tsv". Auto-detected from the file extension if omitted.
src_column string No Column name for the source node key. Defaults to "src" (or column 0 in CSV/TSV).
tgt_column string No Column name for the target node key. Defaults to "tgt" (or column 1 in CSV/TSV).
include_csc bool No When true, builds both forward CSR and reverse CSC topologies so .in(...) reverse walks execute in \(O(1)\) offset lookup time. Defaults to false.
encoding string No Target adjacency list encoding: "raw" (default uncompressed arrays). Compressed gap encodings ("elias_fano", "bic") are planned for future specifications.
attributes AttributeDef[] No List of edge attribute columns to extract from file and reorder alongside the CSR edges.

4.3 attributes[] Schema & Supported Data Types

Both domains and relations accept an "attributes" array where each element has:

{
  "name": "amount",
  "column": "transfer_amount_usd",
  "type": "float64",
  "dimension": 1
}
  • name (required): Attribute name exposed to queries (node.amount, edge.amount).
  • column (required): Source column name in the Parquet or CSV/TSV file.
  • type (optional for Parquet, recommended for CSV): Explicit storage type. For Parquet inputs, impulse build automatically infers the Impulse type from the Arrow column schema if "type" is omitted.
  • dimension (optional): Defaults to 1 (scalar). Set "dimension": D (e.g., 128, 384, 768) for fixed-width vector embeddings stored in Parquet FixedSizeListArray columns.
Type String in manifest.json Physical Layout in .imps Parquet / Arrow Source Types
"int8", "int16", "int32", "int64" Signed 8 / 16 / 32 / 64-bit integer array Int8, Int16, Int32, Int64
"uint8", "uint16", "uint32", "uint64" Unsigned 8 / 16 / 32 / 64-bit integer array UInt8, UInt16, UInt32, UInt64
"float16", "float32", "float64" IEEE-754 16 / 32 / 64-bit float array Float16, Float32, Float64
"bool" / "boolean" 8-bit boolean array (1 byte per element, INT8 0x01). (Note: Nullability bitmaps for nullable attributes are bit-packed at 1 bit per element). Boolean
"timestamp_ms", "timestamp_ns", "date32" 64-bit epoch timestamp (ms / ns) or 32-bit days Timestamp(Millisecond/Second/Microsecond/Nanosecond), Date32, Date64
"string" Variable-length UTF-8 (VAR_STRING 0x0B): per-column 128B-aligned uint32_t offsets[K+1] array + contiguous UTF-8 byte blob in Section 4 (note: Section 2 Shared String Pool stores only schema catalog identifiers) Utf8, LargeUtf8
"uuid" 128-bit (16-byte) fixed-width binary UUID (FIXED_BYTES 0x0A, dim = 16) FixedSizeBinary(16) or UUID string
Nullable Suffix ("?") (e.g. "float64?", "int32?") Prepends an aligned Arrow validity bitmap (1 = valid, 0 = null) before the data array Any nullable Parquet column or CSV column with empty cells

Note

Primary Key Catalog vs. Programmatic & Vector Secondary Indices (Section 2.6): When impulse build compiles a manifest.json, it automatically builds the primary key lookup index (_domain_index) and attribute min/max metadata for each domain. Embedded DiskANN/Vamana vector indices (0x08 IMP_INDEX_VAMANA_ANN, v0.10.0) can be built directly from the CLI via --embeddings <SPEC> and --vector-index <SPEC> on impulse build, impulse snapshot attach-embeddings, or impulse snapshot optimize. Additional secondary indices (0x01 Permutation, 0x02 ZoneMap, 0x03 InvertedBitset, 0x04 MinimalPerfectHash, 0x05 Trigram, 0x06 DomainSplitBitset, 0x07 TemporalInterval, 0x08 VamanaANN) can also be constructed programmatically via the C-ABI (impulse_index_build_* + impulse_writer_add_index in impulse_index.h) or Rust SnapshotWriter::add_index / SnapshotWriter::add_built_vamana_index.


5. Snapshot CLI Lifecycle Cheat Sheet

Beyond impulse build, the impulse CLI provides a complete toolkit for inspecting, validating, optimizing, diffing, and exporting .imps snapshots:

Command Example Purpose
build impulse build --manifest manifest.json -o graph.imps Compiles CSV, TSV, or Parquet node/edge files into an .imps snapshot (supports --embeddings and --vector-index). Pass -o - to stream to stdout (e.g., impulse build -m manifest.json -o - \| aws s3 cp - s3://bucket/graph.imps).
snapshot attach-embeddings impulse snapshot attach-embeddings -i base.imps -o vec.imps --embeddings "Paper.emb=vecs.npy:dim=768:norm=l2" --vector-index "Paper.emb:R=32:L=64:quant=sq8" Attaches external embedding files (.npy, .fvecs, .safetensors, .parquet, .jsonl, .csv) and optional Section 2.6 Vamana ANN indices (0x08) to an existing .imps snapshot.
bench-vector impulse bench-vector -n 10000 -d 128 --ef-search 16,32,64 --compare-optimize Runs the empirical Vamana ANN (IMP_INDEX_VAMANA_ANN = 0x08) construction, two-stage quantized beam search (NONE, FP16, SQ8, BQ1), and Recall@K / QPS benchmark suite.
snapshot inspect impulse snapshot inspect graph.imps --verbose Prints Page 0 header flags, domain cardinalities, relation encodings, attribute schemas, and byte offsets (supports --format json).
snapshot validate impulse snapshot validate graph.imps --strict-alignment --deep-audit Verifies magic bytes, section alignment, monotonic CSR/CSC offset bounds, Vamana ANN invariants (--quick-check / --deep-audit), and the footer SHA-256 checksum.
snapshot stats impulse snapshot stats graph.imps --supernode-threshold 3.0 Computes min/max/mean/p99 out-degree distributions, sparsity, multiplicity, and flags high-degree supernodes exceeding the statistical Z-score threshold (default 3.0).
snapshot optimize impulse snapshot optimize -i raw.imps -o opt.imps --rcm --vamana-locality --csc Reorders domain dense IDs via Reverse Cuthill-McKee (--rcm), Vamana Medoid BFS (--vamana-locality), or Degree Sorting (--degree-sort) to maximize CPU cache locality, and optionally generates missing CSC reverse indices (--csc).
snapshot diff impulse snapshot diff v1.imps v2.imps Compares two .imps snapshots and reports added/removed domains, relations, node/edge count deltas, and attribute layout changes.
snapshot export impulse snapshot export graph.imps -o out_dir/ --format csv Exports the topology of an .imps snapshot back to csv, tsv, or jsonl files.
snapshot convert-tensors impulse snapshot convert-tensors -i model.safetensors -o weights.imps --domain Layer Converts HuggingFace .safetensors archives into .imps vector attribute columns (with optional --vector-index).

6. Official Programmatic Snapshot Writers & Format Compliance

Always generate .imps snapshots using impulse build or the official writer APIs rather than ad-hoc scripts writing raw binary bytes:

  • CLI (CSV / TSV / Apache Parquet): impulse build --manifest manifest.json -o graph.imps (or impulse generate for synthetic topologies).
  • Java 21 LTS / Java 25 (SnapshotBuilder): org.impulsegraph.builder.api.SnapshotBuilder (Building Snapshots in Java).
  • Rust (SnapshotWriter): impulse_graph::SnapshotWriter in impulse-rust (Rust Crate Reference).
  • C / C++20 (impulse_writer_* C-ABI): impulse_writer_create / impulse_writer_finalize in impulse_graph.h (C-ABI & C++20 Reference).

If you are implementing a custom writer: 1. Follow the Binary Snapshot Format Specification for exact header, catalog, CSR/CSC, and footer offsets. 2. Validate output with:

impulse snapshot validate output.imps --strict-alignment
impulse snapshot inspect output.imps --verbose
3. Cross-check against the specification test vectors (tc01–tc38; see Polyglot Validation).


Next Steps