Skip to main content

Load BPMN 2.0 diagrams into Neo4j and create node embeddings for Graph-RAG.

Project description

bpmn2neo

Load BPMN 2.0 diagrams into Neo4j and create node embeddings for Graph-RAG.

PyPI - Version Python License Neo4j BPMN 2.0


1) Overview

Image

bpmn2neo ingests BPMN 2.0 (.bpmn) files, persists a clean BPMN knowledge graph in Neo4j 5.x, then generates hierarchical embeddings for Graph-RAG.
The library is production-oriented: clean configuration via Pydantic .env, and a minimal public API.

  • Parser & Loader: turn .bpmn XML into a normalized Neo4j schema.
  • Embedding Orchestrator: builds node-level context and embeddings in a top-down order (Collaboration → Participant → Process → Lane → FlowNode).
  • Graph-RAG ready: each node stores explanatory text and vector.

2) Key Features

BPMN → Neo4j Loader

  • Robust XML parsing with clear phases (collaboration/participants → processes → lane → flownode → message flow/data objec/etc.).
  • Builds nodes and relationships, mapping each BPMN element’s tag attributes to node properties.
  • Structured logs for each phase, with try/except and error reporting.

👉 Schema details: see the guide Neo4j Graph Schema Guide

Hierarchical Context & Embedding

  • For each node, the pipeline runs:
    Reader → Builder → ContextWriter → Embedder
  • Generates text per node, then embeds using the configured embedding model.
  • Order: FlowNode → Lane → Process → Participant → Model (Collaboration).
    This preserves hierarchy so parents can summarize/aggregate children.

👉 Embedding details: see the guide BPMN Embedding Rules Guide


3) Usage

Installation

pip install bpmn2neo

setting .env

# =========================
# bpmn2neo .env
# =========================
# --- Neo4j (REQUIRED) ---
B2N_NEO4J__URI="YOUR_URI"        # or neo4j+s://<host>:7687
B2N_NEO4J__USERNAME="YOUR_USERNAME"
B2N_NEO4J__PASSWORD="YOUR_PASSWORD"      # if you prefer keyring, comment this and use PASSWORD_ALIAS below
B2N_NEO4J__DATABASE="YOUR_DATABASE"

# Optional Neo4j tweaks:
# B2N_NEO4J__PASSWORD_ALIAS=bpmn2neo/neo4j      # resolve secret via OS keyring
# B2N_NEO4J__LOG_LEVEL=INFO                     # INFO/DEBUG/WARN/ERROR

# --- OpenAI (REQUIRED for embeddings/text) ---
B2N_OPENAI__API_KEY="YOUR_API_KEY"     # if you prefer keyring, comment this and use API_KEY_ALIAS below
B2N_OPENAI__EMBEDDING_MODEL="text-embedding-3-large"

# Optional OpenAI tweaks:
# B2N_OPENAI__API_KEY_ALIAS=bpmn2neo/openai     # resolve secret via OS keyring
# B2N_OPENAI__EMBEDDING_DIMENSION=3072
# B2N_OPENAI__TRANSLATION_MODEL=gpt-4o-mini
# B2N_OPENAI__TEMPERATURE=0.2
# B2N_OPENAI__MAX_TOKENS_FULL=600
# B2N_OPENAI__MAX_TOKENS_SUMMARY=200
# B2N_OPENAI__MAX_RETRIES=3
# B2N_OPENAI__TIMEOUT=60
# B2N_OPENAI__LOG_LEVEL=INFO

# --- Container metadata  ---
B2N_CONTAINER__CREATE_CONTAINER=True # default : true
B2N_CONTAINER__CONTAINER_TYPE="YOUR_CONTAINER_TYPE"
B2N_CONTAINER__CONTAINER_ID="YOUR_CONTAINER_ID"
B2N_CONTAINER__CONTAINER_NAME="YOUR_CONTAINER_NAME"

# --- Runtime (optional) ---
# B2N_RUNTIME__LOG_LEVEL=INFO                  # global log level
# B2N_RUNTIME__PARALLELISM=1                   # worker parallelism
# B2N_RUNTIME__BATCH_SIZE=64                   # embedding batch size
# B2N_RUNTIME__CACHE_DIR=/tmp/bpmn2neo_cache   # local cache dir if you need one
# B2N_RUNTIME__DRY_RUN=false                   # true: do not write to DB
# B2N_RUNTIME__FAIL_FAST=false                 # true: stop on first error

Python API (recommended)

from bpmn2neo import load_bpmn_to_neo4j, create_node_embeddings, load_and_embed
from bpmn2neo.settings import Settings, Neo4jSettings, OpenAISettings

# Option A) reads from .env
s = Settings()  # reads .env via pydantic-settings

