Skip to content

Add support for KEY constraints to KG builder schema#511

Open
adamnsch wants to merge 6 commits intoneo4j:mainfrom
adamnsch:adamnsch/key-constraint
Open

Add support for KEY constraints to KG builder schema#511
adamnsch wants to merge 6 commits intoneo4j:mainfrom
adamnsch:adamnsch/key-constraint

Conversation

@adamnsch
Copy link
Copy Markdown
Contributor

@adamnsch adamnsch commented Apr 15, 2026

Description

Summary

Adds GraphConstraintType.KEY to the experimental GraphSchema (single property, node or relationship scope), aligned with Neo4j key constraints for mandatory presence + identity semantics. Pruning enforces presence for KEY (like EXISTENCE); uniqueness is still not validated in-process.

Note: Support for composite constraints will be added in an upcoming PR.

Breaking change: ParquetWriter / KGWriterModel metadata

metadata["files"][].columns entries now include:

  • is_uniquetrue for UNIQUENESS-backed properties only
  • is_primary_keytrue for KEY-backed properties, synthetic __id__ when no KEY, and relationship from / to columns

UNIQUENESS no longer sets is_primary_key; consumers that relied on that must use is_unique.

Other changes

  • UNIQUENESS + KEY on the same node property is rejected at schema validation (Neo4j rule).
  • Helpers: key_property_names_for_*, uniqueness_property_names_for_node, mandatory_property_names_for_*.
  • Schema-from-text: ExtractedConstraintType and extraction filter support KEY; prompt updated.
  • SchemaFromExistingGraphExtractor: Neo4j NODE_KEY / RELATIONSHIP_KEY metadata maps to KEY (existence-only constraints unchanged).
  • CHANGELOG updated under Next.

Tests

Unit tests cover schema validation, conflict case, pruning (node KEY), extraction, and Parquet column metadata (is_primary_key / is_unique).

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update
  • Project configuration change

Complexity

Complexity: Medium

How Has This Been Tested?

  • Unit tests
  • E2E tests
  • Manual tests

Checklist

The following requirements should have been met (depending on the changes in the branch):

  • Documentation has been updated
  • Unit tests have been updated
  • E2E tests have been updated
  • Examples have been updated
  • New files have copyright header
  • CLA (https://neo4j.com/developer/cla/) has been signed
  • CHANGELOG.md updated if appropriate

@adamnsch adamnsch marked this pull request as ready for review April 15, 2026 07:49
@adamnsch adamnsch requested a review from a team as a code owner April 15, 2026 07:49
Copy link
Copy Markdown
Contributor

@NathalieCharbel NathalieCharbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great 🚀

A few non-blocking suggestions for improvement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants