|
| 1 | +--- |
| 2 | +title: "Bulk Loader" |
| 3 | +description: "Import large graphs from CSV files into FalkorDB using the falkordb-bulk-loader tool" |
| 4 | +--- |
| 5 | + |
| 6 | +# Bulk Loader |
| 7 | + |
| 8 | +The [falkordb-bulk-loader](https://github.com/falkordb/falkordb-bulk-loader) is a Python utility for building FalkorDB graphs from CSV files. It uses the `GRAPH.BULK` endpoint to import nodes and relationships efficiently in binary batches — much faster than issuing individual `CREATE` queries. |
| 9 | + |
| 10 | +## Requirements |
| 11 | + |
| 12 | +- Python 3.10 or later |
| 13 | +- A running FalkorDB instance (see [Get Started](https://docs.falkordb.com)) |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +```sh |
| 18 | +pip install falkordb-bulk-loader |
| 19 | +``` |
| 20 | + |
| 21 | +## Quick Start |
| 22 | + |
| 23 | +Given two CSV files — `Person.csv` (nodes) and `KNOWS.csv` (relationships) — import them into a graph named `SocialGraph`: |
| 24 | + |
| 25 | +```sh |
| 26 | +falkordb-bulk-insert SocialGraph \ |
| 27 | + -n Person.csv \ |
| 28 | + -r KNOWS.csv |
| 29 | +``` |
| 30 | + |
| 31 | +The label (for nodes) and relationship type (for relationships) are derived from the CSV filename. Multiple node and relation files can be provided by repeating the flags: |
| 32 | + |
| 33 | +```sh |
| 34 | +falkordb-bulk-insert SocialGraph \ |
| 35 | + -n Person.csv \ |
| 36 | + -n Country.csv \ |
| 37 | + -r KNOWS.csv \ |
| 38 | + -r VISITED.csv |
| 39 | +``` |
| 40 | + |
| 41 | +## Connecting to FalkorDB |
| 42 | + |
| 43 | +By default the loader connects to `redis://127.0.0.1:6379`. Use `--redis-url` to point it at a different instance: |
| 44 | + |
| 45 | +```sh |
| 46 | +falkordb-bulk-insert SocialGraph \ |
| 47 | + --redis-url redis://myhost:6379 \ |
| 48 | + -n Person.csv |
| 49 | +``` |
| 50 | + |
| 51 | +## Key Options |
| 52 | + |
| 53 | +| Flag | Extended flag | Description | |
| 54 | +|:----:|---------------|-------------| |
| 55 | +| `-u` | `--redis-url TEXT` | Server URL (default: `redis://127.0.0.1:6379`) | |
| 56 | +| `-n` | `--nodes TEXT` | Node CSV file (filename → label) | |
| 57 | +| `-N` | `--nodes-with-label TEXT` | Explicit label followed by node CSV file | |
| 58 | +| `-r` | `--relations TEXT` | Relationship CSV file (filename → type) | |
| 59 | +| `-R` | `--relations-with-type TEXT` | Explicit type followed by relationship CSV file | |
| 60 | +| `-o` | `--separator CHAR` | Field delimiter (default: `,`) | |
| 61 | +| `-d` | `--enforce-schema` | Require typed column headers (see below) | |
| 62 | +| `-j` | `--id-type TEXT` | Type of node ID property: `STRING` or `INTEGER` | |
| 63 | +| `-s` | `--skip-invalid-nodes` | Skip duplicate node IDs instead of erroring | |
| 64 | +| `-e` | `--skip-invalid-edges` | Skip edges with unknown endpoints instead of erroring | |
| 65 | +| `-i` | `--index Label:Property` | Create a range index after import | |
| 66 | +| `-f` | `--full-text-index Label:Property` | Create a full-text index after import | |
| 67 | + |
| 68 | +## Enforcing a Schema |
| 69 | + |
| 70 | +By default the loader infers each property's type. Use `--enforce-schema` (`-d`) when you want explicit control. Column headers must follow the `name:TYPE` format: |
| 71 | + |
| 72 | +**User.csv** |
| 73 | +```csv |
| 74 | +:ID(User),name:STRING,rank:INT |
| 75 | +0,"Alice",5 |
| 76 | +1,"Bob",8 |
| 77 | +``` |
| 78 | + |
| 79 | +**FOLLOWS.csv** |
| 80 | +```csv |
| 81 | +:START_ID(User),:END_ID(User),weight:DOUBLE |
| 82 | +0,1,0.9 |
| 83 | +1,0,0.4 |
| 84 | +``` |
| 85 | + |
| 86 | +```sh |
| 87 | +falkordb-bulk-insert SocialGraph \ |
| 88 | + --enforce-schema \ |
| 89 | + -n User.csv \ |
| 90 | + -r FOLLOWS.csv |
| 91 | +``` |
| 92 | + |
| 93 | +Accepted type strings: `ID`, `START_ID`, `END_ID`, `IGNORE`, `STRING`, `INT` / `INTEGER` / `LONG`, `DOUBLE` / `FLOAT`, `BOOL` / `BOOLEAN`, `ARRAY`. |
| 94 | + |
| 95 | +## Bulk Updates |
| 96 | + |
| 97 | +The companion command `falkordb-bulk-update` reads a CSV in batches and issues a parameterized Cypher query for each row — useful for incremental updates or when you want full control over the Cypher: |
| 98 | + |
| 99 | +```sh |
| 100 | +falkordb-bulk-update SocialGraph \ |
| 101 | + --csv User.csv \ |
| 102 | + --query "MERGE (:User {id: row[0], name: row[1], rank: row[2]})" |
| 103 | +``` |
| 104 | + |
| 105 | +> **Note:** `falkordb-bulk-update` commits changes incrementally. Sanitize your CSV inputs beforehand to avoid leaving the graph in a partially-updated state. |
| 106 | +
|
| 107 | +## Further Reading |
| 108 | + |
| 109 | +- [GitHub repository](https://github.com/falkordb/falkordb-bulk-loader) — full CLI reference, input constraints, and ID namespaces |
| 110 | +- [GRAPH.BULK specification](/design/bulk-spec) — technical wire-format specification for the underlying endpoint |
0 commit comments