neo4j-knowledge-graph-architect
Architect, ingest, query, and test production Neo4j property graphs (LPG) using backward schema modeling, idempotent batch ingestion, and traversal safety. Trigger for Neo4j graphs, Cypher queries, or epistemic graphs. Do not use for W3C RDF/OWL (use /ontological-engineering-coach) or SQL CTEs (use /sql-recursive-graph-traversal).
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- neo4j-knowledge-graph-architect
- description
- Architect, ingest, query, and test production Neo4j property graphs (LPG) using backward schema modeling, idempotent batch ingestion, and traversal safety. Trigger for Neo4j graphs, Cypher queries, or epistemic graphs. Do not use for W3C RDF/OWL (use /ontological-engineering-coach) or SQL CTEs (use /sql-recursive-graph-traversal).
02 资源文件 7
- 参考文档CARD.md6.7 KB
- 参考文档config.default.yaml360 B
- 参考文档REFERENCE.md7.3 KB
- 脚本scripts/__init__.py651 B
- 脚本scripts/batch_ingest.py8.3 KB
- 脚本scripts/cypher_linter.py9.9 KB
- 脚本scripts/evidence_model.py6.5 KB
03 SKILL.md 正文
Neo4j Knowledge Graph Architect
neo4j-knowledge-graph-architect operationalizes Neo4j as an enterprise-grade Labeled Property Graph (LPG) platform. It provides end-to-end guidance for schema design, idempotent batch ingestion, Cypher query engineering, index governance, and ephemeral integration testing. It incorporates epistemic browsing patterns, temporal evidence modeling, and strict boundaries separating primary graph facts from derived analytical inferences.
[1. Schema Design & Semantic Modeling]
↓
[2. Idempotent Batch Ingestion Engine]
↓
[3. Cypher Query Engineering & Traversal Safety]
↓
[4. Index Governance & Query Profiling]
↓
[5. Ephemeral Test Harnessing & Correctness Validation]
See CARD.md for the companion summary card, 5-stage matrix, core pillars, and anti-pattern checklist.
See REFERENCE.md for production Cypher templates, EXPLAIN profiling scripts, and test harness fixtures.
See scripts/ for executable tooling:
scripts/cypher_linter.py— Static Cypher safety analyzer (detects unbounded traversals, trail traps, MERGE mutations).scripts/evidence_model.py— Slotted 7-tuple temporal evidence reification engine (Rule 12).scripts/batch_ingest.py— High-throughput batch ingestion pipeline with chunking and double-load idempotency verification. Consult/data-topology-mapperfor structural blast radius mapping and/epistemic-isnad-auditfor chain-of-custody lineage.
Disambiguation: Graph Engine Selection
Before architecting a graph solution, route the domain problem to the appropriate engineering paradigm:
| Requirement / Paradigm | Engine / Technology | Dispatched Skill |
|---|---|---|
| Labeled Property Graph (LPG): Deep traversal, index-free adjacency, rich node/relationship properties, Cypher queries, pattern matching. | Neo4j (Bolt protocol) | /neo4j-knowledge-graph-architect (This Skill) |
| Relational Graph / Hierarchy: Direct trees, bill of materials, org charts, pathfinding inside existing PostgreSQL / SQLite databases. | Relational SQL (WITH RECURSIVE) |
/sql-recursive-graph-traversal |
| Formal Ontology & Reasoning: W3C standards, RDF triples, OWL taxonomies, SPARQL endpoints, open-world description logics. | RDF / Triplestores | /ontological-engineering-coach |
1. Schema Design & Semantic Modeling
Design labeled property graph schemas backwards from competency questions, ensuring every node label, relationship type, and property serves an explicit query need:
- Partition Graph Primitives:
- Nodes (
:Label): Model distinct business or epistemic entities with independent lifecycles (Person,Paper,Claim,Institution). - Properties (
key: value): Store scalar attributes, metrics, timestamps, and textual descriptions on nodes or edges. - Relationships (
-[:TYPE]->): Model directed semantic connections as explicit, typed verbs (AUTHORED,CITES,AFFILIATED_WITH,REFUTES).
- Nodes (
- Apply Backward Competency Modeling:
- Formulate target business/epistemic questions first (e.g., "Which authors published papers refuting claim X between 2024 and 2026?").
- Derive the path pattern directly from the question:
(:Author)-[:AUTHORED]->(:Paper)-[:REFUTES]->(:Claim). - Validate that relationship directions reflect the semantic action flow while remaining navigable in either direction during query time.
- Model Temporal Evidence Objects:
- For contested, dynamic, or empirical domains, do not use flat timeless edges.
- Reify the connection into a 7-tuple temporal evidence object:
(subject, predicate, object, time, source, confidence, status). - Represent disputed claims with explicit properties (
confidence: 0.85,valid_from: date("2025-01-01"),status: "VERIFIED").
- Enforce the Relation-vs-Inference Boundary:
- Separate documented primary facts (direct observations from source literature) from derived graph analytics (community clusters, inferred links, PageRank scores).
- Tag inferred edges with distinct types or metadata (
inferred: true,algorithm: "louvain",run_id: "20260907") to prevent circular hallucinations.
Axis 3 Diagnostic Questions (Schema Design)
- What specific business or analytical competency questions must this graph answer on day one?
- Have all entities with independent identities been isolated as nodes rather than serialized arrays in properties?
- Are relationship types semantically specific verbs (
AUTHORED,SUPPORTS) rather than generic links (CONNECTED_TO,RELATED)? - Does the schema distinguish primary observational facts from derived algorithmic inferences?
Completion Criterion: Annotated schema diagram or Cypher schema contract answering all target competency questions, with unambiguous node/relationship partitions and temporal evidence properties.
2. Idempotent Batch Ingestion Engine
Construct high-throughput, restart-safe data ingestion pipelines utilizing parameterized batches and schema constraints:
- Pre-Create Schema Constraints:
- Always declare uniqueness and existence constraints before loading data:
CREATE CONSTRAINT cst_person_id IF NOT EXISTS FOR (p:Person) REQUIRE p.id IS UNIQUE; CREATE CONSTRAINT cst_paper_doi IF NOT EXISTS FOR (p:Paper) REQUIRE p.doi IS UNIQUE; - Schema constraints automatically back properties with underlying range indexes, accelerating
MERGElookups from $O(N)$ scans to $O(\log N)$ seeks.
- Always declare uniqueness and existence constraints before loading data:
- Enforce Single Driver Instance Lifecycle:
- Instantiate exactly one
GraphDatabase.driverinstance per application lifecycle. - Manage connection pools through lightweight, short-lived sessions (
driver.session()) and execute writes inside explicit transaction functions (session.execute_write(tx_fn)).
- Instantiate exactly one
- Execute Parameterized Cypher Exclusively:
- Never use Python string interpolation or f-strings to inject values into Cypher queries.
- Pass row batches as structured query parameters (
$batch) to enable query plan caching and eliminate Cypher injection vulnerabilities.
- Implement Identity-Isolated
MERGE:- Scope
MERGEstatements to a single immutable natural identity property. - Set mutable attributes inside
ON CREATE SETandON MATCH SETclauses:UNWIND $batch AS row MERGE (p:Person {id: row.id}) ON CREATE SET p.name = row.name, p.created_at = datetime() ON MATCH SET p.name = row.name, p.updated_at = datetime();
- Scope
- Tune Chunk Sizes for Memory Bounding:
- Ingest data in chunks of 1,000 to 5,000 items.
- Keep transaction sizes small enough to avoid Java Virtual Machine (JVM) garbage collection pauses and prevent transaction log memory blowout.
Axis 3 Diagnostic Questions (Ingestion)
- Are all
MERGEtarget properties protected by unique schema constraints before batch execution begins? - Is the ingestion query fully parameterized, with zero string interpolation or concatenated values?
- Does each
MERGEisolate a single immutable natural key, setting other fields viaON CREATE SET/ON MATCH SET? - Is the batch size tuned between 1,000 and 5,000 rows to ensure sub-second commit cycles?
Completion Criterion: Executable Python ingestion script processing structured batches via
UNWIND $batchwith identity-isolatedMERGE, completing double-runs with zero duplicate nodes or relationships.
3. Cypher Query Engineering & Traversal Safety
Author declarative Cypher queries that leverage index-free adjacency while preventing combinatorial explosion and memory exhaustion:
- Anchor Queries & Directional Traversal:
- Anchor graph traversals on indexed start nodes using specific labels and property predicates:
MATCH (p:Person {id: $person_id})-[:AUTHORED]->(paper:Paper) RETURN paper.title, paper.year;
- Anchor graph traversals on indexed start nodes using specific labels and property predicates:
- Mitigate the Cypher Trail Semantics Trap:
- Neo4j Trail Semantics Rule: A single path pattern will never traverse the exact same relationship twice.
- Trap: In diamond patterns (
(a)-[:REL]->(b)-[:REL]->(d)and(a)-[:REL]->(c)-[:REL]->(d)) or cyclic expansions, queries expecting to traverse shared edges across parallel paths may return zero rows if written as a single chained match. - Mitigation: Split traversal steps across
WITHclauses to reset relationship evaluation scopes:MATCH (a:Node {id: $id})-[:STEP1]->(b:Node) WITH a, b MATCH (b)-[:STEP2]->(c:Node) RETURN a, b, c;
- Bound Variable-Length Relationship Traversal:
- Never write unbounded path patterns (
-[:CONNECTED*]->). - Always declare explicit lower and upper bounds:
-[:CITES*1..4]->. - Add inline filtering predicates or depth brakes to prevent factorial path explosions on dense nodes.
- Never write unbounded path patterns (
- Apply
OPTIONAL MATCHSemantics:- Use
OPTIONAL MATCHfor graph outer joins (e.g., retrieving an author whose affiliations may not yet be recorded). - Place required graph anchors in the leading
MATCHbefore introducingOPTIONAL MATCHbranches to prevent full-graph scans.
- Use
- Manage Pipeline Scope via
WITH:- Use
WITHto group, aggregate, filter, and page (ORDER BY,SKIP,LIMIT) intermediate rows before expanding to subsequent hops.
- Use
Axis 3 Diagnostic Questions (Query Engineering)
- Does every variable-length relationship traversal specify an explicit upper bound (e.g.,
*1..4)? - Are multi-hop diamond or cyclic traversals properly split across
WITHboundaries to avoid trail semantics row drops? - Are optional relationships isolated in
OPTIONAL MATCHclauses following indexed root anchors? - Are intermediate result sets pruned with
WITH ... WHERE ...before secondary expansions?
Completion Criterion: Cypher queries executing with bounded path depths, correct trail semantics handling, and verified deterministic result sets across test graph topologies.
4. Index Governance & Query Profiling
Govern Neo4j index structures and profile Cypher execution plans to eliminate bottlenecks before production deployment:
- Deploy Specialized Index Types:
- Range Index: Default B-tree index for exact matches and scalar comparisons (
n.id,n.age > 30). - Text Index: Optimized for substring and regex lookups (
n.name STARTS WITH 'Dr.'). - Point Index: Optimized for 2D/3D spatial coordinate queries (
distance(n.location, $point) < 1000). - Fulltext Index: Lucene-backed full-text search across multiple node labels and string properties.
- Vector Index: Approximate Nearest Neighbor (ANN) index for high-dimensional embeddings.
- Range Index: Default B-tree index for exact matches and scalar comparisons (
- Execute
EXPLAINin CI Quality Gates:- Run
EXPLAINon all query templates during static testing. - Verify that queries use
NodeIndexSeekorNodeUniqueIndexSeekrather than fullNodeByLabelScanorAllNodesScan. - Fail CI pipelines if any plan contains an unexpected
CartesianProductoperator.
- Run
- Profile Execution Plans via
PROFILE:- Run
PROFILEon staging environments to inspect actual row counts and database hits (dbHits). - Read execution plans from the bottom up:
ProduceResults ↑ Filter ↑ Expand(All) ↑ NodeIndexSeek - Ensure the ratio of
dbHitsto returned rows remains linear ($O(k)$) rather than quadratic ($O(N^2)$).
- Run
Axis 3 Diagnostic Questions (Index & Profiling)
- Are query starting nodes resolving via
NodeIndexSeekorNodeUniqueIndexSeek? - Does any query plan contain an unconstrained
CartesianProduct? - Is the total number of
dbHitsproportional to the returned subgraph rather than the entire database size? - Are text, spatial, and vector searches backed by their respective dedicated index types?
Completion Criterion: Documented
PROFILEexecution plan showing zero Cartesian products, verified index seek operators on anchor nodes, and boundeddbHitsmetrics.
5. Ephemeral Test Harnessing & Correctness Validation
Validate graph data pipelines and Cypher queries against real ephemeral database instances:
- Enforce Real Database Integration:
- Never rely on in-memory mock libraries (such as mock Neo4j drivers) to validate graph queries.
- Spin up real ephemeral Neo4j containers using
Testcontainers(Python:testcontainers-neo4j) or local Docker instances (neo4j:5-community).
- Wipe Graph State Between Test Cases:
- Implement teardown fixtures executing
MATCH (n) DETACH DELETE nto guarantee isolation between unit tests.
- Implement teardown fixtures executing
- Execute the Double-Load Idempotency Gate:
- Load sample dataset once; record node count $N_1$ and relationship count $R_1$.
- Load identical sample dataset a second time; record counts $N_2$ and $R_2$.
- Assert $N_1 == N_2$ and $R_1 == R_2$ to confirm total ingestion idempotency.
- Assert Structural and Epistemic Invariants:
- Verify property types, date parsing, constraint violation handling, and path reachability across known edge topologies.
Axis 3 Diagnostic Questions (Testing)
- Is integration testing conducted against an actual Neo4j instance rather than driver mocks?
- Do test suites verify that running batch ingestion twice produces zero duplicate nodes or edges?
- Does the teardown fixture clean up all nodes and relationships between test runs?
- Are unique constraint violations explicitly tested and handled gracefully?
Completion Criterion: Passing pytest test suite validating schema creation, idempotent batch loading, query correctness, and constraint enforcement against an ephemeral Neo4j container.
Visual Brief & Architectural Seams
During complex graph modeling or refactoring workflows, generate an interactive visual brief in the %TEMP% directory (e.g. %TEMP%\book-to-skill-forge-*.html). The brief must contain:
- Mermaid diagram of the target graph schema (Node labels, Relationship types, Key properties).
- Competency question matrix mapping queries to Cypher path expressions.
- Index coverage and constraint definitions.
- Epistemic evidence boundaries separating primary facts from derived inferences.
Mandatory Checkpoint & Plan Submission
Before executing mutating Cypher scripts, schema drops, or database migrations:
- Submit an
implementation_plan.mdartifact specifying the planned schema modifications, migration scripts, and rollback procedures. - Mark the plan with
RequestFeedback: true. - Halt execution and await explicit user review and approval before mutating persistent graph stores.
In-File Reference: Core Graph Vocabulary
- Index-Free Adjacency (IFA): The core storage architecture where nodes maintain direct physical memory pointers to their adjacent relationships and neighbors, allowing traversals to execute in $O(k)$ time relative to degree $k$, independent of total graph size $N$.
- Trail Semantics: Neo4j's graph traversal rule specifying that within a single path pattern, no relationship can be traversed more than once.
- Hop Count: The distance or number of relationship edges traversed between two nodes in a graph path.
- Bolt Protocol: The binary network protocol operating over TCP or WebSockets used for high-performance communication between client drivers and the Neo4j database engine.
- dbHits: Neo4j execution metric representing the discrete storage engine operations required to retrieve or update an entity, property, or pointer.
- Anchor Query: The initial matching clause that leverages an index or unique identifier to pinpoint the root nodes from which graph traversal begins.
Anti-Patterns
- Generic Relationship Stagnation — Use descriptive, semantically rich relationship types (
AUTHORED,VALIDATED_BY,CHALLENGES) rather than generic links (CONNECTED_TO,RELATED). - Connection as Property Anti-Pattern — Model entity-to-entity associations as first-class directed relationships rather than embedding foreign ID arrays or serialized lists inside node properties.
- Everything as Node Sprawl — Restrict nodes to entities with independent identity, lifecycle, or multi-edge connectivity; model scalar metadata, metrics, and timestamps as properties.
- Compound MERGE Duplicate Explosion — Scope
MERGEstatements to a single immutable natural identity key, moving mutable properties to explicitON CREATE SETandON MATCH SETclauses. - Unbounded Traversal Blowout — Enforce strict upper path bounds (
[*1..4]) and filtering predicates on all variable-length graph traversals to protect query memory and prevent server crashes. - Relationship Uniqueness Silent Drop — Split cyclic or diamond traversals across separate
MATCH ... WITH ... MATCHclauses when edges must be revisited across different paths, circumventing Cypher trail semantics traps. - Mock Database Testing Mirage — Validate graph schema, Cypher syntax, and constraint enforcement against real ephemeral Neo4j containers rather than in-memory mocks that mask driver and query execution errors.
- Unconstrained Transaction OOM — Ingest large graph datasets via parameterized
UNWIND $batchtransactions in chunks of 1,000 to 5,000 items rather than opening monolithic gigabyte-scale write transactions. - Timeless Relationship Fallacy — Model relationship lifecycles using explicit valid-time timestamps, versions, or reified temporal evidence objects rather than assuming static, permanent edges.
- Relation-Inference Conflation — Maintain strict boundary layers separating primary observed facts from derived graph analytics, marking hypotheses with confidence scores and evidence status.
04 同仓库更多 Skills
ui-behavior-primitive-architect
Architect, audit, and verify zero-dependency headless UI behavior primitives, WebMCP agent bridges, WAI-ARIA/SSR/RTL tri-modal checks, and framework expert routing. Do not use for static CSS theme styling or backend database migrations.
trustgraph-ontology-governor
Govern knowledge graphs, SHACL-AF triple policies, OntologyRAG subclass validation, PROV-O dual named graphs, and Laya entropy decision scoring. Do not use for relational SQL queries or generic web scraping.
shim-harness-governor
Govern universal CLI agent loops, 4-tier tool permissions, ancestor-symlink workspace sandboxes, deterministic-first command routing, collision-safe MCP namespacing, and layered skill loading. Do not use for static UI styling or external SQL analytics.
graphiti-zep-memory-governor
Govern bi-temporal knowledge graphs with Graphiti future-edge clamping, MinHash/LSH entity dedup, RRF/MMR reranking, and Zep typed ontologies. Do not use for static SQL joins or generic web crawling.
agora-mcp-workbench-architect
Architect, audit, and orchestrate Agora Workbench MCP servers, loopback sidecars, unified state graphs, gateway/dispatcher connectors, and policy-enforced data lakes. Do not use for static frontend CSS styling or non-MCP desktop GUI automation.
skill-eval-assurance-runner
Evaluate and assure agent skills using small-N Wilson confidence intervals, unbiased pass^k reliability, deterministic trajectory graders, preflight boundary honesty, and sealed digest verification. Do not use for subjective prose review or unconstrained production deployment.