BOM Reachability
Trace transitive dependencies through a bill of materials to identify which raw materials each finished product depends on and which components are structural bottlenecks.
Browse files
What this template is for
A bill of materials (BOM) defines how finished products are built from components and raw materials through multiple assembly stages. Understanding the full transitive dependency tree — not just direct inputs — is critical for supply chain risk management. This template demonstrates two graph analysis techniques on a BOM structure:
- Reachability (
reachable(full=True)) — Trace all transitive dependencies to answer “What does Product X ultimately depend on?” across multiple assembly tiers. - Betweenness Centrality — Identify structural bottleneck components that sit on the most dependency paths between finished goods and raw materials.
Who this is for
- Intermediate users who want to learn reachability analysis on directed graphs
- Supply chain analysts assessing multi-tier dependency exposure
- Manufacturing engineers identifying single-source risks in their BOM
What you’ll build
- Load a 9-SKU, 14-BOM-entry product structure from CSV (consumer electronics: smartphones, tablets, components, raw materials)
- Construct a directed dependency graph where edges point from output SKU to input SKU (“depends on”)
- Compute all-pairs reachability to map full transitive dependency trees
- List dependencies per finished good, broken down by type (COMPONENT vs RAW_MATERIAL)
- Rank components by how many other SKUs depend on them
- Compute betweenness centrality to identify structural bottlenecks
What’s included
- Self-contained script:
bom_reachability.py— Runs the full analysis end-to-end - Data:
data/skus.csv(9 SKUs across 3 tiers) anddata/bill_of_materials.csv(14 BOM entries with site-specific assembly)
Prerequisites
- Python >= 3.10
- A Snowflake account that has the RAI Native App installed.
- A Snowflake user with permissions to access the RAI Native App.
Quickstart
-
Download and extract this template:
Terminal window curl -O https://docs.relational.ai/templates/zips/v1/bom-reachability.zipunzip bom-reachability.zipcd bom-reachability -
Create and activate a virtual environment
Terminal window python -m venv .venvsource .venv/bin/activatepython -m pip install -U pip -
Install dependencies
Terminal window python -m pip install . -
Configure Snowflake connection and RAI profile
Terminal window rai init -
Run the template
Terminal window python bom_reachability.py
How it works
CSV files --> Define SKU + BOM concepts --> Build directed graph --> Reachability analysis --> Betweenness centrality --> Display results1. Load Ontology
SKU and BillOfMaterials concepts are loaded from CSV. Each BOM entry links an output SKU (what is produced) to an input SKU (what is required):
SKU = model.Concept("SKU", identify_by={"id": String})BillOfMaterials = model.Concept("BillOfMaterials", identify_by={"id": String})BillOfMaterials.output_sku = model.Relationship(f"{BillOfMaterials} produces {SKU}")BillOfMaterials.input_sku = model.Relationship(f"{BillOfMaterials} requires {SKU}")2. Build Directed Graph
The graph uses BillOfMaterials as the edge concept, with edges pointing from output to input (“depends on”):
graph = Graph( model, directed=True, weighted=False, node_concept=SKU, edge_concept=BillOfMaterials, edge_src_relationship=BillOfMaterials.output_sku, edge_dst_relationship=BillOfMaterials.input_sku,)3. Trace Dependencies
reachable(full=True) computes all-pairs reachability — every (source, destination) pair where a directed path exists:
reachable = graph.reachable(full=True)
src, dst = graph.Node.ref("src"), graph.Node.ref("dst")all_deps_df = where(reachable(src, dst)).select( src.id.alias("product_id"), dst.id.alias("dep_id"), ...).to_df()4. Identify Bottlenecks
Betweenness centrality ranks components by how many shortest dependency paths pass through them:
betweenness = graph.betweenness_centrality()Components with high betweenness are structural bottlenecks — disrupting them affects the most product lines.
Customize this template
Use your own data:
- Replace CSVs in
data/with your own SKU and BOM data, keeping the same column names. - The BOM data can include site-specific assembly (SITE_ID column) for multi-site manufacturing.
Extend the analysis:
- Use
reachable(from_=target)to trace downstream impact of a specific component disruption - Add cost or lead time properties to quantify dependency exposure
- Combine with supplier data to map component-to-supplier risk chains
Troubleshooting
Why do I see a "multi-edges" warning?
- The BOM data includes site-specific entries (e.g., SKU001 is assembled at both S001 and S012). This creates duplicate edges between the same SKU pair. The warning is informational — the graph deduplicates automatically. To suppress it, add
aggregator="sum"to the Graph constructor.
Why does authentication/configuration fail?
- Run
rai initto create/updateraiconfig.toml. - If you have multiple profiles, set
RAI_PROFILEor switch profiles in your config.