# Option B) by each Settings object
s2 = Settings(
    neo4j=Neo4jSettings(
        uri="bolt://localhost:7687",
        user="neo4j",
        password="your_password",
        database="neo4j",
    ),
    openai=OpenAISettings(
        api_key="sk-...",  # or api_key_alias="openai/default" if using keyring
    ),
)

# 1) Load only
model_keys = load_bpmn_to_neo4j(
    bpmn_path="./data/bpmn/Order Process for Pizza.bpmn",
    settings=s,
)
print("model_keys:", model_keys)

# 2) Embedding only
# mode="all"   : full hierarchy (FlowNodes → Lanes → Process → Participant → Model)
# mode="light" : FlowNodes only (faster iteration)
create_node_embeddings(model_key=model_keys[0], settings=s, mode="all")
create_node_embeddings(model_key=model_keys[0], settings=s, mode="light")

# 3) Pipeline (load + embed)
result = load_and_embed(
    bpmn_path="./data/bpmn/Order Process for Pizza.bpmn",
    settings=s,
    mode="light",  # or "all"
)
print("final model_key:", result["model_key"])

Requirements

  • Python 3.10+
  • Neo4j 5.x (Bolt reachable).
    Ensure the user has MATCH/CREATE/MERGE/SET/DELETE and index/constraint privileges.
  • OpenAI API key (for embeddings & text generation).

4) Project Structure

bpmn2neo/
├─ NEO4J_SCHEMA.md         # Neo4j graph schema documentation
├─ EMBEDDING_RULES.md      # Embedding rules and pipeline documentation
├─ src/bpmn2neo/
│  ├─ config/
│  │  ├─ exceptions.py        # Domain exceptions (Config/Neo4j/etc.)
│  │  ├─ logger.py            # Structured logger (JSON-friendly)
│  │  └─ neo4j_repo.py        # Thin Neo4j driver wrapper + helpers
│  ├─ embedder/
│  │  ├─ builder.py           # Build signals/texts from Reader context
│  │  ├─ context_writer.py    # Ask LLM to craft node explanations
│  │  ├─ embedder.py          # Vectorize and persist embeddings
│  │  ├─ orchestrator.py      # Orchestrates Reader→Builder→Writer→Embedder
│  │  └─ reader.py            # Read graph context per node for embedding
│  ├─ loader/
│  │  ├─ loader.py            # High-level load flow (schema ensure + write)
│  │  └─ parser.py            # BPMN XML → nodes/relationships
│  ├─ settings.py             # Pydantic-based config (.env)
│  ├─ cli.py                  # Optional CLI entry
│  └─ __init__.py             # Public API: load, embed, pipeline
└─ pyproject.toml

5) License

Licensed under Apache License 2.0.
See LICENSE.
Notes:

  • No trademark rights are granted.
  • Contributions (if any) are accepted under the same license.
  • Patent grant/termination follows Apache-2.0 terms.

Configuration & Tips

  • Settings resolution: Settings() reads environment variables (and .env) using pydantic-settings. Keys are prefixed (e.g., B2N_NEO4J__URI).
  • Model key: if not provided, the loader derives it from the BPMN filename (stem).
  • Security: you may use keyring aliases instead of plain secrets (see comments in settings.py).

Troubleshooting

  • Cannot connect to Neo4j

    • Verify B2N_NEO4J__URI (neo4j://host:7687 or neo4j+s://... for Aura).
    • Check firewall, DB auth, and database name.
  • OpenAI errors

    • Ensure B2N_OPENAI__API_KEY set; consider rate limits and retries.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bpmn2neo-0.1.9.tar.gz (69.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bpmn2neo-0.1.9-py3-none-any.whl (72.2 kB view details)

Uploaded Python 3

File details

Details for the file bpmn2neo-0.1.9.tar.gz.

File metadata

  • Download URL: bpmn2neo-0.1.9.tar.gz
  • Upload date:
  • Size: 69.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bpmn2neo-0.1.9.tar.gz
Algorithm Hash digest
SHA256 928df32a597deda769306542e6f02720063c5e04d2265b862032c1ee1e8d8672
MD5 f495069ffbaa4b9ac01f37f0019b19f1
BLAKE2b-256 69aefdd525edc6ccd3a0fc1008f6b08fdc5421e13975c4775eab7b601781e902

See more details on using hashes here.

File details

Details for the file bpmn2neo-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: bpmn2neo-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 72.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bpmn2neo-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e778e6e94e6c7343faf673ffc1a573758f54f3152b9880b35cdc15a84b82af7d
MD5 c8950637ed8679ca63918b324d3a2ed1
BLAKE2b-256 0f06eb14754c727bc2f21b90f182ee9a0adba72e690803ab90b8d28eb3f74ac9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page